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.
Tar
#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
Grep
#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
#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
SSH
#Login to remote host
ssh –l jsmith remotehost.example.com

#Debug ssh client
ssh –v –l jsmith remotehost.example.com

#Display SSH client version
ssh –V
Sed
#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/ /’
Awk
#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
Vim
#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
Diff
#Ignore white space while comparing
diff –w name_list.txt name_list new.txt
Sort
#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  
Export

#View oracle related environment variables
export | grep ORACLE

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

9 comments:

  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

    ReplyDelete
  2. After reading your post I understood that last week was with full of surprises and happiness for you. Congratz! Even though the website is work related, you can update small events in your life and share your happiness with us too.
    python interview questions and answers | python tutorials

    ReplyDelete
  3. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.

    Java training in Chennai | Java training in USA | Java training in Kalyan nagar

    ReplyDelete
  4. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa training in velachery| rpa training in tambaram |rpa training in sholinganallur | rpa training in annanagar| rpa training in kalyannagar

    ReplyDelete
  5. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
    Data Science training in Chennai | Data science training in bangalore

    Data science training in pune | Data science online training

    Data Science Interview questions and answers

    ReplyDelete
  6. Everything is very interesting to learn and easy to understood. Thank you for giving information.
    Ethical Hacking Training in chennai
    Best Training Institute in Chennai

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. "I've found biharjobportal.co.in to be an incredibly useful resource for job seekers in Bihar. The platform offers a comprehensive range of job listings across various sectors, making it easier for individuals to find employment opportunities that align with their skills and interests.

    ReplyDelete