Frequently used linux commands

  1. grep command
    Description :- its comes from g/re/p (globally search regular expression and print)
    it is used as one of the most used command under unix
    Usage:-

    • Find count of matching words
      grep -c “queue” sanj_ms1.log”
      this will find the number of occurence of queue word in the file sanj_ms1.log
    • Showing particular number of lines from the file after the matching word
      grep  -C 2 “queue” “sanj_ms1.log”
    • Different variant of grep command
      • pgrep is the command to give the process id for a supplied process argument
        pgrep -if java
      • grep -i do case insensetive search
        this searches for the given string/pattern case insitively. So it matches all the words wether occuring in lower or uppercase
        grep -i “string” FILE
      • zgrep is used to search for particular string under zip files
        zgrep -iw “less” “filename.txt.gz
  2. SCP command:- SCP command or secure copy is used for transferring of files to remote machine or transfer the files between two remote machines it uses the SSH protocol
    syntax/examples can be reffered @ http://www.hypexr.org/linux_scp_help.php
  3. Find command :-  This command is widely used for searching of files across the system using required parameters
    • Finding files 5 days older
      find /path/to/files* -mtime +5 -exec rm {} \;

      • 1st argument is path to the files
      • 2nd argument  is -mtime specify the number of days old that file is
        +5 will fetch files which are 5 days older
      • 3rd argument is -exec allow to pass command which needs to be executed on the result like rm {} \;
    • Find the files ignoring case
      • find -iname *.txt
    • Find files as per the size its in bytes
      • find . -size +1000c -exec ls -l {} \;
      • find -szie +1000c -size -50000c -printing
  4. netstat -tulpn | grep –color :80
  5. to extract the tarball
    1. untar -xvf filename.tar -C /tmp/dirname
  6. Finding file between two dates/timestamps
    1. find . -type f -newermt 2010-10-07 ! -newermt 2014-10-08
      returns a list of files that havve timestamps after 2010-10-07 and before 2014-10-06
    2. Find files 15 minutes ago until now:
      1. find . -type f  -mmin -15
        Returns list of files that have timestamps after 15 mins ago but before now
    3. Find files between two timestamps
      1. find . -type -newermt “2014-10-08  10:17:00” ! -newermt “2014-10-08  10:53:00”
        returns files with timestamps between 2014-10-08 10:17:00 and 2014-10-08 10:53:00
  7. Export command examples
    1. export | grep ORACLE
      declare -x ORACLE_BASE=”/u01/app/oracle”
      declare -x ORACLE_HOME=”/u01/app/oracle/product/10.2.0″
      declare -x ORACLE_SID=”med”
      declare -x ORACLE_TERM=”xterm”
  8. View the content of the file without unziping it
    1. unzip -l jasper.zip
        Length     Date   Time    Name
       --------    ----   ----    ----
          40995  11-30-98 23:50   META-INF/MANIFEST.MF
          32169  08-25-98 21:07   classes_
          15964  08-25-98 21:07   classes_names
          10542  08-25-98 21:07   classes_ncomp
  9. FTP Commands 
    • ftp IP/hostname
      ftp> mget *.html
    • ftp> mls *.html
      /ftptest/features.html
      /ftptest/index.html
      /ftptest/othertools.html
      /ftptest/samplereport.html
      /ftptest/usage.html
  10. CronTab command
    • View corntab entry for specific user
      crontab -u john -l
    • Schedule a cron job every 10 minutes
      */10 * * * * /home/ec2-user/check-disk-space

 

Leave a Reply