You are on page 1of 15

Ashutosh KS (Http://Www.Hongkiat.Com/Blog/Author/Ashutosh_ks/) — Get daily articles in your inbox for free.


Desktop (Http://Www.Hongkiat.Com/Blog/Category/Desktop/)

29 Linux Commands You Must Know Insert email address Subscribe!

Linux distributions support various GUIs (graphical user interfaces) but the old
command line interface (bash) still proves to be easier and quicker in some
situations. Bash and other Linux shells (http://www.hongkiat.com/blog/basic-shell-
commands-for-bloggers/) require you to type in commands to complete your tasks,
and thus gets named the command line (http://www.hongkiat.com/blog/plain-
english-terminal-commands-betty/) interface.

Commands are directives for the computer to carry out a task. You can use
commands to shut down your computer, or show a list of files in the current
directory or the contents of a text file, or to show a message on the screen. They’re
easy and powerful at the same time.

If you are new to this and have always wanted to try it out, we’ve compiled a list of
various basic Linux commands that you can learn and use for various tasks in
several Linux distros (http://www.hongkiat.com/blog/elementary-os-luna/). The list
is not exhaustive but it should make for a good start for beginners or intermediate
Linux users or administrators.

ls – List
ls lists the contents (files and folders) of the current working directory. It’s the
same as you opening a folder in file explorer to see its contents in GUI.

mkdir – Make Directory


mkdir <new‐directory‐name> makes (or creates) a new directory. It’s the same as
you using the context menu’s ‘new/create directory’ option to create a new folder
(or directory) using file explorer in GUI.
pwd – Print Working Directory
pwd prints the current working directory.

cd – Change Directory
cd <directory> sets the given folder (or directory) as the current working directory
for the current running session of the terminal (or bash). It’s the same as you
opening a directory to do some operations using file explorer in GUI.

rmdir – Remove Directory


rmdir <directory‐name> removes (or deletes) the given directory.
rm – Remove
rm <file‐name> removes the given file or folder. You can use rm ‐r <directory‐
name>  to delete folders recursively.

cp – Copy
cp <source‐file> <destination‐file> copies the file or folder from one location to
another location. You can use its cp ‐r <source‐folder> <destination‐folder>
option to copy folders recursively.

mv – MoVe
mv <source> <destination> moves a file or folder from one location to another
location. It can also act to rename the file or folder if the file or folder is in the
current working directory but the file or folder has a new name.
cat – concatenate and print files
cat <file> concatenates and prints files on the standard output (i.e., the monitor
or computer’s screen). It’s the same as you viewing contents of text files using text
viewer or editor in GUI.

tail – print TAIL (from last)


tail <file‐name> prints the last 10 lines (by default) of the given file on the
standard output (i.e., the computer’s screen or monitor). You can use tail ‐n N
<file‐name> to dictate the last N number of lines to print on the screen.
less – print LESS
less <file‐name> prints the given file page by page (or window by window). It’s
useful and efficient for viewing large files containing lots of textual data that won’t
fit on the screen. You can press Ctrl+F to go forward and Ctrl+B to go backward by
one page. It’s the same as you viewing the contents of a text file in a text viewer or
editor and reading the file page by page in GUI.
grep
grep "<string>" <file‐name> searches for a given string in a given file. You can
use grep ‐i "<string>" <file‐name> to make a case-insensitive search and grep ‐
r "<string>" <file‐name> to search for the given string in all files recursively in
the current working directory.

Find
This command searches for files matching specified criteria in the given location.
You can use find <folder‐to‐search> ‐name <file‐name> its ‘-name’ option to
make a case sensitive search and find <folder‐to‐search> ‐iname <file‐name> to
make a case-insensitive search for files with the given file names.

1 find <folder‐to‐search> ‐iname <file‐name>
tar
This command creates, views and extracts tar archives. You can use tar ‐cvf
<archive‐name.tar> <file1‐OR‐file2‐OR‐both‐to‐archive> to create, tar ‐tvf
<archive‐to‐view.tar> to view and tar ‐xvf <archive‐to‐extract.tar> to extract
tar archives.

gzip
gzip <filename> creates and extracts gzip archives. You can use its gzip ‐d
<filename> to extract gzip archives.

unzip
unzip <archive‐to‐extract.zip> unzips a given zip archive. You can use unzip ‐l
<archive‐to‐extract.zip> to view the contents of the zip file without extracting it.
It’s the same as you using an archive program to extract zip archives in GUI.

help
<command‐name> ‐‐help lists all the available commands in the terminal. You can
use ‘-h’ or ‘–help’ (help has two hyphens here) option with any command to get
help for that specific command.
whatis – What is this command
whatis <command‐name> shows a single-line description for the given command.

man – Manual
man <command‐name> shows the manual page for the given command.
exit
exit ends the current terminal (bash) session. It’s the same as you clicking on the
close button in the title bar of any application to close that application in GUI.

ping
ping <remote‐host‐address> pings a remote host (server) by sending ping packets.
It can be used to check for network connectivity or the status (up and running or
otherwise) of a server. It’s the same as you pinging a host using the network
manager in GUI.
who – Who Is logged in
who shows the list of currently logged in users.

 20 Free, Multi-Purpose Iconsets You 


8 Ways to Get More Free Space on

(http://www.hongkiat.com/blog/free­
Should Bookmark (http://www.hongkiat.com/blog/more­
Dropbox

iconset­websites/) space­dropbox/)

su – Switch User
su <username> switches to a different user. Super user (root) can switch to any
other user in the terminal even without using their password.


(http://www.facebook.com/sharer.php?
u=http%3A%2F%2Fwww.hongkiat.com%2Fblog%2Fbasic-
linux-
commands%2F&t=29%20Linux%20Commands%20You%20Must%20Know)


(http://twitter.com/share?
text=29%20Linux%20Commands%20You%20Must%20Know&url=http%3A%2F%2Fwww.hongkiat.com%2Fblog%2Fbasic-
linux-
commands%2F&via=hongkiat)
uname

(https://plus.google.com/share?
uname shows important information about your system such as kernel name, host
url=http%3A%2F%2Fwww.hongkiat.com%2Fblog%2Fbasic-
linux- kernel release number, processor type and various others. You can use uname
name,
commands%2F&t=29%20Linux%20Commands%20You%20Must%20Know)
‐a to view all information.

free – Free memory


free shows information about the free, used, swap memory available (or currently
free) in your system. You can use free ‐m to view memory in KBs and free –g to
view memory in GBs.

Popular In Hongkiat
df – Disk space Free
df shows information about the file system’s disk space usages – used and 10 Interesting Talks
Designers Must
available storage space on your hard disk and other storage devices. You can use df Watch
(http://www.hongkiat.com/blog/must­
(http://www.hongkiat.com/b
‐h to view the space usages in human readable form (i.e. memory in GBs).
watch­talks­
designers/)
watch­talks­
designers/)
Web Design
(/Blog/Category/Design)

9 Coolest Kids That
Will Definitely Inspire
You!
(http://www.hongkiat.com/blog/coolest­
(http://www.hongkiat.com/b
kids­that­
inspire/)
kids­that­inspire/)
People
(/Blog/Category/People)

404 Not Found & 9
Most Common HTTP
Errors Explained
(http://www.hongkiat.com/blog/common­
(http://www.hongkiat.com/b
http­errors/)
http­errors/)
ps – ProcesseS Hosting
(/Blog/Category/Hosting)
ps displays information about the running processes of the system.

20 Free VPN Services
– Best of
(http://www.hongkiat.com/b
(http://www.hongkiat.com/b
(http://www.hongkiat.com/blog/free­
virtual­private­
virtual­private­
networks/)
networks/)
Internet
(/Blog/Category/Internet)

How to Manage Gen
X, Y and Z in the
Workplace
(http://www.hongkiat.com/blog/gen­
[Infographic]
x­y­z­
workplace/)
(http://www.hongkiat.com/b
x­y­z­workplace/)
Office
(/Blog/Category/Office)

Top – TOP processes


29 Linux Commands
top shows information about the top processes in the system (sorted by CPU usage
You Must Know
by default). You can use top ‐u <username> to view the top processes of a single (http://www.hongkiat.com/b
(http://www.hongkiat.com/blog/basic­
linux­commands/)
user. It’s the same as you viewing the list of the most resource-hungry running linux­
Desktop
commands/)
processes using some task manager in GUI. (/Blog/Category/Desktop)

8 Ways to Get More
Free Space on
Dropbox
(http://www.hongkiat.com/blog/more­
(http://www.hongkiat.com/b
space­
dropbox/)
space­dropbox/)
Desktop
(/Blog/Category/Desktop)

15 Fun Games for the
Bored Designer
(http://www.hongkiat.com/b
(http://www.hongkiat.com/blog/games­
to­test­design­skills/)
to­test­design­
Desktop
skills/)
(/Blog/Category/Desktop)

Google Polymer –
How It’ll Change the
Way Web Apps are
(http://www.hongkiat.com/blog/google­
Built
polymer/)
(http://www.hongkiat.com/b
polymer/)
Toolkit
shutdown (/Blog/Category/Toolkit)

shutdown shuts down your computer. You can use shutdown ‐r to restart your
computer. 12 YouTube Tricks
You Probably Didn’t
Know
Did you use or practice some of these commands? Do you know any other useful (http://www.hongkiat.com/blog/youtube­
(http://www.hongkiat.com/b
tips­tricks­
Linux command for beginners? Kindly let us know using the comments section. 2015/)
tips­tricks­2015/)
Social Media
(/Blog/Category/Social-
Media)
Now Read:
9 Linux Commands & Codes to be Wary of
(http://www.hongkiat.com/blog/linux-commands-to-avoid/)
15 WordPress Plugins
to Supercharge
Search Function
Search Function
(http://www.hongkiat.com/blog/wordpress­
(http://www.hongkiat.com/b
search­
plugins/)
search­plugins/)
WordPress
(/Blog/Category/Wordpress)

8 Classroom
Management Apps for
Tech Savvy Teachers
(http://www.hongkiat.com/blog/classroom­
(http://www.hongkiat.com/b
management­
tools/)
management­tools/)
Desktop
(/Blog/Category/Desktop)

CSS Shorthand vs.
Longhand – When to
Use Which
(http://www.hongkiat.com/blog/css­
(http://www.hongkiat.com/b
shorthand­
longhand­
shorthand­longhand­
notations/) notations/)
(http://www.hongkiat.com/blog/linux-commands-to-avoid/) Coding
(/Blog/Category/Coding)

Cornerstone: The
Readers also read: WordPress Page
Builder Web
(http://www.hongkiat.com/blog/cornerstone­
Designers Will Love
page­builder/)
(http://www.hongkiat.com/b
page­builder/)
WordPress
(/Blog/Category/Wordpress)

WWDC 2014: 8 Coolest Wine + 6 Other Apps Windows XP that looks


Features From The To Run Windows like Windows Vista 30 Bizarre Mobile
New Mac OS X Programs On Other (http://www.hongkiat.com/blog/windows­ Phone Covers &
Yosemite Platforms xp­that­looks­like­ Cases You Can Buy
(http://www.hongkiat.com/blog/mac­
(http://www.hongkiat.com/blog/running­
windows­vista/) (http://www.hongkiat.com/blog/unusual­
(http://www.hongkiat.com/b
phone­
os­x­yosemite­cool­ windows­app­on­
casings/)
phone­casings/)
features/) other­platforms/) Gadgets
(/Blog/Category/Gadgets)

Read more posts on: linux (http://www.hongkiat.com/blog/tag/linux/) ,
20 Free, Multi­
linux commands (http://www.hongkiat.com/blog/tag/linux­commands/) Purpose Iconsets You
Should Bookmark
(http://www.hongkiat.com/blog/free­
(http://www.hongkiat.com/b
iconset­
websites/)
iconset­websites/)
Icons (/Blog/Category/Free-
Icons)

9 WordPress Plugins
That Use Artificial
Intelligence
(http://www.hongkiat.com/blog/artificial­
(http://www.hongkiat.com/b
intelligence­
wordpress­
intelligence­
themes/) wordpress­themes/)
WordPress
(/Blog/Category/Wordpress)

WordPress Theme
Divi 2.4 Gets A
Revamp & New
Revamp & New
3 Comments Hongkiat.com 
1  Login (http://www.hongkiat.com/blog/wordpress­
Features
theme­divi/)
(http://www.hongkiat.com/b
  Recommend ⤤ Share Sort by Newest
theme­divi/)
WordPress
Join the discussion… (/Blog/Category/Wordpress)

Web Outsourcing Gateway  •  2 months ago 20+ Construction


Fun article. My developers were reading this the other day and I just have to check it. I think it's Hoarding Art You
a good collection of must­know commands. Every single one is interesting. Cheers on this, Have to See
(http://www.hongkiat.com/blog/creative­
(http://www.hongkiat.com/b
guys. :) construction­
construction­
△  ▽ • Reply • Share ›  hoardings/)
hoardings/)
Ashutosh Kumar Singh > Web Outsourcing Gateway  •  a month ago Artwork
(/Blog/Category/Artwork)
Thanks for the appreciation. It's a simple crash course for Linux's CLI beginners. :)
△  ▽ • Reply • Share › 
10 Useful Image Tools
Ralph Rothschild  •  2 months ago Every Social Marketer
Good article. You can also learn about different command flags with "­­help".  Needs
For example, "ls ­­help" to learn more about the "ls" command. (http://www.hongkiat.com/blog/social­
(http://www.hongkiat.com/b
media­imaging­
1 △   ▽ • Reply • Share › 
tools/)
media­imaging­tools/)
Social Media
(/Blog/Category/Social-
Media)
✉ Subscribe d Add Disqus to your site ὑ Privacy

About (/blog/about­us/)   Advertise (/blog/advertise/)   Contact (/blog/contact/)   Submit Tips (/blog/submit­

news­tips/)   Authors (/blog/authors/)   Write for Us (/blog/write­for­us/)   Publishing Policy (/blog/publishing­

policy/)   Privacy (/blog/privacy­policy­for­hongkiatcom/)   Sitemap (/blog/sitemap.xml)

You might also like