Linux commands for daily usage

File/Basic commands
These are some useful basic linux commands. For every command I followed this convention.
1)The name of the command with a short description is given.
2)Some of the useful options that can be used with the command is given after the command.

ls – list the current directory contents.
-l long listing
-a list including hidden files
-t list by last modified

cat – show the content of a file.
format: cat [options] [file name(s)]
-n show the line numbers also.

head – output the first 10 lines of each FILE to standard output
format: head [options] [file name(s)]
–bytes=5k or -c 5k
-n specify the number of lines.

tail – output last part of file
same as head

sort – sort lines of text files
sort [OPTION]… [FILE]…
-n numerical sort
-f ingnore case
-r reverse the results
-R random
-d in dictinary order

free – Display amount of free and used memory in the system
free [-b|-k|-m|-g]
-b bytes
-k kilo bytes
-m mega bytes
-g giga bytes

Search commands:

find – search for files in a directory hierarchy
find [directory to search] [option] [filename]
eg:- find . -name

find [directory] -group gname (File belongs to group gname)

grep – print lines matching a pattern
grep [options] [pattern] [filename]
grep ‘head’ words.txt
grep ‘^head’ words.txt
grep ‘head$’ words.txt
grep ‘^head$’ words.txt
grep ‘^….$’ words.txt
grep ‘^h.*d$’ words.txt

sed – stream editor for filtering and transforming text
sed [OPTION]… {script-only-if-no-other-script} [input-file]…
two examples:
sed ‘s/cat/dog/g’ data ( substitute all cat with dog globally )
sed 2,4d data ( delete lines from 2 to 4 in file data)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s