22
2010
40 Linux Shell Commands for Beginners
Linux has more than 650 commands and every command has its own set of options all performing different operations. Going through each and every one of these commands will be a very tedious task. However limiting yourself to only a few of them is never an option. The trick here to learning all these commands, is to categorise them according to their function. By doing this, you will know atleast the basic commands and have some measure of control over the Linux command line.
When you go through these commands, you will be able to perform different function as per your need in the Linux command line.
- Basic Commands
- Editor
- User Account
- Network Commands
- Archive Commands
- Help Commands
- Package Management Utilities
- Process Commands
Basic Commands
The ‘must’ know commands fall in this category. I have distributed the commands into two sub categories: Directory commands and File commands.
Directory Commands
-
- pwd : Print working directory
- mkdir : Create directories
- cd : Change the current directory
- rmdir : Remove directories
File Commands
-
- ls : List directory contents
- rm : Remove files
- cp : Copy files from a source to the same or different target(s).
- mv : Move file to different targets.
- cat : Read one or more files and print them to standard output. If you need to
view contents of a short file, cat is recommended.
-
- cmp: Compare two files byte by byte.
- wc: Print the number of new lines, words, and bytes in files.
- du : Estimate disk usage of each file and recursively for directories.
- find: Search for files in directory hierarchy, e.g. find notes.txt
- grep: Print lines matching a pattern,e.g. grep –i topic notes.txt (topic is the pattern)
- sort: Sort lines of text files
Editor
Every Linux program is an executable file. For instance, the cp command is provided by the file in /bin/sh which holds the list of machine instructions. Similarly, if you are installing a package , let’s say vsftpd, your focus will be modifying its configuration file , vsftpd.conf present in /etc directory. This is where you will be using editors.
I use ‘Vim’ frequently. It’s an advanced text editor that comes with a more complete feature than the ‘Vi’ text editor. The other text editors are: nano, vi, kate, (KDE Advanced Text Editor), gedit (graphical user interface).
e.g. vim rabi.c ( vim filename ).
User Account
In linux, you can say that using the ‘root’ account is like having the powers of God. You will have access to almost each and every file(configuration files, system , text files etc) with no interruption and restriction. You need to be very careful while doing work as the root (super user). Therefore, managing user accounts and groups is an essential part of a system administrator.
For example, an organization ABC has three departments: Marketing, Technical and Account, each department having 3-4 employees. The organization demands you to verify the users of marketing, technical and account departments so that the employees of each group will be able to view his/her own department file.
Given a scenario, if you know how to manage these accounts, you can easily set permissions for the users mentioned above. If not, these commands are essential for the task.
- useradd : for creating user account.
This command can be executed by administrators only. On debian, you should use adduser. For other options like adding expiry date, home directory etc refer man useradd.
- passwd : for changing user password.
If the user has set password before, he/she will be prompted for the first password whereas superuser is permitted to bypass the step so that forgotten passwords may be changed.
You can find advices on how to choose a strong password on http://en.wikipedia.org/wiki/Password_strength
- usermod : modify user accoun.
- userdel : delete a user account and related files
This command can be executed by administrators only.
- groupadd : create a new group
- groupdel : delete the group and entries referring to the group
- groupmod : modify a group definition on the system
- chmod : modify properties for users
- chown : change file owner and group
- chgrp : change group ownership
Network Commands
Linux is predominantly known for its use in servers. In 2009 it held a server market share ranging between 20–40%(source : wikipedia). One should know the commands to check the ip address, download files from the net, get DNS, etc.
wget : a non-interactive network downloader
Even if a download fails due to a network problem, it will keep retrying until the whole file has been retrieved. The server will instruct to continue to download from where it it left off.
$ wget url-for-file
ping : send ICMP ECHO_REQUEST to network hosts, you will get back ICMP packet if the host responds. This command is useful when you are in a doubt whether your computer is connected or not.
$ ping IP or host name
hostname : show or set the system’s host name
dnsdomainname : show the system’s DNS domain name
netstat : displays the status of ports ie. which ports are open, closed, waiting for connections. It displays the contents of /proc/net file.
ifconfig : configure a network interface, or to display their current configuration. It is also useful to get the information about IP address, Subnet Mask,set remote IP address , Netmask etc.
ifup : bring a network interface up
ifdown : take a network interface down
Archive Commands
You want to install a package from its source code. You find out that the source code of the package is archived in a file xxx.tar. In this situation, the command-line utility ‘tar’ proves to be a vital resource for you. The ‘tar’ is probably the most popular Linux backup utility. If the ‘tar’ file is compressed with the compression utility like ‘bzip’ or ‘gzip’, the resulting file is the famous ‘tarballs’ which is a common method to deliver software installation archives.
tar : an archiving program designed to store and extract files from an archive known as a tarfile.
Options :
-c : create a new archive
-r : append files to the end of an archive
-t : list the contents of an archive
-u : only append files that are newer than copy in archive
-x : extract files from an archive
-C : change to directory Dir
-j : filter archive through bzip2, use to decompress .bz2 files.
-v : verbosely list files processed
-f : use archive file
-z : filter the archive through gzip
Examples: tar -xvf test.tar ( extract foo.tar to the current location)
tar -xvzf test.tar.gz ( extract gzipped test.tar.gz )
tar -cvf test.tar foo/ ( compress the contents of foo folder to foo.tar )
Help commands
There are manual pages for almost all the commands of Linux. You can access the manual pages using man command. The man command offers documentation of the command. If you type:
$ man ls
You will be seeing the manual page of ls with its name, synopsis, description, author, copyright etc. Remember, there is a manual page for the man command itself.
If you desire to have a brief reference of the command, use -help option with the command. $ ls -help
You can even use info command to have a quick overview of the command. $ info ls
Remember, that memorizing all the commands in Linux along with all its options is a very difficult job. So memorise the command and options which has frequent usage and leave the rest to the HELP commands.
Package Management Utilities
On RED HAT, SUSE, and many similar Linux distributions, the RPM Package Manager (RPM) format is used. Ubuntu and Debian, however, uses the Debian Pacakge (DEB) format. Therefore, I have categorised it into two, one for RPM and the other for Debian.
For RPM format, the rpm and yum is prefered.
rpm options rpm-package-name (use man rpm for further more information) The -q option tells you if a package is already installed, and the -qa option displays a list of all installed packages.
-qa : List all installed RPM applications -qf : Lists applications that own filename -qR : Lists applications on which this application depends -qi : Displays all application information -qd : Lists only documentation files in the application -qc : Lists only configuration files in the application
If you add p qualifier to the above options, gives information about specific package. For e.g. -qpl : Lists files in the RPM package
Yum (Yellowdog Update modifier) -yum is an automatic updater and package installer/remover for rpm systems. It automatically computes dependencies and figures out what things should occur to install packages. You need to install yum in your Linux system.
yum command package-name
e.g. $yum install package-name
Its configuration file is /etc/yum.
For Debian packages, Advanced Package Tool (APT) and Debian Package Tool (dpkg) is preferred.
apt command package-name use apt-get install package-name to install a package.
Similarly, if you want to upgrade a package use apt-get upgrade package-name. With no package specified, apt-get with the upgrade command will upgrade your entire system for FTP site, or CD. You can find configuration files in /etc/apt. There are sources.list, apt.conf files to look for.
dpkg(Debian package tool) is another method to install a binary file with the format .deb. To install , type $dpkg -i xxxx.deb
To remove, $dpkg -r xxxx.deb.
Process commands
In order to execute a command in the background, place an ampersand(&) on the command line at the end of the command. A user job number(placed in brackets) and a system process number are displayed. A system process number is the number by which the system identifies the job whereas a user job number is the number by which the user identifies the job.
$ sudo cp -rf * ~/ss &
[1] 9144
$
- jobs : lists the jobs being run at the background
$jobs
[1]- Running sudo cp -rf * ~/ss &
[2]+ Running sudo cp -rf * ~/yy &
- The ‘+‘ sign indicates the job currently being processed , ‘-’ sign indicates the upcoming jobs to be executed. The ‘% ‘ used with the job number refrences a job. e.g. Used in fg.
- fg : a process running in the background will be processed in the foreground
$ fg % 2
cat *.cpp > mytext
$
- kill : cancels a job running in the background, it takes argument either the user job number or the system process number.
$jobs
[1] + Running cp *.c > mytext
[2] - Running cp *.dat >>mytext
$kill %2
- bg: places a suspended job in the background
$ cat *.cpp > mytext
^Z
$bg
( Ctrl + Z will suspend the process running at the moment )
- ps : reports a snapshot of the current processes
- top : displays Linux tasks
- at : executes commands at a specified time.
$ at 8:00
at > echo “HI” > /dev/tty1
(Press ‘ctrl + d’ to return to the command line. This will display the message in tty1 at 8′o clock.)
- To view the schedule : $ atq
- To cancel a job : $atrm 5 [job ID]
- crontab :crontab is a file which contains the schedule of entries to run at specified times.
- shutdown : bring the system down
- -r Requests that the system be rebooted after it has been brought down.
- -c Cancels a running shutdown.
Other commands
- whoami : displays the login name of the current effective user.
- logname : print user´s login name
- quota : display disk usage and limits, e.g $ quota -v
- su : switch to super user or change user ID
- which : returns the pathnames of the files which would be executed in the current environment.
Type $which ls, you will get /bin/ls.
Subscribe to fortystones.
Follow @fortystones on Twitter.
Get updated from our Facebook Fanpage.
Related Posts
34 Comments + Add Comment
Leave a comment
Fortystones Lab Projects
Categories
- Articles (43)
- Idea (2)
- Review (5)
- Social Media (29)
- Trending Topics (13)
- Collection (29)
- How To (27)
- Linux (28)
- News (15)
- PHP (6)
- Project (2)
- Tutorials (36)
- Java (4)
- Programming (10)
- Wordpress (7)
Popular Posts
- 40 Basic Linux Command-line Tips and Tricks
- Tips and Tricks for Facebook Chat (Save History/ Video Chat/ Send Files)
- 40 Linux Shell Commands for Beginners
- Creating a Simple GUI for Absolute Beginners (Java Tutorials)
- Online Coding Zones for Programmers
- Special: Facebook Smiley, Special Text Symbols and ASCII Arts
- The First on the World Wide Web

