Most frequently used Linux commands 1

Most frequently used Linux commands 1

Tar command

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 command

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 "howcsharp" *

Find command

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

Ssh command

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

OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003

Sed command

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/ /'

Awk command

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

Vim command

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 the file in read only mode.

$ vim -R /etc/passwd

Diff command

Ignore white space while comparing.

$ diff -w name_list.txt name_list_new.txt

Sort command

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 command

To view 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"

To export an environment variable:

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


Most frequently used Linux commands 1
added 8 years 5 months ago

Contents related to 'Most frequently used Linux commands 1'

Most frequently used Linux commands 2: Most frequently used linux commands 2, explanation of linux commands, examples of linux command usage.

Most frequently used Linux commands 3: Most frequently used linux commands 3, explanation of linux commands, examples of linux command usage.

Most frequently used Linux commands 4: Most frequently used linux commands 4, explanation of linux commands, examples of linux command usage.

Most frequently used Linux commands 5: Most frequently used linux commands 5, explanation of linux commands, examples of linux command usage.

- Average Calculator
- Most frequently used Linux commands 5
- Most frequently used Linux commands 4
- Most frequently used Linux commands 3
- Most frequently used Linux commands 2
- Most frequently used Linux commands 1
- How to rename a filename to current date with batch
- How does a mutex work? What does a mutex cost?
- Locking : Mutex vs Spinlocks
- Description of Lock, Monitor, Mutex and Semaphore
- Difference between Mutex and Semaphore
- Difference between association, aggregation and composition
- Coordinating C/C++ ØMQ and .NET ØMQ
- Regular Expressions (Regex) Reference Sheet