50 Most Unix Commands PDF
50 Most Unix Commands PDF
50 Most Unix Commands PDF
• Home
• About
• Free eBook
• Archives
• Best of the Blog
• Contact
This is not a comprehensive list by any means, but this should give you a jumpstart on some of the common
Linux commands. Bookmark this article for your future reference.
Did I miss any frequently used Linux commands? Leave a comment and let me know.
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 2 of 23
More tar examples: The Ultimate Tar Command Tutorial with 10 Practical Examples
Print the matched line, along with the 3 lines after it.
$ grep -A 3 -i "example" demo_text
More grep examples: Get a Grip on the Grep! – 15 Practical Grep Command Examples
More find examples: Mommy, I found it! — 15 Practical Linux Find Command Examples
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 3 of 23
Print all lines from /etc/passwd that has the same uid and gid
$awk -F ':' '$3==$4' passwd.txt
More awk examples: 8 Powerful Awk Built-in Variables – FS, OFS, RS, ORS, NR, NF, FILENAME, FNR
2c2,3
< John Doe --- > John M Doe
> Jason Bourne
More diff examples: Top 4 File Difference Tools on UNIX / Linux – Diff, Colordiff, Wdiff, Vimdiff
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 4 of 23
$ sort names.txt
Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr
$ ls -ltr
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 5 of 23
More bzip2 examples: BZ is Eazy! bzip2, bzgrep, bzcmp, bzdiff, bzcat, bzless, bzmore examples
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 6 of 23
To view the file names located on the remote server before downloading, mls ftp command as shown below.
ftp> mls *.html -
/ftptest/features.html
/ftptest/index.html
/ftptest/othertools.html
/ftptest/samplereport.html
/ftptest/usage.html
More ftp examples: FTP and SFTP Beginners Guide with 10 Examples
Restart a service.
# service ssh restart
While there are lot of arguments that could be passed to a ps command, following are some of the common ones.
To view current running processes in a tree structure. H option stands for process hierarchy.
$ ps -efH | more
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 7 of 23
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 used free shared buffers cached
Mem: 3 1 1 0 0 0
-/+ buffers/cache: 0 2
Swap: 3 0 3
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 used free shared buffers cached
Mem: 3566408 1592148 1974260 0 204260 912556
-/+ buffers/cache: 475332 3091076
Swap: 4000176 0 4000176
Total: 7566584 1592148 5974436
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 -h displays output in human readable form. i.e size will be displayed in GB’s.
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
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 8 of 23
$ kill -9 7243
More kill examples: 4 Ways to Kill a Process – kill, killall, pkill, xkill
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. This also removes
the example directory itself.
$ rm -r example
Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ cp -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
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 {
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 9 of 23
2 missingok
3 monthly
4 create 0660 root utmp
5 rotate 1
6 }
You can also add this to the fstab for automatic mounting. i.e Anytime system is restarted, the filesystem will be
mounted.
/dev/sdb1 /u01 ext2 defaults 0 2
Give full access to user and group (i.e read, write and execute ) on a specific file.
$ chmod ug+rwx file.txt
Revoke all access for the group (i.e read, write and execute ) on a specific file.
$ chmod g-rwx file.txt
Apply the file permissions recursively to all the files in the sub-directories.
$ chmod -R ug+rwx file.txt
To change owner to oracle and group to db on a file. i.e Change both owner and group at the same time.
$ chown oracle:dba dbora.sh
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
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 10 of 23
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 doesn’t exist, it will create them.
$ mkdir -p dir1/dir2/dir3/dir4/
Start or stop a specific interface using up and down command as shown below.
$ ifconfig eth0 up
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.
$ whereis -u -B /tmp -f lsmk
lsmk: /tmp/lsmk
$ whatis ifconfig
ifconfig (8) - configure a network interface
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 11 of 23
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
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.
$ man SECTION-NUMBER commandname
1. General commands
2. System calls
3. C library functions
4. Special files (usually devices, those found in /dev) and drivers
5. File formats and conventions
6. Games and screensavers
7. Miscellaneous
8. System administration commands and daemons
For example, when you do whatis crontab, you’ll notice that crontab has two man pages (section 1 and section 5).
To view section 5 of crontab man page, do the following.
$ whatis crontab
crontab (1) - maintain crontab files for individual users (V3)
crontab (5) - tables for driving cron
$ man 5 crontab
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
More tail examples: 3 Methods To View tail -f output of Multiple Log Files in One Terminal
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 12 of 23
One you open a file using less command, following two keys are very helpful.
CTRL+F – forward one window
CTRL+B – backward one window
More less examples: Unix Less Command: 10 Tips for Effective Navigation
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 john’s account.
[john@dev-server]$ su - raj -c 'ls'
[john@dev-server]$
Login to a specified user account, and execute the specified shell instead of the default shell.
$ su -s 'SHELLNAME' USERNAME
If you want to specify the mysql root password in the command line itself, enter it immediately after -p (without
any space).
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 13 of 23
More rpm examples: RPM Command: 15 Examples to Install, Uninstall, Upgrade, Query RPM Packages
Once you’ve changed the system date, you should syncronize the hardware clock with the system date as shown
below.
# hwclock –systohc
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.
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 14 of 23
Hi Ramesh,
Thank you !!!!
Please prepare one more treat for Christmas and New year 2011.
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:
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 15 of 23
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
• whereis, locate – use “which” in Solaris, although not as powerful
• mysql – not installed
• yum, rpm – RedHat Package Manager tools, so not relevant for Solaris
• ping – available as /user/sbin/ping, and with significant differences from the Llinux version the linked
tutorial shows, so check the Solaris ping man page ( “ man ping “) to see its syntax – very useful for
troubleshooting connectivity issues.
• date – only root Id can change the date/time – normally one uses date command to view it, and there are
many format options, so check “man date” and “man strftime “ for that formatting info.
I think distinguishing at least superuser-specific commands in a separate list might be helpful, as well as
Linux-specific commands like “free” (thinking I might see if I can make an alias to massage vmstat, iostat,
and some others for a similar output – would be useful).
RO
Filters the ps output based on the given procname — very useful to see if a particular process is running, or
to find it’s pid. (Similar functionality is available via pgrep as well.)
But this is a handy list, nonetheless. I suspect it will be showing up in a lot of Google searches.
This is a really nice article for everyone. I sent the link to every friend who know Unix/Linux. Thanks a
lot!
awesome!
Nice list.
Possible additions:
rsync
nano (in vi category)
sudo (in su category)
apropos (in man category)
who, whoami,groups
whois
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 16 of 23
exit or ctrl-d
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.”.
In case you don’t want tar to list the files it processed (because you want a clean terminal ), simply
remove the letter “v” (“v” for “verbose” [not vendetta ]) from the options:
for creating a tar, use “tar cf ” instead of “tar cvf ”
for extracting a tar, use “tar xf ” instead of “tar xvf ”
for viewing a tar use “tar tf ” instead of “tar tvf “
Thanks
Title of this article is kinda inaccurate. Several examples aren’t 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.
Nice list
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).
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 17 of 23
Thanks Ramesh! This is a very useful list for new Linux users to use for reference. Really gets you up to
speed quickly!
1. tutorial on chkconfig?
2. how to set up a temporary and a permanent route?
3. how to check SAN?
Thank You!!
Thank U Sir,
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
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
You should include print commands like lpr, lpoptions, lpstat too
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 18 of 23
Great list, I’m in college and taking a few linux admin classes, and my teacher was trying to do a lesson on
Crontab, but for whatever reason couldn’t remember how to do it. I looked it up on here and was able to
look smart in front of the whole class
for example.
Sorry about the previous grep comment — it was at the top of your 50 and I missed it. Dooh!
i think it should be
tar -cvf archive_name.tar dirname/
instead of
tar cvf archive_name.tar dirname/
The first argument to tar should be a function; either one of the letters
Acdrtux, or one of the long function names. A function letter need not
be prefixed with “-”,
I have not used a dash prefix for a long time (maybe since it is not allowed (?) in Solaris version, which is
what I use more than Linux for work like that).
Great Job!!
very excellent!!!!
well done
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 19 of 23
great help
Ramesh,
U r not a beginner bro..
This is very good., am a bigginer but i know that very soon will be very far
Leave a Comment
Name
Website
Submit
Previous post: Linux Strings Command Examples (Search Text in UNIX Binary Files)
Next post: Linux modprobe Command Examples to View, Install, Remove Modules
Search
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 20 of 23
• EBOOKS
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 21 of 23
• POPULAR POSTS
◦ 12 Amazing and Essential Linux Books To Enrich Your Brain and Library
◦ 50 UNIX / Linux Sysadmin Tutorials
◦ 50 Most Frequently Used UNIX / Linux Commands (With Examples)
◦ How To Be Productive and Get Things Done Using GTD
◦ 30 Things To Do When you are Bored and have a Computer
◦ Linux Directory Structure (File System Structure) Explained with Examples
◦ Linux Crontab: 15 Awesome Cron Job Examples
◦ Get a Grip on the Grep! – 15 Practical Grep Command Examples
◦ Unix LS Command: 15 Practical Examples
◦ 15 Examples To Master Linux Command Line History
◦ Top 10 Open Source Bug Tracking System
◦ Vi and Vim Macro Tutorial: How To Record and Play
◦ Mommy, I found it! -- 15 Practical Linux Find Command Examples
◦ 15 Awesome Gmail Tips and Tricks
◦ 15 Awesome Google Search Tips and Tricks
◦ RAID 0, RAID 1, RAID 5, RAID 10 Explained with Diagrams
◦ Can You Top This? 15 Practical Linux Top Command Examples
◦ Top 5 Best System Monitoring Tools
◦ Top 5 Best Linux OS Distributions
◦ How To Monitor Remote Linux Host using Nagios 3.0
◦ Awk Introduction Tutorial – 7 Awk Print Examples
◦ How to Backup Linux? 15 rsync Command Examples
◦ The Ultimate Wget Download Guide With 15 Awesome Examples
◦ Top 5 Best Linux Text Editors
◦ Packet Analyzer: 15 TCPDUMP Command Examples
◦ The Ultimate Bash Array Tutorial with 15 Examples
◦ 3 Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id
◦ Unix Sed Tutorial: Advanced Sed Substitution Examples
◦ UNIX / Linux: 10 Netstat Command Examples
◦ The Ultimate Guide for Creating Strong Passwords
◦ 6 Steps to Secure Your Home Wireless Network
◦ Turbocharge PuTTY with 12 Powerful Add-Ons
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 22 of 23
• Support Us
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12
50 Most Frequently Used UNIX / Linux Commands (With Examples) Page 23 of 23
• Contact Us
Email Me : Use this Contact Form to get in touch me with your comments, questions or suggestions about
this site. You can also simply drop me a line to say hello!.
Follow us on Twitter
Copyright © 2008–2012 Ramesh Natarajan. All rights reserved | Terms of Service | Advertise
Vi & Vim Video Tutorial Learn Free by Just Watching! Designed for Absolute Beginners www.DecisionScienceNews.com
LinuxLIVE for Linux PCs Suspend-Resume, Sharing, Mobility and Re-Connect to Remote X Sessions www.starnet.com
Janison Learning Systems Learning systems and portal on Web and Microsoft Azure www.janison.com.au
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 01-Mar-12