An article by







There is a slight correction in the first line.
Old:
“Linux has about 650 commands and every command has its own set of options all performing different operations. ”
New:
“Linux has more than 650 commands and every command has its own set of options all performing different operations. ”
I would say, the number of commands would depend, how many are being packed with the distro, installing additional packages would come with even more programs ie. commands. So there are many commands.
Good Article mate
Even though it had few minor errors. good share
great resource for a newbie like myself.
really very useful post
thankx
nice work guys….
very useful for beginners…..like me
You could add the ip command to the list. It’s a replacement for ifconfig, route and some other commands since .. forever.
I would have added more, tail and the pipe |
Indeed, to be able to pipe commands is maybe the greatest asset of unix-like shells.
♺ @ksaver: 40 #Linux #Shell Commands for Beginners: http://www.fortystones.com/40-linux-shell-commands-beginners/
RT @brainvision ♺ @ksaver: 40 #Linux #Shell Commands for Beginners: http://www.fortystones.com/40-linux-shell-commands-beginners/
RT @ksaver 40 #Linux #Shell Commands for Beginners: http://www.fortystones.com/40-linux-shell-commands-beginners/
40 linux commands for beginners (missing the “nice” and “ionice” commands) http://www.fortystones.com/40-linux-shell-commands-beginners/
[...] 40 linux shell commands for beginners [...]
40 Linux shell commands for beginners : http://www.fortystones.com/40-linux-shell-commands-beginners/
I searched many websites and here i found what i was looking for, thanks for valuable article
Good work ! Keep us posting, you are good writer.
I saw many sites but yours is very interesting, you got talent in writing posts, website bookmarked! Waiting for more info!
Interesting article buddy i should bookmark your site
Hey, something is wrong with your site in Opera, you should check into it.
wow, awesome post, I was wondering the same thing. and found your site by google, many userful stuff here, now i have got some idea. bookmarked and also signed up your rss. keep us updated.
I can’t wait for more posts! When will you update your interesting site?
Great information! I’ve been looking for something like this for a while now. Thanks!
It’s not that I want to duplicate your internet site, but I really like the design. Could you tell me which theme are you using? Or was it tailor made?
Great work keep it coming
[...] So, if you go through this article, you will eventually appreciate the wonders of the shell commands. [...]
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon. Thanks! There’s a lot of smartphone Internet traffic that is generated by people who are just trying to check when they get to go, over and over again.
That may seem very good nonetheless i’m just still less than sure that I favor it. At any rate will look a lot more into it and decide for myself!
Rendering is a good one.
useful article buddy
[...] more information on TAR, refer our previous stone http://www.fortystones.com/40-linux-shell-commands-beginners/ . I highly recommend you to go through manual page of TAR if you have any [...]
[...] more information on TAR, refer our previous stone http://www.fortystones.com/40-linux-shell-commands-beginners/ . I highly recommend you to go through manual page of TAR if you have any [...]
/40-linux-shell-commands-beginners
“Sudo shutdown now” never seems to work for me i don’t know why…
Thanks…
I absolutely love your blog and find many of your post’s to be just what I’m
looking for. Would you offer guest writers to write content for yourself?
I wouldn’t mind publishing a post or elaborating on a lot of the subjects you write in relation to here. Again, awesome web site!
Have a look at my homepage; Ilse