Subscribe:

Ads 468x60px

Showing posts with label grep. Show all posts
Showing posts with label grep. Show all posts

Friday, August 31, 2012

Useful Linux Commands

Here I am documenting few useful linux terminal command:


  1. Command to report system disk space usage:
    [osao@slc01nga ~]df
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/xvda2           195592588 177362320   8294652  96% /
    tmpfs                  3931448       368   3931080   1% /dev/shm
    /dev/xvda1             1007896    124588    832108  14% /boot
    slcnas411:/export/home1/osao
                         16106127360 8378327360 7727800000  53% /home/osao
    10.246.4.40:/vol/ade_infra/prod/LINUX.X64
                         100663296   5784768  94878528   6% /usr/dev_infra/platform
    10.246.4.37:/vol/ade_infra/prod/GENERIC
                         100663296   5784768  94878528   6% /usr/dev_infra/generic
    slc1001nap:/vol/local/x86_64/redhat/60_prod/packages
                         1132462080 1087278784  45183296  97% /usr/local/remote/packages
    slc1001nap:/vol/local/linux/redhat/packages
                         1132462080 1087278784  45183296  97% /usr/local/redhat/packages
    Command to see these in summarised short form
    [osao@slc01nga ~]df -lhk
  2. Command for knowing all services running on a machine
    [osao@slc01nga ~] nmap localhost     (in place of localhost you can give other live machine also in your intranet)

  3. Command for knowing a port number for service running and Process ID (pid)
    [osao@slc01nga ~]netstat -anp | grep 9000  (it will search a service running on port no. 9000)
    The following two command will also do the same:
    [osao@slc01nga ~] lsof -w -n -i tcp:8080
    [osao@slc01nga ~]  fuser -n tcp 8080
  4. Command for knowing Directory/File size
    [osao@slc01nga ~]du -hs
  5. Command for searching particular string in particular files in regular expression form
    For ex. here we are searching in all files whose name end contains .jspx or .jsff and file contains text "encoding"
    [osao@slc01nga ~]grep -H -r -n -i --color "encoding" . --include='*.[j][s][fp][xf]'
  6. Perl Command to replace all occurences of string to other string
    the format is
    [osao@slc01nga ~]/usr/bin/perl -p -i -e "s/string1/string2/g"  
    For Ex. for converting all occurences of "ReSult" to "" We will invoke the command
      [osao@slc01nga ~] /usr/bin/perl -p -i -e "s/ReSuLt/$Result_Count<\\/font>/g"