50 Most Frequently Used Linux Commands PDF
50 Most Frequently Used Linux Commands PDF
50 Most Frequently Used Linux Commands PDF
About
Free eB o o k
A r c h iv e s
B e s t o f t h e B lo g
C o n t act
230
Like
Tw eet
347
317
Did I miss any frequently used Linux commands? Leave a comment and let me know.
>Email >RSS >Twitter >Facebook
pdfcrowd.com
EBO O KS
Linux 101 Hacks 2nd Edition eBook - Practical
Examples to Build a Strong Foundation in Linux
Bash 101 Hacks eBook - Take Control of Your Bash
Command Line and Shell Scripting
More tar examples: The Ultimate Tar Command Tutorial with 10 Practical Examples
pdfcrowd.com
Print the matched line, along with the 3 lines after it.
$ grep -r "ramesh" *
More grep examples: Get a Grip on the Grep! 15 Practical Grep Command Examples
# find ~ -empty
More find examples: Mommy, I found it! 15 Practical Linux Find Command Examples
pdfcrowd.com
Linux
Vim
Sed
Awk
Bash
Nagios
OpenSSH
$ ssh -V
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
IPTables
Apache
MySQL
Perl
Google
Ubuntu
When you copy a DOS file to Unix, you could find \r\n in the end of each line. This example
PostgreSQL
converts the DOS file format to Unix file format using sed command.
Hello World
C Programming
C++ Programming
DELL
Oracle
VMware
pdfcrowd.com
Print all lines from /etc/passwd that has the same uid and gid
More awk examples: 8 Powerful Awk Built-in Variables FS, OFS, RS, ORS, NR, NF,
FILENAME, FNR
pdfcrowd.com
$ vim -R /etc/passwd
More diff examples: Top 4 File Difference Tools on UNIX / Linux Diff, Colordiff, Wdiff, Vimdiff
$ sort names.txt
pdfcrowd.com
$ sort -r names.txt
$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0
pdfcrowd.com
$ ls -lh
-rw-r----- 1 ramesh team-dev 8.9M Jun 12 15:27 arch-linux.txt.gz
Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr
$ ls -ltr
$ ls -F
pdfcrowd.com
$ gzip test.txt
$ gzip -d test.txt.gz
$ gzip -l *.gz
compressed
uncompressed
23709
97975
ratio uncompressed_name
75.8% asp-patch-rpms.txt
$ bzip2 test.txt
pdfcrowd.com
bzip2 -d test.txt.bz2
More bzip2 examples: BZ is Eazy! bzip2, bzgrep, bzcmp, bzdiff, bzcat, bzless, bzmore examples
$ unzip test.zip
$ unzip -l jasper.zip
Archive: jasper.zip
Length
Date
Time
--------------
Name
----
40995
32169
15964
11-30-98 23:50
08-25-98 21:07
08-25-98 21:07
META-INF/MANIFEST.MF
classes_
classes_names
10542
08-25-98 21:07
classes_ncomp
# shutdown -h now
pdfcrowd.com
# shutdown -h +10
# shutdown -r now
$ ftp IP/hostname
ftp> mget *.html
To view the file names located on the remote server before downloading, mls ftp command as
shown below.
pdfcrowd.com
More ftp examples: FTP and SFTP Beginners Guide with 10 Examples
# crontab -u john -l
*/10 * * * * /home/ramesh/check-disk-space
service --status-all
pdfcrowd.com
Restart a service.
$ ps -ef | more
To view current running processes in a tree structure. H option stands for process hierarchy.
$ ps -efH | more
$ free
total
Mem:
3566408
-/+ buffers/cache:
used
1580220
473272
free
1986188
3093136
shared
0
buffers
203988
cached
902960
pdfcrowd.com
Swap:
4000176
4000176
If you want to quickly 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
total
Mem:
3
-/+ buffers/cache:
Swap:
used
1
0
free
1
2
shared
0
buffers
0
cached
0
If you want to see a total memory ( including the swap), use the -t switch, which will display a
total line as shown below.
ramesh@ramesh-laptop:~$ free -t
total
Mem:
3566408
-/+ buffers/cache:
used
1592148
475332
free
1974260
3091076
Swap:
Total:
0
1592148
4000176
5974436
4000176
7566584
shared
0
buffers
204260
cached
912556
Select sort field via field letter, type any other key to return
a: PID
= Process Id
v: nDRT
pdfcrowd.com
d: UID
e: USER
........
= User Id
= User Name
y: WCHAN
z: Flags
= Sleeping in Function
= Task Flags
To displays only the processes that belong to a particular user use -u option. The following will
show only the top processes that belongs to oracle user.
$ top -u oracle
More top examples: Can You Top This? 15 Practical Linux Top Command Examples
$ df -k
Filesystem
/dev/sda1
/dev/sda2
1K-blocks
29530400
120367992
df -h displays output in human readable form. i.e size will be displayed in GBs.
ramesh@ramesh-laptop:~$ df -h
Filesystem
Size Used Avail Use% Mounted on
/dev/sda1
29G 3.1G
24G 12% /
/dev/sda2
115G
48G
62G 44% /home
ramesh@ramesh-laptop:~$ df -T
pdfcrowd.com
Filesystem
/dev/sda1
/dev/sda2
Type
ext4
ext4
1K-blocks
29530400
120367992
9 22:43 pts/2
00:00:00 vim
$ kill -9 7243
More kill examples: 4 Ways to Kill a Process kill, killall, pkill, xkill
$ rm -i filename.txt
It is very useful while giving shell metacharacters in the file name argument.
Print the filename and get confirmation before removing the file.
$ rm -i file*
Following example recursively removes all files and directories under the example directory.
open in browser PRO version Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
$ rm -r example
$ cp -p file1 file2
Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ cp -i file1 file2
$ mv -i file1 file2
Note: mv -f is just the opposite, which will overwrite file2 without prompting.
mv -v will print what is happening during file rename, which is useful while specifying shell
metacharacters in the file name argument.
$ mv -v file1 file2
pdfcrowd.com
While displaying the file, following cat -n command will prepend the line number to each line of
the output.
$ cat -n /etc/logrotate.conf
1
/var/log/btmp {
2
missingok
3
4
5
6
monthly
create 0660 root utmp
rotate 1
}
# mkdir /u01
# mount /dev/sdb1 /u01
You can also add this to the fstab for automatic mounting. i.e Anytime system is restarted, the
filesystem will be mounted.
pdfcrowd.com
Revoke all access for the group (i.e read, write and execute ) on a specific file.
Apply the file permissions recursively to all the files in the sub-directories.
pdfcrowd.com
$ passwd
Super user can use passwd command to reset others password. This will not prompt for current
password of the user.
# passwd USERNAME
Remove password for a specific user. Root user can disable password for a specific user. Once
the password is disabled, the user can login without entering the password.
# passwd -d USERNAME
$ mkdir ~/temp
Create nested directories using one mkdir command. If any of these directories exist already, it
will not display any error. If any of these directories doesnt exist, it will create them.
open in browser PRO version Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
will not display any error. If any of these directories doesnt exist, it will create them.
$ mkdir -p dir1/dir2/dir3/dir4/
$ ifconfig -a
Start or stop a specific interface using up and down command as shown below.
$ ifconfig eth0 up
$ ifconfig eth0 down
$ uname -a
Linux john-laptop 2.6.32-24-generic #41-Ubuntu SMP Thu Aug 19 01:12:52 UTC 2010 i686 GNU/Linux
pdfcrowd.com
$ whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
When you want to search an executable from a path other than the whereis default path, you
can use -B option and give path as argument to it. This searches for the executable lsmk in the
/tmp directory, and displays it, if it is available.
$ whatis ls
ls
(1)
$ whatis ifconfig
ifconfig (8)
pdfcrowd.com
The example below shows all files in the system that contains the word crontab in it.
$ locate crontab
/etc/anacrontab
/etc/crontab
/usr/bin/crontab
/usr/share/doc/cron/examples/crontab2english.pl.gz
/usr/share/man/man1/crontab.1.gz
/usr/share/man/man5/anacrontab.5.gz
/usr/share/man/man5/crontab.5.gz
/usr/share/vim/vim72/syntax/crontab.vim
$ man crontab
When a man page for a command is located under more than one section, you can view the
man page for that command from a specific section as shown below.
pdfcrowd.com
$ whatis crontab
crontab (1)
crontab (5)
$ man 5 crontab
$ tail 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
pdfcrowd.com
More tail examples: 3 Methods To View tail -f output of Multiple Log Files in One Terminal
$ less huge-log-file.log
One you open a file using less command, following two keys are very helpful.
More less examples: Unix Less Command: 10 Tips for Effective Navigation
$ su - USERNAME
Execute a single command from a different account name. In the following example, john can
execute the ls command as raj username. Once the command is executed, it will come back to
johns account.
pdfcrowd.com
[john@dev-server]$
Login to a specified user account, and execute the specified shell instead of the default shell.
$ su -s 'SHELLNAME' USERNAME
$ mysql -u root -p
If you want to specify the mysql root password in the command line itself, enter it immediately
after -p (without any space).
pdfcrowd.com
More rpm examples: RPM Command: 15 Examples to Install, Uninstall, Upgrade, Query RPM
Packages
pdfcrowd.com
$ ping -c 5 gmail.com
Once youve changed the system date, you should syncronize the hardware clock with the
system date as shown below.
# hwclock systohc
# hwclock --systohc utc
$ wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz
pdfcrowd.com
More wget examples: The Ultimate Wget Download Guide With 15 Awesome Examples
Did I miss any frequently used Linux commands? Leave a comment and let me know.
230
Tw eet
317
Like
347
(With Examples)
Rules Examples
Turbocharge PuTTY with 12 Powerful
Fundamentals
Add-Ons
pdfcrowd.com
mio
Madharasan
Hi Ramesh,
pdfcrowd.com
rameshkumar
RO
I found this a good set of tips to pass on to a newbie on my team that is supporting a
corporate application package, although I had to make the following distinctions for the
Solaris servers we work on:
commands in that list of 50 that do not work in Solaris (without adding extra packages at
least):
vim (only vi is included, and a much simpler editor than vim)
shutdown (only for root Id, so you should not be able to use it do NOT try, if you can for
some reason)
service specific to root in Linux
free parts of this command info can be had from several Solaris commands: vmstat,
iostat, mpstat
top use prstat in Solaris
mount another one only for root (superuser) Id
passwd our organization uses NIS for this kind of user management, and only via special
requests
pdfcrowd.com
Geoff
Shashi
Earl Jenkins
pdfcrowd.com
Hamilton Jimenez
This is a really nice article for everyone. I sent the link to every friend who know Unix/Linux.
Thanks a lot!
ignazioc
10
awesome!
dj
11
Nice list.
Possible additions:
rsync
nano (in vi category)
sudo (in su category)
apropos (in man category)
who, whoami,groups
whois
exit or ctrl-d
pdfcrowd.com
hexdump -C
A side-note on `less`. If the user finds the need to edit the file they are viewer, they could use
the `v` command. I do see in the man-page it says, The following four commands may or
may not be valid, depending on your particular installation..
Teresa
12
Wuzzy
13
In case you dont want tar to list the files it processed (because you want a clean terminal
), simply remove the letter v (v for verbose [not vendetta
krushna
14
sathiya
15
pdfcrowd.com
tom
16
Title of this article is kinda inaccurate. Several examples arent so much UNIX/Linux as
much as they are GNU tools.
Also, the use of ssh -l ${USER} is kind of an archaic usage style. Using ssh
$USER@${HOST} (or scp $USER@${HOST}) is a bit more common (at least in production
UNIX or Linux) shops and has the value of saving you a couple keystrokes.
Vaishali
17
Nice list
anonymous
18
Not that service command is a Red Hat command. For any Unix or Linux (including Red Hat)
is via:
{{{
/etc/init.d/sshd status
/etc/init.d/httpd start or /etc/init.d/apache2 start
/etc/init.d/nfs restart
/etc/init.d/mysdl stop
}}}
As already mentioned since these act upon Daemons (or services) you need to be username
root (or use sudo).
BHARATH
19
pdfcrowd.com
joey
20
Shelly
21
Thanks Ramesh! This is a very useful list for new Linux users to use for reference. Really
gets you up to speed quickly!
highlandham
22
AR
23
1. tutorial on chkconfig?
2. how to set up a temporary and a permanent route?
3. how to check SAN?
Thank You!!
Hima
24
pdfcrowd.com
joel
25
thanks very very very much please keep the good work going
am so a beginner in linux for i am a oracle11g student those command are real helping me.
please i would like to have more pleaseeeeeeeeeeeee in my email thanks alot
eliyas
26
Nalaka
27
Dear Ramesh,
Pls clarify, the way how can i create a descending order file(upon numeric column), where
there are many columns in the lst file.
Regards
Nalaka
28
You should include print commands like lpr, lpoptions, lpstat too
29
pdfcrowd.com
I really wanted to say thank you for writting such a great tutorial.
Any chance of NMAP, Print, Whois topics, please
Also, a litte tute on switches would be awesome.
Mihai
30
John
31
Great list, Im in college and taking a few linux admin classes, and my teacher was trying to
do a lesson on Crontab, but for whatever reason couldnt remember how to do it. I looked it
up on here and was able to look smart in front of the whole class
32
Stefan
33
pdfcrowd.com
Bob Kraus
34
bob kraus
35
Sorry about the previous grep comment it was at the top of your 50 and I missed it. Dooh!
prabinseth
36
i think it should be
tar -cvf archive_name.tar dirname/
instead of
tar cvf archive_name.tar dirname/
please correct me if i am wrong.
RO
37
pdfcrowd.com
vinayak
38
sukhbir
39
Great Job!!
MYZJ forever...
40
Munish
41
well done
foyufugfogfopu
42
great help
chandrashekar
43
hemant
44
pdfcrowd.com
shesh nath
45
Chamanlal
46
Ramesh,
U r not a beginner bro..
moses chisanga
47
This is very good., am a bigginer but i know that very soon will be very far
Ramesh Velauthem
48
pubudu
49
Tb
50
pdfcrowd.com
abhi
51
Ramesh,
Nice list. very helpful.
Prabin seth,
you are right.
sanvi
52
sudo command
moumita
53
Hi
I have a question.How can I construct a pipe to execute the following?
Output of who should be displayed on the screen with value of total number of users who
have logged in
displayed at the bottom of the list.
Thankx
Moumita
Rajendeer
54
pdfcrowd.com
Thnks
pathum
55
Shradha
56
Welly
57
Aslam
58
59
Thanks
Vijay
Very good explanation with examples. Can you provide just brief explanation about command
eg, awk what is mean by awk ? (remembering purpose)
Thank you!
Ashok
60
pdfcrowd.com
Prr Suresh
61
Very useful to beginners like me. You might have included vim editor commands with its
useful options and its subcommands
Vivek
62
Hi, Does anyone know how I can install UNIX on my laptop to practice unix commands?
Vivek.
Elex
63
@vivek Install one of the linux distribution on your system. Ubuntu will be good for you.
If you want dual boot, Install ubuntu with WUBI that is windows based ubuntu installer.
If you do not want dual boot, install virtual box on your windows and install ubuntu into it. You
can find free ubuntu iso file on ubuntu-website.
Wes
64
b2
65
pdfcrowd.com
meena
66
charan nm
67
very usefull
Ashok
68
Anonymous
69
Hi Ramesh
Excellent
Mikkh
70
Yum and rpm only really apply to Red Hat/Fedora or rpm distributions shouldnt really be in
this list IMO unless you also include the equally common apt for Debian distributions, emerge
for Gentoo etc etc.
A command I find useful is uname for finding out various bits of system info but mostly by me
for what kernel is currently installed
uname -r display kernel number installed
pdfcrowd.com
sanjeev
71
david
72
Ebby
73
hi, Could please help me in getting the UNIX code to display a message box if the file size is
85% full?
Ramesh
74
awesome bro.
Yogesh Choudhary
75
seyi
76
pdfcrowd.com
I wish to know if there is a command that can be used to increase the space allocated to an
application (e.g a simulator). Help with it.
77
satish
78
OM PRAKASH SINGH
79
Hi Dear
I found these commands are very useful and now I am studying. Actually where I am working
there Linux, AIX6 and Solaris 10 server is used. I wanted to know how to connect tata photon
in Red hat linux 5. Please help me. I shall remain thankful to
you forever.
thanks
pommuraj
80
thank you.
Ramachandra
81
pdfcrowd.com
Durjoy
82
Ramesh
83
Thanks a lot. If you write another article, please include the below commands.
netstat
tcpdump
route
ntpq
nslookup, dig, host
mail
uptime
waleed butt
84
snsn
85
Thanks a lot.
vinayak
86
pdfcrowd.com
whoami
MMR
87
Great Collection
Thanks
farhad
88
Subrat N
89
Rahul SIngh
90
Hareesh
91
Green
92
pdfcrowd.com
Can any one help me out how the sed and awk command working in the example 5 and 6 to
get reverse order and Remove duplicate lines using awk.
rajendar
93
sameer
94
hi,
Thank you for posting useful commands.
mahesh bomble
95
riten
96
pls send me how to create log file(tape wirrten is normal file, normal file format only not tar
file format)
ismail
97
tulasi
98
pdfcrowd.com
thank you
very useful
ramac
99
Anoop
100
Corbeaux
101
riten
102
pls anyone write commond how to create log file (text file), file written by normal format in
3592 tape.
sinjish
103
pdfcrowd.com
shresta
104
amit
105
Adam
106
if you include rpm and yum, how about apt/dpkg and pacman?
octopus
107
riten
108
Milan
109
pdfcrowd.com
sudhakar reddy
110
raj
111
Harikrishna
112
Hi
Thanks for thinking and sharing knowledge about collection of things required for Unix user.
Ravi
113
deepak
114
Very precise and useful like me beginners. Want to see more commands.
pGwtech
115
Anonymous
116
pdfcrowd.com
Shailendra
117
Neeraj
118
hi,
i m new, this may help me i think, I would like to know the similarity of windows / dos
commands with linux / unix commands.
It would be helpful to those who want to use linux in place of windows / dos.
119
A.Nagaraju
120
good !
Krishna
121
Good
meenu tiwari
122
thanks
pdfcrowd.com
Aditya Rajawat
123
Good list
Deep
124
This is a really nice article for everyone. I sent the link to every friend who know Unix/Linux.
Thanks a lot!
Deep
125
Mahesh
126
Thanks,
This is very help full for beginners,Keep on posting few more.
Subba Reddy
127
dharamvir
128
great
Anju
129
pdfcrowd.com
good
Samah
130
Tarakraj bist
131
KAnagaraj
132
How can i install exe file in linux (for ex-NHM Writer 1511.exe)
Curt
133
Curt
134
Naresh
135
pdfcrowd.com
Priyabrata Karan
136
Leave a Comment
Name
E-mail
Website
Submit
pdfcrowd.com
P RE V IOUS P OS T :
NE X T P OS T :
Contact Us
Support Us
Follow us on Twitter
Copyright 20082013 Ramesh Natarajan. All rights reserved | Terms of Service | Advertise
pdfcrowd.com