most used linux comands
This article provides practical examples for
most frequently used commands in Linux / UNIX.
Extract from an existing tar archive.
View an existing tar archive.
Print the matched line, along with the 3 lines after it.
Search for a given string in all files recursively
Execute commands on files found by the find command
Find all empty files in home directory
Debug ssh client
Display ssh client version
Print file content in reverse order
Add line number for all non-empty-lines in a file
Print all lines from /etc/passwd that has the same uid and gid
Print only specific field from a file.
most frequently used commands in Linux / UNIX.
1. tar command examples
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
2. grep command examples
Search for a given string in a file (case in-sensitive search).$ 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" *
3. find command examples
Find files using file-name ( case in-sensitve find)# find -iname "MyCProgram.c"
Execute commands on files found by the find command
$ find -iname "MyCProgram.c" -exec md5sum {} \;
Find all empty files in home directory
# find ~ -empty
4. ssh command examples
Login to remote hostssh -l jsmith remotehost.example.com
Debug ssh client
ssh -v -l jsmith remotehost.example.com
Display ssh client version
$ ssh -V OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
5. sed command examples
When you copy a DOS file to Unix, you could find \r\n in the end of each line. This example converts the DOS file format to Unix file format using sed command.$sed 's/.$//' filename
Print file content in reverse order
$ 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/ /'
6. awk command examples
Remove duplicate lines using awk$ awk '!($0 in array) { array[$0]; print }' temp
Print all lines from /etc/passwd that has the same uid and gid
$awk -F ':' '$3==$4' passwd.txt
Print only specific field from a file.
$ awk '{print $2,$5;}' employee.txt
Comments
Post a Comment