Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 68

Command Description

adduser Add a new user


arch Print machine architecture
awk Find and Replace text within file(s)
bc An arbitrary precision calculator language
cal Display a calendar
cat Concatenate files and print on the standard output
chdir Change working directory
chgrp Change the group ownership of files
chkconfig Tool for maintaining the /etc/rc[0-6].d directory hierarchy
chmod Change the access permissions of files and directories
chown Change the user and group ownership of files
chroot Change root directory
cksum Print CRC checksum and byte counts
clear Clear terminal screen
cmp Compare two files
comm Compare two sorted files line by line
cp Copy one or more files to another location
cron Daemon to execute scheduled commands
crontab Schedule a command to run at a later time
csplit Split a file into context-determined pieces
cut Divide a file into several parts
date Display or change the date & time
dc Desk Calculator
dd Data Dump - Convert and copy a file
df Display free disk space
diff Display the differences between two files
diff3 Show differences among three files
dir Briefly list directory contents
dircolors Colour setup for `ls'
dirname Convert a full pathname to just a path
du Estimate file space usage
echo Display message on screen
ed A line-oriented text editor (edlin)
egrep Search file(s) for lines that match an extended expression
eject Eject CD-ROM
env Display, set, or remove environment variables
expand Convert tabs to spaces
expr Evaluate expressions
factor Print prime factors
false Do nothing, unsuccessfully
fdformat Low-level format a floppy disk
fdisk Partition table manipulator for Linux
fgrep Search file(s) for lines that match a fixed string
find Search for files that meet a desired criteria
fmt Reformat paragraph text
fold Wrap text to fit a specified width
format Format disks or tapes
free Display memory usage
fsck Filesystem consistency check and repair
gawk Find and Replace text within file(s)
grep Search file(s) for lines that match a given pattern
groups Print group names a user is in
gzip Compress or decompress named file(s)
head Output the first part of file(s)
hostname Print or set system name
id Print user and group id's
info Help info
install Copy files and set attributes
join Join lines on a common field
kill Stop a process from running
less Display output one screen at a time
ln Make links between files
locate Find files
logname Print current login name
lpc Line printer control program
lpr Off line print
lprm Remove jobs from the print queue
ls List information about file(s)
man Help manual
mkdir Create new folder(s)
mkfifo Make FIFOs (named pipes)
mknod Make block or character special files
more Display output one screen at a time
mount Mount a file system
mv Move or rename files or directories
nice Set the priority of a command or job
nl Number lines and write files
nohup Run a command immune to hangups
passwd Modify a user password
paste Merge lines of files
pathchk Check file name portability
pr Convert text files for printing
printcap Printer capability database
printenv Print environment variables
printf Format and print data
ps Process status
pwd Print Working Directory
quota Display disk usage and limits
quotacheck Scan a file system for disk usage
quotactl Set disk quotas
ram ram disk device
rcp Copy files between two machines
rm Remove files
rmdir Remove folder(s)
rpm Remote Package Manager
rsync Remote file copy (Synchronize file trees)
screen Terminal window manager
sdiff Merge two files interactively
sed Stream Editor
select Accept keyboard input
seq Print numeric sequences
shutdown Shutdown or restart linux
sleep Delay for a specified time
sort Sort text files
split Split a file into fixed-size pieces
su Substitute user identity
sum Print a checksum for a file
symlink Make a new name for a file
sync Synchronize data on disk with memory
tac Concatenate and write files in reverse
tail Output the last part of files
tar Tape Archiver
tee Redirect output to multiple files
test Evaluate a conditional expression
time Measure Program Resource Use
touch Change file timestamps
top List processes running on the system
traceroute Trace Route to Host
tr Translate, squeeze, and/or delete characters
true Do nothing, successfully
tsort Topological sort
tty Print filename of terminal on stdin
umount Unmount a device
uname Print system information
unexpand Convert spaces to tabs
uniq Uniquify files
units Convert units from one scale to another
unshar Unpack shell archive scripts
useradd Create new user account
usermod Modify user account
users List users currently logged in
uuencode Encode a binary file
uudecode Decode a file created by uuencode
vdir Verbosely list directory contents (`ls -l -b')
watch Execute/display a program periodically
wc Print byte, word, and line counts
whereis Report all known instances of a command
which Locate a program file in the user's path
who Print all usernames currently logged in
whoami Print the current user id and name (`id -un')
xargs Execute utility, passing constructed argument list(s)
yes Print a string until interrupted

The 10 Most Important Linux Commands

By Brad Yale Sep 22, 2014

Topics: Information Technology, Open Source, Linux/UNIX/Open Source, Linux/UNIX/Open Source Operating


Systems, Operating Systems, Server

I get it. 

You're new to the Linux Command Line and truth be told, you might be a little intimidated. Coming from the
comfort of a PC or Mac desktop, the Linux Command Line (CLI) looks nothing like what you normally use.
The Linux CLI is dark, it's secretive, it's bare bones minimal and it's anything but friendly to newcomers. And
yet, the Linux CLI is highly useful, essential to using your Linux box or virtual machine and can, if done right,
provide you with more insight and practical use than the Windows or Mac desktop ever could.
For those reasons, from someone who was also once a Linux newb, I present the top ten Linux CLI commands
you need to master for basic Linux CLI comprehension.

This list will not make your a Linux System Admin however it will get you on your way with your foot in the
ocean.

Before my top ten Linux CLI list, I want to preface this countdown by stating the commands presented are
being presented to give you a working knowledge of how to get around your Linux terminal from the shell. This
list is meant to serve as an introduction to basic yet highly vital Linux CLI commands. 

There are a ton of other commands - more sophisticated commands - which you will one day learn. But for
now, like learning to add before you learn to multiply, this list will provide you with your Linux CLI
command foundation.

At the end of the list, some vital information you need to use the Linux CLI.

1. ls

The ls command - the list command - functions in the Linux terminal to show all of the major directories filed
under a given file system. For example, the command:

ls /applications

...will show the user all of the folders stored in the overall applications folder.

The ls command is used for viewing files, folders and directories.

2. cd

The cd command - change directory - will allow the user to change between file directories. As the name
command name suggest, you would use the cd command to circulate between two different directories. For
example, if you wanted to change from the home directory to the Arora directory, you would input the following
command:

cd/arora/applications

As you might have noted, the path name listed lists in reverse order. Logically cd/arora/applications reads
change to the arora directory which is stored in the applications directory. All Linux commands follow a logical
path.

3. mv

The mv command - move - allows a user to move a file to another folder or directory. Just like dragging a file
located on a PC desktop to a folder stored within the "Documents" folder, the mv command functions in the
same manner. An example of the mv command is:
mv/arora/applications/majorapps /arora/applications/minorapps

The first part of the command mv/arora/applications/majorapps lists the application to be moved. In this


case, arora. The second part of the command /arora/applications/minorapps lists where arora will be moved
to - from majorapps to minorapps.

4. man

The man command - the manual command - is used to show the manual of the inputted command. Just like a
film on the nature of film, the man command is the meta command of the Linux CLI. Inputting the man
command will show you all information about the command you are using. An example:

man cd

The inputting command will show the manual or all relevant information for the change directory command.

5. mkdir

The mkdir - make directory - command allows the user to make a new directory. Just like making a new
directory within a PC or Mac desktop environment, the mkdir command makes new directories in a Linux
environment. An example of the mkdir command

mkdir testdirectory

The example command made the directory "testdirectory".

6. rmdir

The rmdir - remove directory - command allows the user to remove an existing command using the Linux CLI.
An example of the rmdir command:

rmdir testdirectory
The example command removed the directory "testdirectory".

It should be noted: both the mkdir and rmdir commands make and remove directories. They do not
make files and they will also not remove a directory which has files in it. The mkdir will make an empty
directory and the rmdir command will remove an empty directory.

7. touch

The touch command - a.k.a. the make file command - allows users to make files using the Linux CLI. Just as
the mkdir command makes directories, the touch command makes files. Just as you would make a .doc or a
.txt using a PC desktop, the touch command makes empty files. An example of the touch command:

touch testfile.txt

The example touch command effectively created the file testfile.txt. As noted by the extension, the file created
is a .txt or text file. To equate, a .txt file in Linux is akin to a .txt notebook file within a Windows or Mac OS.
8. rm

The rm command - remove - like the rmdir command is meant to remove files from your Linux OS. Whereas
the rmdir command will remove directories and files held within, the rm command will delete created files. An
example of the rm command:

rm testfile.txt

The aforementioned command removed testfile.txt. Interestingly, whereas the rmdir command will only delete
an empty directory, the rm command will remove both files and directories with files in it. This said, the rm
command carries more weight than the rmdir command and should be used with more specificity.

9. locate

The locate - a.k.a. find - command is meant to find a file within the Linux OS. If you don't know the name of a
certain file or you aren't sure where the file is saved and stored, the locate command comes in handy. A locate
command example:

locate -i *red*house**city*

The stated command will locate an file with the a file name containing "Red", "House" and "City". A note on the
input: the use of "-i" tells the system to search for a file unspecific of capitalization (Linux functions in lower
case). The use of the asterik "*" signifies searching for a wildcard. A wildcard tells the system to pull any and all
files containing the search criteria.

By specifying -i with wildcards, the locate CLI command will pull back all files containing your search criteria
effectivley casting the widest search net the system will allow.

10. clear

The clear command does exactly what it says. When your Linux CLI gets all mucked up with various readouts
and information, the clear command clears the screen and wipes the board clean. Using the clear command
will take the user back to the start prompt of whatever directory you are currently operating in. To use the clear
command simply type clear.

50 Most Frequently Used UNIX / Linux


Commands (With Examples)
by RAMESH NATARAJAN on NOVEMBER 8, 2010
This article provides practical examples for
50 most frequently used commands in Linux / UNIX.

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.

1. tar command examples


Create a new tar archive.

$ tar cvf archive_name.tar dirname/

Extract from an existing tar archive.

$ tar xvf archive_name.tar

View an existing tar archive.

$ tar tvf archive_name.tar

More tar examples: The Ultimate Tar Command Tutorial with 10 Practical Examples

2. grep command examples


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

$ grep -r "ramesh" *

More grep examples: Get a Grip on the Grep! – 15 Practical Grep Command Examples

3. find command examples


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

More find examples: Mommy, I found it! — 15 Practical Linux Find Command Examples

4. ssh command examples


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

OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003

More ssh examples: 5 Basic Linux SSH Client Commands

5. sed command examples


When you copy a DOS file to Unix, you could find \r\n in the end of each line. This
example converts the DOS file format to Unix file format using sed command.

$sed 's/.$//' filename

Print file content in reverse order

$ sed -n '1!G;h;$p' thegeekstuff.txt

Add line number for all non-empty-lines in a file

$ sed '/./=' thegeekstuff.txt | sed 'N; s/\n/ /'

More sed examples: Advanced Sed Substitution Examples


6. awk command examples
Remove duplicate lines using awk

$ awk '!($0 in array) { array[$0]; print }' temp

Print all lines from /etc/passwd that has the same uid and gid

$awk -F ':' '$3==$4' passwd.txt

Print only specific field from a file.

$ awk '{print $2,$5;}' employee.txt

More awk examples: 8 Powerful Awk Built-in Variables – FS, OFS, RS, ORS, NR, NF,
FILENAME, FNR

7. vim command examples


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

More vim examples: How To Record and Play in Vim Editor


8. diff command examples
Ignore white space while comparing.

# diff -w name_list.txt name_list_new.txt

2c2,3

< John Doe --- > John M Doe

> Jason Bourne

More diff examples: Top 4 File Difference Tools on UNIX / Linux – Diff, Colordiff,
Wdiff, Vimdiff

9. sort command examples


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

10. export command examples


To view oracle related environment variables.
$ export | grep ORACLE

declare -x ORACLE_BASE="/u01/app/oracle"

declare -x ORACLE_HOME="/u01/app/oracle/product/10.2.0"

declare -x ORACLE_SID="med"

declare -x ORACLE_TERM="xterm"

To export an environment variable:

$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0

11. xargs command examples


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

12. ls command examples


Display filesize in human readable format (e.g. KB, MB etc.,)

$ 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

Visual Classification of Files With Special Characters Using ls -F

$ ls -F

More ls examples: Unix LS Command: 15 Practical Examples

13. pwd command


pwd is Print working directory. What else can be said about the good old pwd who has
been printing the current directory name for ages.

14. cd command examples


Use “cd -” to toggle between the last two directories

Use “shopt -s cdspell” to automatically correct mistyped directory names on cd

More cd examples: 6 Awesome Linux cd command Hacks

15. gzip command examples


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

compressed uncompressed ratio uncompressed_name

23709 97975 75.8% asp-patch-rpms.txt

16. bzip2 command examples


To create a *.bz2 compressed file:

$ bzip2 test.txt

To uncompress a *.bz2 file:

bzip2 -d test.txt.bz2

More bzip2 examples: BZ is Eazy! bzip2, bzgrep, bzcmp, bzdiff, bzcat, bzless, bzmore
examples

17. unzip command examples


To extract a *.zip compressed file:

$ unzip test.zip

View the contents of *.zip file (Without unzipping it):

$ unzip -l jasper.zip

Archive: jasper.zip

Length Date Time Name


-------- ---- ---- ----

40995 11-30-98 23:50 META-INF/MANIFEST.MF

32169 08-25-98 21:07 classes_

15964 08-25-98 21:07 classes_names

10542 08-25-98 21:07 classes_ncomp

18. shutdown command examples


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

19. ftp command examples


Both ftp and secure ftp (sftp) has similar commands. To connect to a remote server and
download multiple files, do the following.
$ ftp IP/hostname

ftp> mget *.html

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

20. crontab command examples


View crontab entry for a specific user

# crontab -u john -l

Schedule a cron job every 10 minutes.

*/10 * * * * /home/ramesh/check-disk-space

More crontab examples: Linux Crontab: 15 Awesome Cron Job Examples


21. service command examples
Service command is used to run the system V init scripts. i.e Instead of calling the
scripts located in the /etc/init.d/ directory with their full path, you can use the service
command.

Check the status of a service:

# service ssh status

Check the status of all the services.

service --status-all

Restart a service.

# service ssh restart

22. ps command examples


ps command is used to display information about the processes that are running in the
system.

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.

$ ps -ef | more

To view current running processes in a tree structure. H option stands for process
hierarchy.

$ ps -efH | more
23. free command examples
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

total used free shared buffers cached

Mem: 3566408 1580220 1986188 0 203988 902960

-/+ buffers/cache: 473272 3093136

Swap: 4000176 0 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 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

24. top command examples


top command displays the top processes in the system ( by default sorted by cpu usage ).
To sort top output by any column, Press O (upper-case O) , which will display all the
possible columns that you can sort by as shown below.

Current Sort Field: P for window 1:Def

Select sort field via field letter, type any other key to return

a: PID = Process Id v: nDRT = Dirty Pages count

d: UID = User Id y: WCHAN = Sleeping in Function

e: USER = User Name z: Flags = 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

25. df command examples


Displays the file system disk space usage. By default df -k displays output in bytes.
$ df -k

Filesystem 1K-blocks Used Available Use% Mounted on

/dev/sda1 29530400 3233104 24797232 12% /

/dev/sda2 120367992 50171596 64082060 44% /home

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

Use -T option to display what type of file system.

ramesh@ramesh-laptop:~$ df -T

Filesystem Type 1K-blocks Used Available Use% Mounted on

/dev/sda1 ext4 29530400 3233120 24797216 12% /

/dev/sda2 ext4 120367992 50171596 64082060 44% /home

26. kill command examples


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 as shown below. You can also use
killall, pkill, xkill to terminate a unix process.

$ ps -ef | grep vim


ramesh 7243 7222 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

27. rm command examples


Get confirmation before removing the file.

$ 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. This also removes the example directory itself.

$ rm -r example

28. cp command examples


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

29. mv command examples


Rename file1 to file2. if file2 exists prompt for confirmation before overwritting it.

$ 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

30. cat command examples


You can view multiple files at the same time. Following example prints the content of
file1 followed by file2 to stdout.

$ cat 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 {

2 missingok

3 monthly

4 create 0660 root utmp


5 rotate 1

6 }

31. mount command examples


To mount a file system, you should first create a directory and mount it as shown below.

# 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.

/dev/sdb1 /u01 ext2 defaults 0 2

32. chmod command examples


chmod command is used to change the permissions for a file or directory.

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

More chmod examples: 7 Chmod Command Examples for Beginners

33. chown command examples


chown command is used to change the owner and group of a file. \

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

Use -R to change the ownership recursively.

$ chown -R oracle:dba /home/oracle

34. passwd command examples


Change your password from command line using passwd. This will prompt for the old
password followed by the new password.

$ 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
35. mkdir command examples
Following example creates a directory called temp under your home directory.

$ 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 doesn’t exist, it will
create them.

$ mkdir -p dir1/dir2/dir3/dir4/

36. ifconfig command examples


Use ifconfig command to view or configure a network interface on the Linux system.

View all the interfaces along with status.

$ ifconfig -a

Start or stop a specific interface using up and down command as shown below.

$ ifconfig eth0 up

$ ifconfig eth0 down

More ifconfig examples: Ifconfig: 7 Examples To Configure Network Interface

37. uname command examples


Uname command displays important information about the system such as — Kernel
name, Host name, Kernel release number,
Processor type, etc.,
Sample uname output from a Ubuntu laptop is shown below.
$ uname -a

Linux john-laptop 2.6.32-24-generic #41-Ubuntu SMP Thu Aug 19 01:12:52 UTC 2010 i686
GNU/Linux

38. whereis command examples


When you want to find out where a specific Unix command exists (for example, where
does ls command exists?), you can execute the following command.

$ 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.

$ whereis -u -B /tmp -f lsmk

lsmk: /tmp/lsmk

39. whatis command examples


Whatis command displays a single line description about a command.

$ whatis ls

ls (1) - list directory contents

$ whatis ifconfig

ifconfig (8) - configure a network interface


40. locate command examples
Using locate command you can quickly search for the location of a specific file (or group
of files). Locate command uses the database created by updatedb.

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

41. man command examples


Display the man page of a specific command.

$ 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.

$ man SECTION-NUMBER commandname

Following 8 sections are available in the man page.


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

42. tail command examples


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
More tail examples: 3 Methods To View tail -f output of Multiple Log Files in One
Terminal

43. less command examples


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

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

44. su command examples


Switch to a different user account using su command. Super user can switch to any other
user without entering their password.

$ 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 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

45. mysql command examples


mysql is probably the most widely used open source database on Linux. Even if you
don’t run a mysql database on your server, you might end-up using the mysql command
( client ) to connect to a mysql database running on the remote server.

To connect to a remote mysql database. This will prompt for a password.

$ mysql -u root -p -h 192.168.1.2

To connect to a local mysql database.

$ 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).

46. yum command examples


To install apache using yum.

$ yum install httpd

To upgrade apache using yum.

$ yum update httpd

To uninstall/remove apache using yum.


$ yum remove httpd

47. rpm command examples


To install apache using rpm.

# rpm -ivh httpd-2.2.3-22.0.1.el5.i386.rpm

To upgrade apache using rpm.

# rpm -uvh httpd-2.2.3-22.0.1.el5.i386.rpm

To uninstall/remove apache using rpm.

# rpm -ev httpd

More rpm examples: RPM Command: 15 Examples to Install, Uninstall, Upgrade, Query


RPM Packages

48. ping command examples


Ping a remote host by sending only 5 packets.

$ ping -c 5 gmail.com

More ping examples: Ping Tutorial: 15 Effective Ping Command Examples

49. date command examples


Set the system date:

# date -s "01/31/2010 23:59:53"


Once you’ve changed the system date, you should syncronize the hardware clock with
the system date as shown below.

# hwclock –systohc

# hwclock --systohc –utc

50. wget command examples


The quick and effective method to download software, music, video from internet is
using wget command.

$ wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz

Download and store it with a different name.

$ wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=770

1. Command: ls
The command “ls” stands for (List Directory Contents), List the contents of the
folder, be it file or folder, from which it runs.

root@tecmint:~# ls

Android-Games Music

Pictures Public

Desktop Tecmint.com
Documents TecMint-Sync

Downloads Templates

The command “ls -l” list the content of folder, in long listing fashion.

root@tecmint:~# ls -l

total 40588

drwxrwxr-x 2 ravisaive ravisaive 4096 May 8 01:06 Android Games

drwxr-xr-x 2 ravisaive ravisaive 4096 May 15 10:50 Desktop

drwxr-xr-x 2 ravisaive ravisaive 4096 May 16 16:45 Documents

drwxr-xr-x 6 ravisaive ravisaive 4096 May 16 14:34 Downloads

drwxr-xr-x 2 ravisaive ravisaive 4096 Apr 30 20:50 Music

drwxr-xr-x 2 ravisaive ravisaive 4096 May 9 17:54 Pictures

drwxrwxr-x 5 ravisaive ravisaive 4096 May 3 18:44 Tecmint.com

drwxr-xr-x 2 ravisaive ravisaive 4096 Apr 30 20:50 Templates

Command “ls -a“, list the content of folder, including hidden files starting with ‘.’.

root@tecmint:~# ls -a

. .gnupg .dbus .goutputstrea


m-PI5VVW .mission-control

.adobe deja-dup .grsync .mozilla .themes


.gstreamer-0.10 .mtpaint .thumbnails .gtk-bookmarks .thunderbird

.HotShots .mysql_history .htaccess .apport-ignore.xml .ICEauthority

.profile .bash_history .icons .bash_logout .fbmessenger

.jedit .pulse .bashrc .liferea_1.8 .pulse-cookie

.Xauthority .gconf .local .Xauthority.HGHVWW


.cache

.gftp .macromedia .remmina .cinnamon .gimp-2.8

.ssh .xsession-errors .compiz .gnome teamviewer_linux.deb

.xsession-errors.old .config .gnome2 .zoncolor

Note: In Linux file name starting with ‘.‘ is hidden. In Linux every


file/folder/device/command is a file. The output of ls -l is:
▪ d (stands for directory).
▪ rwxr-xr-x is the file permission of the file/folder for owner, group and world.
▪ The 1st ravisaive in the above example means that file is owned by user ravisaive.
▪ The 2nd ravisaive in the above example means file belongs to user group
ravisaive.
▪ 4096 means file size is 4096 Bytes.
▪ May 8 01:06 is the date and time of last modification.
▪ And at the end is the name of the File/Folder.
For more “ls” command examples read 15 ‘ls’ Command Examples in Linux.
2. Command: lsblk
The “lsblk” stands for (List Block Devices), print block devices by their assigned
name (but not RAM) on the standard output in a tree-like fashion.

root@tecmint:~# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT


sda 8:0 0 232.9G 0 disk

├─sda1 8:1 0 46.6G 0 part /

├─sda2 8:2 0 1K 0 part

├─sda5 8:5 0 190M 0 part /boot

├─sda6 8:6 0 3.7G 0 part [SWAP]

├─sda7 8:7 0 93.1G 0 part /data

└─sda8 8:8 0 89.2G 0 part /personal

sr0 11:0 1 1024M 0 rom

The “lsblk -l” command list block devices in ‘list‘ structure (not tree like
fashion).

root@tecmint:~# lsblk -l

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 232.9G 0 disk

sda1 8:1 0 46.6G 0 part /

sda2 8:2 0 1K 0 part

sda5 8:5 0 190M 0 part /boot

sda6 8:6 0 3.7G 0 part [SWAP]

sda7 8:7 0 93.1G 0 part /data

sda8 8:8 0 89.2G 0 part /personal


sr0 11:0 1 1024M 0 rom

Note: lsblk is very useful and easiest way to know the name of New Usb
Device you just plugged in, especially when you have to deal with disk/blocks
in terminal.
3. Command: md5sum
The “md5sum” stands for (Compute and Check MD5 Message Digest), md5
checksum (commonly called hash) is used to match or verify integrity of files
that may have changed as a result of a faulty file transfer, a disk error or non-
malicious interference.

root@tecmint:~# md5sum teamviewer_linux.deb

47790ed345a7b7970fc1f2ac50c97002 teamviewer_linux.deb

Note: The user can match the generated md5sum with the one provided
officially. Md5sum is considered less secure than sha1sum, which we will
discuss later.

4. Command: dd
Command “dd” stands for (Convert and Copy a file), Can be used to convert
and copy a file and most of the times is used to copy a iso file (or any other
file) to a usb device (or any other location), thus can be used to make a
‘Bootlable‘ Usb Stick.

root@tecmint:~# dd if=/home/user/Downloads/debian.iso of=/dev/sdb1 bs=512M; sync

Note: In the above example the usb device is supposed to be sdb1 (You
should Verify it using command lsblk, otherwise you will overwrite your disk
and OS), use name of disk very Cautiously!!!.
dd command takes some time ranging from a few seconds to several minutes
in execution, depending on the size and type of file and read and write speed
of Usb stick.
5. Command: uname
The “uname” command stands for (Unix Name), print detailed information about
the machine name, Operating System and Kernel.

root@tecmint:~# uname -a

Linux tecmint 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:36:13 UTC 2013 i686 i686 i686 GNU/Linux

Note: uname shows type of kernel. uname -a output detailed information.


Elaborating the above output of uname -a.
▪ “Linux“: The machine’s kernel name.
▪ “tecmint“: The machine’s node name.
▪ “3.8.0-19-generic“: The kernel release.
▪ “#30-Ubuntu SMP“: The kernel version.
▪ “i686“: The architecture of the processor.
▪ “GNU/Linux“: The operating system name.

6. Command: history
The “history” command stands for History (Event) Record, it prints the history of
long list of executed commands in terminal.

root@tecmint:~# history

1 sudo add-apt-repository ppa:tualatrix/ppa

2 sudo apt-get update

3 sudo apt-get install ubuntu-tweak

4 sudo add-apt-repository ppa:diesch/testing

5 sudo apt-get update

6 sudo apt-get install indicator-privacy


7 sudo add-apt-repository ppa:atareao/atareao

8 sudo apt-get update

9 sudo apt-get install my-weather-indicator

10 pwd

11 cd && sudo cp -r unity/6 /usr/share/unity/

12 cd /usr/share/unity/icons/

13 cd /usr/share/unity

Note: Pressing “Ctrl + R” and then search for already executed commands
which lets your command to be completed with auto completion feature.

(reverse-i-search)`if': ifconfig

7. Command: sudo
The “sudo” (super user do) command allows a permitted user to execute a
command as the superuser or another user, as specified by the security policy
in the sudoers list.

root@tecmint:~# sudo add-apt-repository ppa:tualatrix/ppa

Note: sudo allows user to borrow superuser privileged, while a similar


command ‘su‘ allows user to actually log in as superuser. Sudo is safer than su.
It is not advised to use sudo or su for day-to-day normal use, as it can result in
serious error if accidentally you did something wrong, that’s why a very
popular saying in Linux community is:
“To err is human, but to really foul up everything, you need root password.”

8. Command: mkdir
The “mkdir” (Make directory) command create a new directory with name path.
However is the directory already exists, it will return an error message “cannot
create folder, folder already exists”.

root@tecmint:~# mkdir tecmint

Note: Directory can only be created inside the folder, in which the user has
write permission. mkdir: cannot create directory `tecmint‘: File exists
(Don’t confuse with file in the above output, you might remember what i said
at the beginning – In Linux every file, folder, drive, command, scripts are
treated as file).
9. Command: touch
The “touch” command stands for (Update the access and modification times of
each FILE to the current time). touch command creates the file, only if it
doesn’t exist. If the file already exists it will update the timestamp and not the
contents of the file.

root@tecmint:~# touch tecmintfile

Note: touch can be used to create file under directory, on which the user has
write permission, only if the file don’t exist there.
10. Command: chmod
The Linux “chmod” command stands for (change file mode bits). chmod changes
the file mode (permission) of each given file, folder, script, etc.. according to
mode asked for.
There exist 3 types of permission on a file (folder or anything but to keep
things simple we will be using file).
Read (r)=4

Write(w)=2

Execute(x)=1

So if you want to give only read permission on a file it will be assigned a value
of ‘4‘, for write permission only, a value of ‘2‘ and for execute permission only,
a value of ‘1‘ is to be given. For read and write permission 4+2 = ‘6‘ is to be
given, ans so on.
Now permission need to be set for 3 kinds of user and usergroup. The first is
owner, then usergroup and finally world.

rwxr-x--x abc.sh

Here the root’s permission is rwx (read, write and execute).


usergroup to which it belongs, is r-x (read and execute only, no write
permission) and
for world is –x (only execute).
To change its permission and provide read, write and execute permission to
owner, group and world.

root@tecmint:~# chmod 777 abc.sh

only read and write permission to all three.

root@tecmint:~# chmod 666 abc.sh

read, write and execute to owner and only execute to group and world.

root@tecmint:~# chmod 711 abc.sh


Note: one of the most important command useful for sysadmin and user both.
On a multi-user environment or on a server, this command comes to rescue,
setting wrong permission will either makes a file inaccessible or provide
unauthorized access to someone.

11. Command: chown


The Linux “chown” command stands for (change file owner and group). Every file
belongs to a group of user and a owner. It is used Do ‘ls -l‘ into your directory
and you will see something like this.

root@tecmint:~# ls -l

drwxr-xr-x 3 server root 4096 May 10 11:14 Binary

drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

Here the directory Binary is owned by user “server” and it belongs to usergroup


“root” where as directory “Desktop” is owned by user “server” and belongs to
user group “server“.
This “chown” command is used to change the file ownership and thus is useful
in managing and providing file to authorised user and usergroup only.

root@tecmint:~# chown server:server Binary

drwxr-xr-x 3 server server 4096 May 10 11:14 Binary

drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

Note: “chown” changes the user and group ownership of each


given FILE to NEW-OWNER or to the user and group of an existing reference
file.
12. Command: apt
The Debian based “apt” command stands for (Advanced Package Tool). Apt is
an advanced package manager for Debian based system (Ubuntu, Kubuntu,
etc.), that automatically and intelligently search, install, update and resolves
dependency of packages on Gnu/Linux system from command line.

root@tecmint:~# apt-get install mplayer

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following package was automatically installed and is no longer required:

java-wrappers

Use 'apt-get autoremove' to remove it.

The following extra packages will be installed:

esound-common libaudiofile1 libesd0 libopenal-data libopenal1 libsvga1 libvdpau1 libxvidcore4

Suggested packages:

pulseaudio-esound-compat libroar-compat2 nvidia-vdpau-driver vdpau-driver mplayer-doc netselect fping

The following NEW packages will be installed:

esound-common libaudiofile1 libesd0 libopenal-data libopenal1 libsvga1 libvdpau1 libxvidcore4 mplayer

0 upgraded, 9 newly installed, 0 to remove and 8 not upgraded.

Need to get 3,567 kB of archives.

After this operation, 7,772 kB of additional disk space will be used.

Do you want to continue [Y/n]? y


root@tecmint:~# apt-get update

Hit http://ppa.launchpad.net raring Release.gpg

Hit http://ppa.launchpad.net raring Release.gpg

Hit http://ppa.launchpad.net raring Release.gpg

Hit http://ppa.launchpad.net raring Release.gpg

Get:1 http://security.ubuntu.com raring-security Release.gpg [933 B]

Hit http://in.archive.ubuntu.com raring Release.gpg

Hit http://ppa.launchpad.net raring Release.gpg

Get:2 http://security.ubuntu.com raring-security Release [40.8 kB]

Ign http://ppa.launchpad.net raring Release.gpg

Get:3 http://in.archive.ubuntu.com raring-updates Release.gpg [933 B]

Hit http://ppa.launchpad.net raring Release.gpg

Hit http://in.archive.ubuntu.com raring-backports Release.gpg

Note: The above commands results into system-wide changes and hence
requires root password (Check ‘#‘ and not ‘$’ as prompt). Apt is considered
more advanced and intelligent as compared to yum command.
As the name suggest, apt-cache search for package containing sub
package mpalyer. apt-get install, update all the packages, that are already
installed, to the newest one.
Read more about apt-get and apt-cache commands at 25 APT-GET and APT-
CACHE Commands
13. Command: tar
The “tar” command is a Tape Archive is useful in creation of archive, in a
number of file format and their extraction.
root@tecmint:~# tar -zxvf abc.tar.gz (Remember 'z' for .tar.gz)
root@tecmint:~# tar -jxvf abc.tar.bz2 (Remember 'j' for .tar.bz2)
root@tecmint:~# tar -cvf archieve.tar.gz(.bz2) /path/to/folder/abc

Note: A ‘tar.gz‘ means gzipped. ‘tar.bz2‘ is compressed with bzip which uses a
better but slower compression method.
Read more about “tar command” examples at 18 Tar Command Examples
14. Command: cal
The “cal” (Calendar), it is used to displays calendar of the present month or any
other month of any year that is advancing or passed.

root@tecmint:~# cal

May 2013

Su Mo Tu We Th Fr Sa

1 2 3 4

5 6 7 8 9 10 11

12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29 30 31

Show calendar of year 1835 for month February, that already has passed.

root@tecmint:~# cal 02 1835


February 1835

Su Mo Tu We Th Fr Sa

1 2 3 4 5 6 7

8 9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

Shows calendar of year 2145 for the month of July, that will advancing

root@tecmint:~# cal 07 2145

July 2145

Su Mo Tu We Th Fr Sa

1 2 3

4 5 6 7 8 9 10

11 12 13 14 15 16 17

18 19 20 21 22 23 24

25 26 27 28 29 30 31

Note: You need not to turn the calendar of 50 years back, neither you need to
make complex mathematical calculation to know what day you were worn or
your coming birthday will fall on which day.
15. Command: date
The “date” (Date) command print the current date and time on the standard
output, and can further be set.

root@tecmint:~# date

Fri May 17 14:13:29 IST 2013

root@tecmint:~# date --set='14 may 2013 13:57'

Mon May 13 13:57:00 IST 2013

Note: This Command will be very use-full in scripting, time and date based
scripting, to be more perfect. Moreover changing date and time using terminal
will make you feel GEEK!!!. (Obviously you need to be root to perform this
operation, as it is a system wide change).
16. Command: cat
The “cat” stands for (Concatenation). Concatenate (join) two or more plain file
and/or print contents of a file on standard output.

root@tecmint:~# cat a.txt b.txt c.txt d.txt >> abcd.txt

root@tecmint:~# cat abcd.txt

....

contents of file abcd

...

Note: “>>” and “>” are called append symbol. They are used to append the
output to a file and not on standard output. “>” symbol will delete a file already
existed and create a new file hence for security reason it is advised to use
“>>” that will write the output without overwriting or deleting the file.
Before Proceeding further, I must let you know about wildcards (you would be
aware of wildcard entry, in most of the Television shows) Wildcards are a shell
feature that makes the command line much more powerful than any GUI file
managers. You see, if you want to select a big group of files in a graphical file
manager, you usually have to select them with your mouse. This may seem
simple, but in some cases it can be very frustrating.
For example, suppose you have a directory with a huge amount of all kinds of
files and subdirectories, and you decide to move all the HTML files, that have
the word “Linux” somewhere in the middle of their names, from that big
directory into another directory. What’s a simple way to do this? If the
directory contains a huge amount of differently named HTML files, your task is
everything but simple!

In the Linux CLI that task is just as simple to perform as moving only one
HTML file, and it’s so easy because of the shell wildcards. These are special
characters that allow you to select file names that match certain patterns of
characters. This helps you to select even a big group of files with typing just a
few characters, and in most cases it’s easier than selecting the files with a
mouse.

Here’s a list of the most commonly used wildcards :

Wildcard Matches
* zero or more characters
? exactly one character
[abcde] exactly one character listed
[a-e] exactly one character in the given range
[!abcde] any character that is not listed
[!a-e] any character that is not in the given range
{debian,linux} exactly one entire word in the options given

! is called not symbol, and the reverse of string attached with ‘!’ is true.
Read more examples of Linux “cat command” at 13 Cat Command Examples in
Linux
17. Command: cp
The “copy” stands for (Copy), it copies a file from one location to another
location.

root@tecmint:~# cp /home/user/Downloads abc.tar.gz /home/user/Desktop (Return 0 when sucess)


Note: cp is one of the most commonly used command in shell scripting and it
can be used with wildcard characters (Describe in the above block), for
customised and desired file copying.
18. Command: mv
The “mv” command moves a file from one location to another location.

root@tecmint:~# mv /home/user/Downloads abc.tar.gz /home/user/Desktop (Return 0 when sucess)

Note: mv command can be used with wildcard characters. mv should be used


with caution, as moving of system/unauthorised file may lead to security as
well as breakdown of system.
19. Command: pwd
The command “pwd” (print working directory), prints the current working
directory with full path name from terminal.

root@tecmint:~# pwd

/home/user/Desktop

Note: This command won’t be much frequently used in scripting but it is an


absolute life saver for newbie who gets lost in terminal in their early
connection with nux. (Linux is most commonly referred as nux or nix).
20. Command: cd
Finally, the frequently used “cd” command stands for (change directory), it
change the working directory to execute, copy, move write, read, etc. from
terminal itself.

root@tecmint:~# cd /home/user/Desktop

server@localhost:~$ pwd

/home/user/Desktop
SERVICES / PROGRAMS  SOC 1,2,3

Amazon API Gateway ✓

Amazon Cloud Directory ✓

Amazon CloudFront ✓

Amazon CloudWatch Logs ✓

Amazon Cognito ✓

Amazon Connect ✓

Amazon DynamoDB ✓

Amazon EC2 Container Registry (ECR) ✓

Amazon EC2 Container Service (ECS) ✓

Amazon ElastiCache ✓

Amazon Elastic Block Store (EBS) ✓

Amazon Elastic Compute Cloud (EC2) ✓

Amazon Elastic File System (EFS) ✓

Amazon Elastic MapReduce ✓

Amazon Glacier ✓

Amazon Inspector ✓

Amazon Kinesis Data Streams ✓

Amazon Redshift ✓

Amazon RDS ✓

Amazon Route 53 ✓

Amazon S3 Transfer Acceleration ✓

Amazon SimpleDB ✓

Amazon Simple Email Service (SES) ✓


Amazon Simple Notification Service (SNS) ✓

Amazon Simple Queue Service (SQS) ✓

Amazon Simple Storage Service (S3) ✓

Amazon Simple Workflow Service (SWF) ✓

Amazon Virtual Private Cloud (VPC) ✓

Amazon WorkMail ✓

Amazon WorkSpaces ✓

Auto Scaling ✓

AWS CloudFormation ✓

AWS CloudHSM ✓

AWS CloudTrail ✓

AWS Database Migration Service ✓

AWS Direct Connect ✓

AWS Directory Service for Microsoft Active Directory ✓

AWS Elastic Beanstalk ✓

AWS Identity & Access Management (IAM) ✓

AWS IoT Platform ✓

AWS Key Management Service ✓

AWS Lambda ✓

AWS Lambda@Edge ✓

AWS Managed Services ✓

AWS Shield ✓

AWS Step Functions ✓

AWS Storage Gateway ✓

AWS Systems Manager ✓


AWS Web Application Firewall (WAF) ✓

Elastic Load Balancing ✓

VM Import/Export ✓

1. Command: ls
The command “ls” stands for (List Directory Contents), List the contents of the
folder, be it file or folder, from which it runs.

root@tecmint:~# ls

Android-Games Music

Pictures Public

Desktop Tecmint.com

Documents TecMint-Sync

Downloads Templates

The command “ls -l” list the content of folder, in long listing fashion.

root@tecmint:~# ls -l

total 40588

drwxrwxr-x 2 ravisaive ravisaive 4096 May 8 01:06 Android Games

drwxr-xr-x 2 ravisaive ravisaive 4096 May 15 10:50 Desktop

drwxr-xr-x 2 ravisaive ravisaive 4096 May 16 16:45 Documents


drwxr-xr-x 6 ravisaive ravisaive 4096 May 16 14:34 Downloads

drwxr-xr-x 2 ravisaive ravisaive 4096 Apr 30 20:50 Music

drwxr-xr-x 2 ravisaive ravisaive 4096 May 9 17:54 Pictures

drwxrwxr-x 5 ravisaive ravisaive 4096 May 3 18:44 Tecmint.com

drwxr-xr-x 2 ravisaive ravisaive 4096 Apr 30 20:50 Templates

Command “ls -a“, list the content of folder, including hidden files starting with ‘.’.

root@tecmint:~# ls -a

. .gnupg .dbus .goutputstrea


m-PI5VVW .mission-control

.adobe deja-dup .grsync .mozilla .themes

.gstreamer-0.10 .mtpaint .thumbnails .gtk-bookmarks .thunderbird

.HotShots .mysql_history .htaccess .apport-ignore.xml .ICEauthority

.profile .bash_history .icons .bash_logout .fbmessenger

.jedit .pulse .bashrc .liferea_1.8 .pulse-cookie

.Xauthority .gconf .local .Xauthority.HGHVWW


.cache

.gftp .macromedia .remmina .cinnamon .gimp-2.8

.ssh .xsession-errors .compiz .gnome teamviewer_linux.deb

.xsession-errors.old .config .gnome2 .zoncolor


Note: In Linux file name starting with ‘.‘ is hidden. In Linux every
file/folder/device/command is a file. The output of ls -l is:
▪ d (stands for directory).
▪ rwxr-xr-x is the file permission of the file/folder for owner, group and world.
▪ The 1st ravisaive in the above example means that file is owned by user ravisaive.
▪ The 2nd ravisaive in the above example means file belongs to user group
ravisaive.
▪ 4096 means file size is 4096 Bytes.
▪ May 8 01:06 is the date and time of last modification.
▪ And at the end is the name of the File/Folder.
For more “ls” command examples read 15 ‘ls’ Command Examples in Linux.
2. Command: lsblk
The “lsblk” stands for (List Block Devices), print block devices by their assigned
name (but not RAM) on the standard output in a tree-like fashion.

root@tecmint:~# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 232.9G 0 disk

├─sda1 8:1 0 46.6G 0 part /

├─sda2 8:2 0 1K 0 part

├─sda5 8:5 0 190M 0 part /boot

├─sda6 8:6 0 3.7G 0 part [SWAP]

├─sda7 8:7 0 93.1G 0 part /data

└─sda8 8:8 0 89.2G 0 part /personal

sr0 11:0 1 1024M 0 rom


The “lsblk -l” command list block devices in ‘list‘ structure (not tree like
fashion).

root@tecmint:~# lsblk -l

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 232.9G 0 disk

sda1 8:1 0 46.6G 0 part /

sda2 8:2 0 1K 0 part

sda5 8:5 0 190M 0 part /boot

sda6 8:6 0 3.7G 0 part [SWAP]

sda7 8:7 0 93.1G 0 part /data

sda8 8:8 0 89.2G 0 part /personal

sr0 11:0 1 1024M 0 rom

Note: lsblk is very useful and easiest way to know the name of New Usb
Device you just plugged in, especially when you have to deal with disk/blocks
in terminal.
3. Command: md5sum
The “md5sum” stands for (Compute and Check MD5 Message Digest), md5
checksum (commonly called hash) is used to match or verify integrity of files
that may have changed as a result of a faulty file transfer, a disk error or non-
malicious interference.

root@tecmint:~# md5sum teamviewer_linux.deb

47790ed345a7b7970fc1f2ac50c97002 teamviewer_linux.deb
Note: The user can match the generated md5sum with the one provided
officially. Md5sum is considered less secure than sha1sum, which we will
discuss later.

4. Command: dd
Command “dd” stands for (Convert and Copy a file), Can be used to convert
and copy a file and most of the times is used to copy a iso file (or any other
file) to a usb device (or any other location), thus can be used to make a
‘Bootlable‘ Usb Stick.

root@tecmint:~# dd if=/home/user/Downloads/debian.iso of=/dev/sdb1 bs=512M; sync

Note: In the above example the usb device is supposed to be sdb1 (You
should Verify it using command lsblk, otherwise you will overwrite your disk
and OS), use name of disk very Cautiously!!!.
dd command takes some time ranging from a few seconds to several minutes
in execution, depending on the size and type of file and read and write speed
of Usb stick.
5. Command: uname
The “uname” command stands for (Unix Name), print detailed information about
the machine name, Operating System and Kernel.

root@tecmint:~# uname -a

Linux tecmint 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:36:13 UTC 2013 i686 i686 i686 GNU/Linux

Note: uname shows type of kernel. uname -a output detailed information.


Elaborating the above output of uname -a.
▪ “Linux“: The machine’s kernel name.
▪ “tecmint“: The machine’s node name.
▪ “3.8.0-19-generic“: The kernel release.
▪ “#30-Ubuntu SMP“: The kernel version.
▪ “i686“: The architecture of the processor.
▪ “GNU/Linux“: The operating system name.
6. Command: history
The “history” command stands for History (Event) Record, it prints the history of
long list of executed commands in terminal.

root@tecmint:~# history

1 sudo add-apt-repository ppa:tualatrix/ppa

2 sudo apt-get update

3 sudo apt-get install ubuntu-tweak

4 sudo add-apt-repository ppa:diesch/testing

5 sudo apt-get update

6 sudo apt-get install indicator-privacy

7 sudo add-apt-repository ppa:atareao/atareao

8 sudo apt-get update

9 sudo apt-get install my-weather-indicator

10 pwd

11 cd && sudo cp -r unity/6 /usr/share/unity/

12 cd /usr/share/unity/icons/

13 cd /usr/share/unity

Note: Pressing “Ctrl + R” and then search for already executed commands
which lets your command to be completed with auto completion feature.
(reverse-i-search)`if': ifconfig

7. Command: sudo
The “sudo” (super user do) command allows a permitted user to execute a
command as the superuser or another user, as specified by the security policy
in the sudoers list.

root@tecmint:~# sudo add-apt-repository ppa:tualatrix/ppa

Note: sudo allows user to borrow superuser privileged, while a similar


command ‘su‘ allows user to actually log in as superuser. Sudo is safer than su.
It is not advised to use sudo or su for day-to-day normal use, as it can result in
serious error if accidentally you did something wrong, that’s why a very
popular saying in Linux community is:

“To err is human, but to really foul up everything, you need root password.”

8. Command: mkdir
The “mkdir” (Make directory) command create a new directory with name path.
However is the directory already exists, it will return an error message “cannot
create folder, folder already exists”.

root@tecmint:~# mkdir tecmint

Note: Directory can only be created inside the folder, in which the user has
write permission. mkdir: cannot create directory `tecmint‘: File exists
(Don’t confuse with file in the above output, you might remember what i said
at the beginning – In Linux every file, folder, drive, command, scripts are
treated as file).
9. Command: touch
The “touch” command stands for (Update the access and modification times of
each FILE to the current time). touch command creates the file, only if it
doesn’t exist. If the file already exists it will update the timestamp and not the
contents of the file.

root@tecmint:~# touch tecmintfile

Note: touch can be used to create file under directory, on which the user has
write permission, only if the file don’t exist there.
10. Command: chmod
The Linux “chmod” command stands for (change file mode bits). chmod changes
the file mode (permission) of each given file, folder, script, etc.. according to
mode asked for.
There exist 3 types of permission on a file (folder or anything but to keep
things simple we will be using file).

Read (r)=4

Write(w)=2

Execute(x)=1

So if you want to give only read permission on a file it will be assigned a value
of ‘4‘, for write permission only, a value of ‘2‘ and for execute permission only,
a value of ‘1‘ is to be given. For read and write permission 4+2 = ‘6‘ is to be
given, ans so on.
Now permission need to be set for 3 kinds of user and usergroup. The first is
owner, then usergroup and finally world.

rwxr-x--x abc.sh
Here the root’s permission is rwx (read, write and execute).
usergroup to which it belongs, is r-x (read and execute only, no write
permission) and
for world is –x (only execute).
To change its permission and provide read, write and execute permission to
owner, group and world.

root@tecmint:~# chmod 777 abc.sh

only read and write permission to all three.

root@tecmint:~# chmod 666 abc.sh

read, write and execute to owner and only execute to group and world.

root@tecmint:~# chmod 711 abc.sh

Note: one of the most important command useful for sysadmin and user both.
On a multi-user environment or on a server, this command comes to rescue,
setting wrong permission will either makes a file inaccessible or provide
unauthorized access to someone.

11. Command: chown


The Linux “chown” command stands for (change file owner and group). Every file
belongs to a group of user and a owner. It is used Do ‘ls -l‘ into your directory
and you will see something like this.

root@tecmint:~# ls -l

drwxr-xr-x 3 server root 4096 May 10 11:14 Binary

drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop


Here the directory Binary is owned by user “server” and it belongs to usergroup
“root” where as directory “Desktop” is owned by user “server” and belongs to
user group “server“.
This “chown” command is used to change the file ownership and thus is useful
in managing and providing file to authorised user and usergroup only.

root@tecmint:~# chown server:server Binary

drwxr-xr-x 3 server server 4096 May 10 11:14 Binary

drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

Note: “chown” changes the user and group ownership of each


given FILE to NEW-OWNER or to the user and group of an existing reference
file.
12. Command: apt
The Debian based “apt” command stands for (Advanced Package Tool). Apt is
an advanced package manager for Debian based system (Ubuntu, Kubuntu,
etc.), that automatically and intelligently search, install, update and resolves
dependency of packages on Gnu/Linux system from command line.

root@tecmint:~# apt-get install mplayer

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following package was automatically installed and is no longer required:

java-wrappers

Use 'apt-get autoremove' to remove it.


The following extra packages will be installed:

esound-common libaudiofile1 libesd0 libopenal-data libopenal1 libsvga1 libvdpau1 libxvidcore4

Suggested packages:

pulseaudio-esound-compat libroar-compat2 nvidia-vdpau-driver vdpau-driver mplayer-doc netselect fping

The following NEW packages will be installed:

esound-common libaudiofile1 libesd0 libopenal-data libopenal1 libsvga1 libvdpau1 libxvidcore4 mplayer

0 upgraded, 9 newly installed, 0 to remove and 8 not upgraded.

Need to get 3,567 kB of archives.

After this operation, 7,772 kB of additional disk space will be used.

Do you want to continue [Y/n]? y

root@tecmint:~# apt-get update

Hit http://ppa.launchpad.net raring Release.gpg

Hit http://ppa.launchpad.net raring Release.gpg

Hit http://ppa.launchpad.net raring Release.gpg

Hit http://ppa.launchpad.net raring Release.gpg

Get:1 http://security.ubuntu.com raring-security Release.gpg [933 B]

Hit http://in.archive.ubuntu.com raring Release.gpg

Hit http://ppa.launchpad.net raring Release.gpg

Get:2 http://security.ubuntu.com raring-security Release [40.8 kB]


Ign http://ppa.launchpad.net raring Release.gpg

Get:3 http://in.archive.ubuntu.com raring-updates Release.gpg [933 B]

Hit http://ppa.launchpad.net raring Release.gpg

Hit http://in.archive.ubuntu.com raring-backports Release.gpg

Note: The above commands results into system-wide changes and hence
requires root password (Check ‘#‘ and not ‘$’ as prompt). Apt is considered
more advanced and intelligent as compared to yum command.
As the name suggest, apt-cache search for package containing sub
package mpalyer. apt-get install, update all the packages, that are already
installed, to the newest one.
Read more about apt-get and apt-cache commands at 25 APT-GET and APT-
CACHE Commands
13. Command: tar
The “tar” command is a Tape Archive is useful in creation of archive, in a
number of file format and their extraction.
root@tecmint:~# tar -zxvf abc.tar.gz (Remember 'z' for .tar.gz)
root@tecmint:~# tar -jxvf abc.tar.bz2 (Remember 'j' for .tar.bz2)
root@tecmint:~# tar -cvf archieve.tar.gz(.bz2) /path/to/folder/abc

Note: A ‘tar.gz‘ means gzipped. ‘tar.bz2‘ is compressed with bzip which uses a
better but slower compression method.
Read more about “tar command” examples at 18 Tar Command Examples
14. Command: cal
The “cal” (Calendar), it is used to displays calendar of the present month or any
other month of any year that is advancing or passed.

root@tecmint:~# cal

May 2013

Su Mo Tu We Th Fr Sa
1 2 3 4

5 6 7 8 9 10 11

12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29 30 31

Show calendar of year 1835 for month February, that already has passed.

root@tecmint:~# cal 02 1835

February 1835

Su Mo Tu We Th Fr Sa

1 2 3 4 5 6 7

8 9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

Shows calendar of year 2145 for the month of July, that will advancing

root@tecmint:~# cal 07 2145

July 2145

Su Mo Tu We Th Fr Sa
1 2 3

4 5 6 7 8 9 10

11 12 13 14 15 16 17

18 19 20 21 22 23 24

25 26 27 28 29 30 31

Note: You need not to turn the calendar of 50 years back, neither you need to
make complex mathematical calculation to know what day you were worn or
your coming birthday will fall on which day.
15. Command: date
The “date” (Date) command print the current date and time on the standard
output, and can further be set.

root@tecmint:~# date

Fri May 17 14:13:29 IST 2013

root@tecmint:~# date --set='14 may 2013 13:57'

Mon May 13 13:57:00 IST 2013

Note: This Command will be very use-full in scripting, time and date based
scripting, to be more perfect. Moreover changing date and time using terminal
will make you feel GEEK!!!. (Obviously you need to be root to perform this
operation, as it is a system wide change).
16. Command: cat
The “cat” stands for (Concatenation). Concatenate (join) two or more plain file
and/or print contents of a file on standard output.
root@tecmint:~# cat a.txt b.txt c.txt d.txt >> abcd.txt

root@tecmint:~# cat abcd.txt

....

contents of file abcd

...

Note: “>>” and “>” are called append symbol. They are used to append the
output to a file and not on standard output. “>” symbol will delete a file already
existed and create a new file hence for security reason it is advised to use
“>>” that will write the output without overwriting or deleting the file.
Before Proceeding further, I must let you know about wildcards (you would be
aware of wildcard entry, in most of the Television shows) Wildcards are a shell
feature that makes the command line much more powerful than any GUI file
managers. You see, if you want to select a big group of files in a graphical file
manager, you usually have to select them with your mouse. This may seem
simple, but in some cases it can be very frustrating.
For example, suppose you have a directory with a huge amount of all kinds of
files and subdirectories, and you decide to move all the HTML files, that have
the word “Linux” somewhere in the middle of their names, from that big
directory into another directory. What’s a simple way to do this? If the
directory contains a huge amount of differently named HTML files, your task is
everything but simple!

In the Linux CLI that task is just as simple to perform as moving only one
HTML file, and it’s so easy because of the shell wildcards. These are special
characters that allow you to select file names that match certain patterns of
characters. This helps you to select even a big group of files with typing just a
few characters, and in most cases it’s easier than selecting the files with a
mouse.

Here’s a list of the most commonly used wildcards :

Wildcard Matches
* zero or more characters
? exactly one character
[abcde] exactly one character listed
[a-e] exactly one character in the given range
[!abcde] any character that is not listed
[!a-e] any character that is not in the given range
{debian,linux} exactly one entire word in the options given

! is called not symbol, and the reverse of string attached with ‘!’ is true.
Read more examples of Linux “cat command” at 13 Cat Command Examples in
Linux
17. Command: cp
The “copy” stands for (Copy), it copies a file from one location to another
location.

root@tecmint:~# cp /home/user/Downloads abc.tar.gz /home/user/Desktop (Return 0 when sucess)

Note: cp is one of the most commonly used command in shell scripting and it
can be used with wildcard characters (Describe in the above block), for
customised and desired file copying.
18. Command: mv
The “mv” command moves a file from one location to another location.

root@tecmint:~# mv /home/user/Downloads abc.tar.gz /home/user/Desktop (Return 0 when sucess)

Note: mv command can be used with wildcard characters. mv should be used


with caution, as moving of system/unauthorised file may lead to security as
well as breakdown of system.
19. Command: pwd
The command “pwd” (print working directory), prints the current working
directory with full path name from terminal.

root@tecmint:~# pwd

/home/user/Desktop
Note: This command won’t be much frequently used in scripting but it is an
absolute life saver for newbie who gets lost in terminal in their early
connection with nux. (Linux is most commonly referred as nux or nix).
20. Command: cd
Finally, the frequently used “cd” command stands for (change directory), it
change the working directory to execute, copy, move write, read, etc. from
terminal itself.

root@tecmint:~# cd /home/user/Desktop

server@localhost:~$ pwd

/home/user/Desktop

Note: cd comes to rescue when switching between directories from terminal.


“Cd ~” will change the working directory to user’s home directory, and is very
useful if a user finds himself lost in terminal. “Cd ..” will change the working
directory to parent directory (of current working directory).
These commands will surely make you comfortable with Linux. But it’s not the
end. Very soon I will be coming with other commands which will be useful for
‘Middle Level User‘ i.e., You! No don’t exclaim, if you get used-to these
commands, You will notice promotion in user-level from newbie to Middle-level-
user. In the next article, I will be coming up with commands like ‘Kill‘, ‘Ps‘,
‘grep‘,….Wait for the article and I don’t want to spoil your interest.

You might also like