Friday, 10 February 2012

10 Frequently Used UNIX / Linux Commands

This short post provides practical examples for ten most frequently used commands in Linux/UNIX. The purpose of this list is to give you a jump-start on some of the common Linux commands.
#Create a new tar archive
tar cvf archive_name.tar dirname/

#Extract from an existing tar archive
tar xvf archive_name.tar

#View an existing tar archive
tar tvf archive_name.tar
#Search for a given string in a file (case insensitive)
grep –i “the” demo_file

#Print the matched line along with the 3 lines after it
grep –A 3 –i “example” demo_text

#Search for a given string in all files recursively
grep –r “ramesh” *
#Find files using file-name (case insensitive)
find –iname “MyProgram.c”

#Execute commands on the files found by the find command
find –iname “MyProgram.c” –exec md5sum {} \;

#Find all empty files in home directory
find ~ -empty
#Login to remote host
ssh –l jsmith

#Debug ssh client
ssh –v –l jsmith

#Display SSH client version
ssh –V
#Convert the DOS file format to Unix file format
sed ‘s/.$//’filename

#Print file content in reverse
sed –n ‘1!G;h;$p’ thegeekstuff.txt

#Add line number for all non-empty-lines in a file
sed ‘/./=’ thegeekstuff.txt | sed ‘N; s/\n/ /’
#Remove duplicate lines using awk
awk ‘!($0 in array) { array[$0]; print }’ temp

# Print all lines from /etc/passwd that have the same uid and gid
awk –F ‘:’ ‘$3 == $4’ passwd.txt

# Print only a specific field from a file
awk ‘{print $2, $5}’ employee.txt
#Go to the 143rd line of file
vim +143 filename.txt

#Go to the first match of the specified
vim +/search-term filename.txt

#Open file in read-only mode
vim –R /etc/passwd
#Ignore white space while comparing
diff –w name_list.txt name_list new.txt
#Sort a file in ascending order
sort names.txt

#Sort a file in descending order
sort –r names.txt

#Sort passwd file by 3rd field
sort –t: -k 3n /etc/passwd | more  

#View oracle related environment variables
export | grep ORACLE

#Export an environment variable
export ORACLE_HOME = ‘/u01/app/oracle/product/10.2.0’

1 comment:

  1. Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.
    AWS Training in Bangalore | Amazon Web Services Training in Bangalore

    Amazon Web Services Training in Pune | Best AWS Training in Pune