10 Most Frequently Used Linux Commands

Are you starting out on the Linux command line? Are you having a hard time remembering those commands? Not to worry. Here's a list of some of the most common and most basic commands that are used on Linux, along with some examples explaining there usage

  1. tar command

    The following command creates a new tar archive:

    tar cvf archive_name.tar dirname/

    Use this when you need to extract from an existing archive:

    tar xvf archive_name.tar

    This is the command that is used to view a tar archive:

    tar tvf archive_name.tar
  2. grep command

    This command searches for a given string within a file:

    grep -i "the" demo_file

    This command prints a matched line and three lines after it:

    grep -A 3 -i "example" demo_text

    Recursively search for a string in all files:

    grep -r "ramesh" *
  3. find command

    Use this to find files when the filename is known:

    find -iname "MyCProgram.c"

    This command is used to execute command on files that have been found using find:

    find -iname "MyCProgram.c" -exec md5sum {} \;

    Empty files in the directory:

    find ~ -empty
  4. ssh command

    This command allows you to login to a remote host.

    ssh -l jsmith remotehost.example.com

    Use this to debug ssh clients:

    ssh -v -l jsmith remotehost.example.com

    For displaying the ssh client version:

    ssh -V

  5. sed command

    Convert the DOS file format into Unix format:

    sed 's/.$//' filename

    Print the contents of a file in reverse order:

    sed -n '1!G;h;$p' thegeekstuff.txt

    Add a line number for the non-empty lines in a particular file

    sed '/./=' thegeekstuff.txt | sed 'N; s/\n/ /'
  6. awk command

    Remove duplicate lines:

    awk '!($0 in array) { array[$0]; print }' temp

    Print all lines from a file , which have the same uid and gid:

    awk -F ':' '$3==$4' passwd.txt

    Printing specific fields from a particular file:

    awk '{print $2,$5;}' employee.txt
  7. vim command

    Go to the file's 143rd line.

    vim +143 filename.txt

    Go to the first found match of the file specified:

    vim +/search-term filename.txt
  8. diff command

    Ignoring white spaces when comparing files:

    diff -w name_list.txt name_list_new.txt
  9. sort command

    Ascending order:

    sort names.txt

    Descending order:

    sort -r names.txt

    Sort a file (passwd) the third field:

    sort -t: -k 3n /etc/passwd | more
  10. export command

    Use this for viewing oracle related environment variables:

    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"

    Export environment variable:

    export ORACLE_HOME=/u01/app/oracle/product/10.2.0


Popular posts from this blog