Important UNIX comands

1. Get list of files in a directory
ls , ls-la ( detailed view ) , $ ls -a ( to list invisible files )

2.What is metacharacters in UNIX

* and ? are metacharacters in unix * stands for 0 or many characters and ? stands for one character .
Eg : ls *.png ( will list all files which contains .png in the end os string )

3.How to add and edit a file
step 1. locate to directory where you want to add file
step 2 . command $vi filename – this will create file
step 3 : click on i to active edit mode
step 4 : if you are done with editing click esc to come out of insert mode.
step 5 :wq or SHift + zz to get out of the file

4. How to display content of the file

use cat filename
use cat -b filename ( to get the line numbers as well )

5. How to copy file to other locations
$cp sourceDest targetDes

6. How to rename file
$mv filename newFileName

7. how to delete file

$rm filename to be more careful use -i with this command

Grep commands

1. grep -m 20 “SqlExceptionHelper” catalina.out
here -m will start search from the beginning and ll stop at 20th occurrence .

2.grep -m 20 “SqlExceptionHelper” catalina.out | tail -10
grep “SqlExceptionHelper” catalina.out | head -10

Do you have a scenario where you want to find last N occurrence of a string in log file the above command is useful .

some sample commands :
Cat fileName | grep ‘textToFind’

want to search gz file ?? use below command
find /opt/PathToFile -name “FileName.gz” -exec zgrep -H ‘StringToSearch’ {} \;

Leave a Reply

Your email address will not be published. Required fields are marked *