-
Create a new tar archive
$ tar cvf archive_name.tar dirname/
-
Extract 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 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 (pertaining to)
$ grep -r "ramesh" *
-
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
-
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
-
Print only 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 the 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
-
To export an environment variable:
$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0
-
Copy all images to external hard-drive
# ls *.jpg | xargs -n1 -i cp {} /external-hard-drive/directory
-
Search all jpg images in the system and archive it.
# find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
-
Download all the URLs mentioned in the url-list.txt file
# cat url-list.txt | xargs wget –c
-
Display filesize in human readable format (e.g. KB, MB etc.,)
$ ls -lh
-
Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr
$ ls -ltr
-
Visual Classification of Files With Special Characters Using ls -F
$ ls -F
-
To create a *.gz compressed file:
$ gzip test.txt
-
To uncompress a *.gz file:
$ gzip -d test.txt.gz
-
Display compression ratio of the compressed file using gzip -l
$ gzip -l *.gz
-
To create a *.bz2 compressed file:
$ bzip2 test.txt
-
To uncompress a *.bz2 file:
bzip2 -d test.txt.bz2
-
To extract a *.zip compressed file:
$ unzip test.zip
-
View the contents of *.zip file (Without unzipping it):
$ unzip -l jasper.zip
-
Shutdown the system and turn the power off immediately
# shutdown -h now
-
Shutdown the system and turn the power off immediately
# shutdown -h now
-
Shutdown the system after 10 minutes
# shutdown -h +10
-
Reboot the system using shutdown command
# shutdown -r now
-
Force the filesystem check during reboot.
# shutdown -Fr now
-
View crontab entry for a specific user
# crontab -u john -l
-
Check the status of all the services
service --status-all
-
Restart a service
# service ssh restart
-
To view current running processes
$ ps -ef | more
-
To view current running processes in a tree structure. H option stands for process hierarchy.
$ ps -efH | more
-
This command is used to display the free, used, swap memory available in the system.Typical free command output. The output is displayed in bytes.
$ free
-
check how many GB of RAM your system has use the -g option. -b option displays in bytes, -k in kilo bytes, -m in mega bytes
$ free -g
-
If you want to see a total memory ( including the swap), use the -t switch, which will display a total line as shown below.
$ free -t
-
Use kill command to terminate a process. First get the process id using ps -ef command, then use kill -9 to kill the running Linux process
- $ ps -ef | grep vim
- ramesh 7243 7222 9 22:43 pts/2 00:00:00 vim
$ kill -9 7243
-
Get confirmation before removing the file.
$ rm -i filename.txt
-
Following example recursively removes all files and directories under the example directory. This also removes the example directory itself.
$ rm -r example
-
Copy file1 to file2 preserving the mode, ownership and timestamp.
$ cp -p file1 file2
-
Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.
cp -i file1 file2
-
Rename file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ mv -i file1 file2
-
You can view multiple files at the same time.
$ cat file1 file2
-
To mount a file system, you should first create a directory and mount it as shown
# mkdir /u01
# mount /dev/sdb1 /u01
-
Use ifconfig command to view or configure a network interface on the Linux system.
$ ifconfig -a
-
shows all files in the system that contains the word crontab in it.
$ locate crontab
-
Print the last 10 lines of a file by default.
$ tail filename.txt
-
Print N number of lines from the file named filename.txt
$ tail -n N filename.txt
-
View the content of the file in real time using tail -f. This is useful to view the log files, that keeps growing. The command can be terminated using CTRL-C
$ tail -f log-file
-
less is very efficient while viewing huge log files, as it doesn’t need to load the full file while opening.
$ less huge-log-file.log
-
Ping a remote host by sending only 5 packets.
$ ping -c 5 gmail.com
|
|