0% found this document useful (0 votes)
37 views

Linux Command

Uploaded by

nationalnfsu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Linux Command

Uploaded by

nationalnfsu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

Introduction to Linux Commands.

LINUX:
Linux is a UNIX-like operating system. It is one of the most prominent open source software. This
free online tutorial will help you to learn basics of linux cmd. The following UNIX commands are
some of the commands which we use often. All UNIX commands are case-sensitive.

Let us see the list of linux commands given below.

Linux commands:

1) alias 2) awk 3) auto reconf


4) a2p 5) bc 6) bg
7) bzip2 8) cal 9) cat
10) cd 11) chattr 12) chgrp
13) chkconfig 14) chmod 15) chown
16) chpasswd 17) clear 18) cmp
19) cp 20) cpio 21) cut
22) date 23) dd 24) df
25) diff 26) du 27) dump
28) echo 29) egrep 30) fdisk
31) fg 32) fgrep 33) file
34) find 35) finger 36) free
37) grep 38) groupadd 39) groupdel
40) groupmod 41) groups 42) halt
43) head 44) host 45) hostid
46) hostname 47) id 48) info
49) ifconfig 50) jobs 51) kill
52) last 53) lastlog 54) less
55) link 56) ln 57) ls
58) lsattr 59) mail 60) man
61) mkdir 62) more 63) mv
64) netstat 65) passwd 66) paste
67) pidof 68) ping 69) printf
70) ps 71) pwd 72) restore
73) rm 74) rmdir 75) route
76) sed 77) shut down 78) sort
79) tail 80) tar 81) useradd
82) who 83) whois 84) yes
 What is Linux alias Command?

Explanation
alias command allows you to create a shortcut to a command. As the name indicates, you can
set alias/shortcut name for the commands/paths which is too longer to remember.

SYNTAX:
The Syntax is
alias [options] [ AliasName [ =String ] ]

OPTIONS:

-a Removes all alias definitions from the current shell execution environment.
-p Prints the list of aliases in the form alias name=value on standard output.

EXAMPLE:

1. To create a shortcut temporarily:

alias lhost='cd /var/www/html'

This command will set lhost to cd /var/www/html/.


Now if you type lhost it will take you to the specified folder/directory.

2. To create a shortcut Permanently:


You can put your aliases into the /home/user/.bashrc file. It is good to add them at the
end of the file.

alias home='cd /var/www/html/hscripts/linux-commands'

Now if you type home it will take you to the specified folder/directory.

3. To create a shortcut for a command:

alias c='clear'

This command will set c to clear.


Now if you type c it will clear the screen.

 What is Linux awk Command?

Explanation
awk command is used to manipulate the text.This command checks each line of a file,
looking for patterns that match those given on the command line.

SYNTAX:
The Syntax is
awk '{pattern + action}' {filenames}
OPTIONS:

-W version Display version information and exit.


-F Print help message and exit.
EXAMPLE:
Lets create a file file1.txt and let it have the following data:
Data in file1.txt
14 15 16
15 15 11
5 56 6
5 25 1

1. To print the second column data in file1.txt

awk '{print $2}' file1.txt

This command will manipulate and print second column of text file (file1.txt). The
output will look like

15
15
56
25

2. To multiply the column-1 and column-2 and redirect the output to file2.txt:

awk '{print $1,$2,$1*$2}' file1.txt > file2.txt


Command Explanation:
$1 : Prints 1st column
$2 : Prints 2ndcolumn
$1*$2 : Prints Result of $1 x $2
file1.txt : input file
> : redirection symbol
file2.txt : output file

The above command will redirect the output to file2.txt and it will look like,
14 15 210
15 15 225
5 56 280
5 25 125

15 15 225
5 56 280
5 25 125

 What is Linux autoreconf Command?


Explanation
autoreconf - Update generated configuration files

Run 'autoreconf' repeatedly to remake the GNU Build System files in the DIRECTORIES or
the directory trees driven by CONFIG-URE-AC.

By default, it only remakes those files that are older than their predecessors. If you install
new versions of the GNU Build System, running 'autoreconf' remakes all of the files by
giving it the '--force' option.

SYNTAX:
The Syntax is
autoreconf [OPTION] ... [CONFIGURE-AC or DIRECTORY] ...

OPTIONS:

Operation modes:
-h,--help print this help, then exit.
-V, --version print version number, then exit.
-v,--verbose verbosely report processing.
-d,--debug don't remove temporary files.
-f, --force consider all files obsolete.
-i, --install copy missing auxiliary files.
-s,--symlink with -i, install symbolic links instead of copies
-m, --make when applicable, re-run ./configure && make
-W,--
report the warnings falling in CATEGORY [syntax]
warnings=CATEGORY

Warning categories include:


'cross' cross compilation issues
GNU coding standards (default in gnu and gnits
'gnu'
modes).
'obsolete' obsolete features or constructions
'override' user redefinitions of Automake rules or variables
'portability' portability issues
'syntax' dubious syntactic constructs (default).
EXAMPLE:

autoreconf --force --install -I config -I m4

 What is Linux a2p Command?

Explanation
a2p - Awk to Perl translator
A2p takes an awk script specified on the command line (or from standard input) and produces
a comparable perl script on the standard output.

SYNTAX:
The Syntax is
a2p [options] [filename]

OPTIONS:

-D<number> sets debugging flags.


-F<character> tells a2p that this awk script is always invoked with this -F switch.
specifies the names of the input fields if input does not have to be
-n<fieldlist>
split into an array.
-<number> causes a2p to assume that input will always have that many fields.
EXAMPLE:

a2p myfile - would convert the file


myfile.
Awk to perl translator scripts are often embedded in a shell script that pipes stuff into and out of awk.
Often the shell script wrapper can be incorporated into the perl script, since perl can start up pipes into
and out of itself, and can do other things that awk can't do by itself.

 What is Linux bc Command?

Explanation
bc command is used for command line calculator. It is similar to basic calculator. By using
which we can do basic mathematical calculations.

SYNTAX:
The Syntax is
bc [options]

OPTIONS:

Compile only. The output is dc commands that are sent to the standard
-c
output.
Define the math functions and initialize scale to 20, instead of the default
-l
zero.
Name of the file that contains the basic calculator commands to be
filename
calculated this is not a necessary command.
EXAMPLE:

1. bc

Output:

bc 1.06
Copyright 1991-1994,1997,1998,2000 Free Software Foundation,Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
9*2
18

The above command used is for mathematical calculations.


2. bc -l

Output:

bc 1.06
Copyright 1991-1994,1997,1998,2000 Free Software Foundation,Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
1+2
3

The above command displays the sum of '1+2'.

3. bc calc.txt

Output:

bc 1.06
Copyright 1991-1994,1997,1998,2000 Free Software Foundation,Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
3

'calc.txt' file have the following code:1+2. Get the input from file and displays the
output.

 What is Linux bg Command?

Explanation
bg command is used to place a job in background. User can run a job in the background by
adding a "&" symbol at the end of the command.

SYNTAX:
The Syntax is
bg [options] [job]

OPTIONS:

-l
Report the process group ID and working directory of the jobs.
-p
Report only the process group ID of the jobs.
Replace any job_id found in command or arguments with the
-x corresponding process group ID, then execute command passing it
arguments.
job Specifies the job that want to run in the background.
EXAMPLE:

1. To Run a process in background


2. kmail- start the email client application.
Press ctrl+z to stop the current job.

Now just type bg to move last stopped job to background.

3. To move the specified job to back ground:

Lets start some three jobs and suspend those process in background.

kmail- start the email client application.

Press ctrl+z to stop the current job.

xmms- music player application.

Press ctrl+z to stop the current job.

sleep 120- a dummy job.

Press ctrl+z to stop the current job.

jobs

The above command will display the jobs in the shell.

[1] Stopped kmail


[2]- Stopped xmms
[3]+ Stopped sleep 120
bg 2

The above command will start running the xmms application. In such way you can
start running the specific background process.

jobs
[1]- Stopped kmail
[2] Running xmms &
[3]+ Stopped sleep 120

 What is Linux bzip2 Command?

Explanation
bzip2 COMMAND:
bzip2 linux command is used to compress the file. Each file is replaced by a compressed
version of itself with .bz2 extension.

SYNTAX:
The Syntax is
bzip2 [ options ] filenames

OPTIONS:

-c Compress or decompress to standard output.


-d Force decompression.
-z The complement to -d. Force compression.
Performs the integrity test. It performs a trial decompression test and prints
-t
the result.
- f Force overwrite of output file.
Keep the original file. dont delete the input file during compression or
-k
decompression.
- q Quiet, suppress non-essential warning messages.
- s Reduce memory usage, for compression,decompression and testing.
- v verbose mode shows the compression ratio for each file processed.
- V Displays the version of the software.
- L Displays the license terms and conditions.
- 1 Performs fast compression,creating a relatively large files.
- 9 Get the best possible compression.
EXAMPLE:

1. To Compress a file using bzip2:

Lets have a text file as an example.

$ ls -l
-rw-rw-r-- 1 hiox hiox 9150000 Sep 26 18:37 hiox.txt

$ bzip2 -c -1 hiox.txt > hiox.txt.bz2


$ ls -l
-rw-rw-r-- 1 hiox hiox 9150000 Sep 26 18:37 hiox.txt
-rw-rw-r-- 1 hiox hiox 17706 Sep 27 12:38 hiox.txt.bz2

From the above example it is clear that the filesize is reduced from 9150000 bytes to
17706.

When the File is reduced with option -9 the filesize still gets reduced.

$ bzip2 -c -9 hiox.txt > hscripts.txt.bz2

$ ls -l
-rw-rw-r-- 1 hiox hiox 9150000 Sep 26 18:37 hiox.txt
-rw-rw-r-- 1 hiox hiox 17706 Sep 27 12:38 hiox.txt.bz2
-rw-rw-r-- 1 hiox hiox 2394 Sep 27 13:01 hscripts.txt.bz2

When the file is compressed with -1 the size was 17706 bytes and now the filesize is
2394 bytes. The 9 makes best compression but the default is 6.

 What is Linux cal Command?

Explanation
cal COMMAND:
cal command is used to display the calendar.
SYNTAX:
The Syntax is
cal [options] [month] [year]

OPTIONS:

-1 Displays single month as output.


-3 Displays prev/current/next month output.
-s Displays sunday as the first day of the week.
-m Displays Monday as the first day of the week.
-j Displays Julian dates (days one-based, numbered from January 1).
-y Displays a calendar for the current year.
EXAMPLE:

1. cal

Output:

September 2008
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

cal command displays the current month calendar.

2. cal -3 5 2008

Output:

April 2008 May 2008 June 2008


Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 1 2 3 1 2 3 4 5 6 7
6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14
13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21
20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28
27 28 29 30 25 26 27 28 29 30 31 29 30

Here the cal command displays the calendar of April, May and June month of year
2008.

 What is Linux cat Command?

Explanation
cat COMMAND:
cat linux command concatenates files and print it on the standard output.

SYNTAX:
The Syntax is
cat [OPTIONS] [FILE]...
OPTIONS:

-A Show all.
-b Omits line numbers for blank space in the output.
-e A $ character will be printed at the end of each line prior to a new line.
-E Displays a $ (dollar sign) at the end of each line.
-n Line numbers for all the output lines.
-s If the output has multiple empty lines it replaces it with one empty line.
-T Displays the tab characters in the output.
Non-printing characters (with the exception of tabs, new-lines and form-
-v
feeds) are printed visibly.

EXAMPLE:

1. To Create a new file:

cat > file1.txt

This command creates a new file file1.txt. After typing into the file press control+d
(^d) simultaneously to end the file.

2. To Append data into the file:

cat >> file1.txt

To append data into the same file use append operator >> to write into the file, else
the file will be overwritten (i.e., all of its contents will be erased).

3. To display a file:

cat file1.txt

This command displays the data in the file.

4. To concatenate several files and display:

cat file1.txt file2.txt

The above cat command will concatenate the two files (file1.txt and file2.txt) and it
will display the output in the screen. Some times the output may not fit the monitor
screen. In such situation you can print those files in a new file or display the file using
less command.

cat file1.txt file2.txt | less

5. To concatenate several files and to transfer the output to another file.

cat file1.txt file2.txt > file3.txt


In the above example the output is redirected to new file file3.txt. The cat command
will create new file file3.txt and store the concatenated output into file3.txt.

 What is Linux cd Command?

Explanation
cd COMMAND:
cd command is used to change the directory.

SYNTAX:
The Syntax is
cd [directory | ~ | ./ | ../ | - ]

OPTIONS:

-L Use the physical directory structure.


-P Forces symbolic links.

EXAMPLE:

1. cd linux-command

This command will take you to the sub-directory(linux-command) from its parent
directory.

2. cd ..

This will change to the parent-directory from the current working directory/sub-
directory.

3. cd ~

This command will move to the user's home directory which is "/home/username".

 What is Linux chattr Command?

Explanation
chattr COMMAND:
chattr command is used to change the file attributes. This is an admin command. Root user only
can change the file attributes/Process.

SYNTAX:
The Syntax is
chattr [options] filename

OPTIONS:

+i Make the file as Read-Only.


-i Remove the Read-Only.
+a Can't open file for writing.
-a Open file for writing.
+S The changes in the file are written synchronously on the disk.
EXAMPLE:

1. chattr +i test.txt

Here the 'test.txt' file has the write permission, to make it as Read-Only file use +i
option.

2. chattr -i test.txt

The above command process is used to remove the Read-Only mark.

 What is Linux chgrp Command?

Explanation
chgrp COMMAND:
chgrp command is used to change the group of the file or directory. This is an admin
command. Root user only can change the group of the file or directory.

SYNTAX:
The Syntax is
chgrp [options] newgroup filename/directoryname

OPTIONS:

Change the permission on files that are in the subdirectories of the directory
-R
that you are currently in.
-c Change the permission for each file.
-f Force. Do not report errors.
EXAMPLE:

1. chgrp hiox test.txt

The group of 'test.txt' file is root, Change to newgroup hiox.

2. chgrp -R hiox test

The group of 'test' directory is root. With -R, the files and its subdirectories also
changes to newgroup hiox.

3. chgrp -c hiox calc.txt

They above command is used to change the group for the specific file('calc.txt') only.

 What is Linux chkconfig Command?


Explanation
chkconfig COMMAND:
chkconfig command is used to change, update and query runlevel information for system
services. chkconfig is an admin command.

SYNTAX:
The Syntax is
chkconfig [options]

OPTIONS:

Create a start or kill symbolic link in every runlevel for the


--add service specified service according to default behavior specified in the
service's initialization script.
Print whether the specified service is on or off in each level. If no
--list service is specified, print runlevel information for all services
managed by chkconfig.
Specify by number the runlevels to change. Provide numbers as a
--level numbers numeric string: e.g., 016 for levels 0, 1 and 6. Use this to override
specified defaults.
--del service Remove entries for specified service from all runlevels.
EXAMPLE:

1. chkconfig --list

The above configuration command list the runlevels and the service status(i.e, on or
off).

2. chkconfig tomcat5 off

The above command is used to set the status for tomcat5 service. Now tomcat5
service status is off.

3. chkconfig --list tomcat5

Output:

tomcat5 0:off 1:off 2:off 3:off 4:off 5:off 6:off

The above command displays the status of tomcat5 service(i.e, on or off).

 What is Linux chmod Command?

Explanation
chmod COMMAND:
chmod command allows you to alter / Change access rights to files and directories.

File Permission is given for users,group and others as,


Read Write Execute
User
Group
Others

Permission 000

Symbolic ___ ___ ___


Mode

SYNTAX:
The Syntax is
chmod [options] [MODE] FileName

File Permission

# File Permission
0 none
1 execute only
2 write only
3 write and execute
4 read only
5 read and execute
6 read and write
7 set all permissions

OPTIONS:

-c Displays names of only those files whose permissions are being changed
-f Suppress most error messages
-R Change files and directories recursively
-v Output version information and exit.
EXAMPLE:

1. To view your files with what permission they are:

ls -alt

This command is used to view your files with what permission they are.

2. To make a file readable and writable by the group and others.

chmod 066 file1.txt


3. To allow everyone to read, write, and execute the file

chmod 777 file1.txt

 What is Linux chown Command?

Explanation
chown COMMAND:
chown command is used to change the owner / user of the file or directory. This is an
admin command, root user only can change the owner of a file or directory.

SYNTAX:
The Syntax is
chown [options] newowner filename/directoryname

OPTIONS:

Change the permission on files that are in the subdirectories of the directory
-R
that you are currently in.
-c Change the permission for each file.
Prevents chown from displaying error messages when it is unable to change
-f
the ownership of a file.
EXAMPLE:

1. chown hiox test.txt

The owner of the 'test.txt' file is root, Change to new user hiox.

2. chown -R hiox test

The owner of the 'test' directory is root, With -R option the files and subdirectories
user also gets changed.

3. chown -c hiox calc.txt

Here change the owner for the specific 'calc.txt' file only.

 What is Linux chpasswd Command?

Explanation
chpasswd COMMAND:
chpasswd command is used to change password for users. This is an admin command,
Only root user can change the password for users.

SYNTAX:
The Syntax is
chpasswd [options]
OPTIONS:

-c Clears all password flags.


-e Specifies that the passwords are of encrypted format.
Specifies the comma separated list of password flags to set. Valid
flag values are: ADMIN, ADMCHG, and/or NOCHECK. Refer to
-f flags
the pwdadm command documentation for details about these
values.
Specifies the loadable I & A module used to change user's
-R load_module
password.
EXAMPLE:

1. To reset password for users from command line,type

chpasswd

Followed by entering username:password pairs, one pair per line. Enter ctrl+D when
finished.

user1:passwd1
user2:passwd2
....

 What is Linux clear Command?

Explanation
clear COMMAND:
This command clears the terminal screen.

SYNTAX:
The Syntax is
clear

OPTIONS:
There is no options for clearscreen command.

EXAMPLE:

1. clear

clear command clearscreen like cls command.

2. You can also have alias for this command.

alias c='clear'
c is the alias name for clear command.

 What is Linux cmp Command?


Explanation
cmp COMMAND:
cmp linux command compares two files and tells you which line numbers are different.

SYNTAX:
The Syntax is
cmp [options..] file1 file2

OPTIONS:

-cOutput differing bytes as characters.


Print the byte number (decimal) and the differing byte values (octal) for
-l
each difference.
- s Prints nothing for differing files, return exit status only.
EXAMPLE:

1. Compare two files:

cmp file1 file2

The above cmp command compares file1.php with file2.php and results as follows.

file1.php file2.php differ: byte 35, line 3

2. Compare two files output differing bytes as characters:

cmp -c file1.php file2.php

The above cmp command compares file1.php with file2.php and results as follows.

file1.php file2.php differ: byte 35, line 3 is 151 i 15

 What is Linux cp Command?

Explanation
cp COMMAND:
cp command copy files from one location to another. If the destination is an existing file,
then the file is overwritten; if the destination is an existing directory, the file is copied into the
directory (the directory is not overwritten).

SYNTAX:
The Syntax is
cp [OPTIONS]... SOURCE DEST
cp [OPTIONS]... SOURCE... DIRECTORY
cp [OPTIONS]... --target-directory=DIRECTORY SOURCE...
OPTIONS:

-a same as -dpR.
--backup[=CONTROL] make a backup of each existing destination file
-b like --backup but does not accept an argument.
if an existing destination file cannot be opened, remove it and
-f
try again.
-p same as --preserve=mode,ownership,timestamps.
preserve the specified attributes (default:
--
mode,ownership,timestamps) and security contexts, if possible
preserve[=ATTR_LIST]
additional attributes: links, all.
--no-
don't preserve the specified attribute.
preserve=ATTR_LIST
--parents append source path to DIRECTORY.
EXAMPLE:

1. Copy two files:

cp file1 file2

The above cp command copies the content of file1.php to file2.php.

2. To backup the copied file:

cp -b file1.php file2.php

Backup of file1.php will be created with '~' symbol as file2.php~.

3. Copy folder and subfolders:

cp -R scripts scripts1

The above cp command copy the folder and subfolders from scripts to scripts1.

 What is Linux cpio Command?

Explanation
cpio COMMAND:
cpio command creates and un-creates archived cpio files. It is capable of copying files to
things other than a hard disk. Probably, this command is also used to backup and restore files.

SYNTAX:
The Syntax is
cpio [options]
OPTIONS:

-i
Extracts files from the standard input.
Reads the standard input to obtain a list of path names and copies those
-o
files onto the standard output.
-p Reads the standard input to obtain a list of path names of files.
-c Read or write header information in ASCII character form for portability.
-d Creates directories as needed.
Copy unconditionally (normally, an older file will not replace a newer file
-u
with the same name).
Retain previous file modification time. This option is ineffective on
-m
directories that are being copied.
-v Verbose.Print a list of file names.
EXAMPLE:

1. find . -print | cpio -ocv > /dev/fd0

Find list of files and directories and then copy those to floppy drive.

2. find . -print | cpio -dumpv /home/nirmala

Find list of files and directories and then copy or backup those to user.

3. cpio -icuvd < /dev/fd0

Restore the files back from the floppy.

 What is Linux cut Command?

Explanation
cut COMMAND:
cut command is used to cut out selected fields of each line of a file. The cut command uses
delimiters to determine where to split fields.

SYNTAX:
The Syntax is
cut [options]

OPTIONS:

-c Specifies character positions.


-b Specifies byte positions.
-d flags Specifies the delimiters and fields.
EXAMPLE:
Lets create a file file1.txt and let it have the following data:
Data in file1.txt
This is, an example program,for cut command.
1. cut -c1-3 text.txt
Output:

Thi

Cut the first three letters from the above line.

2. cut -d, -f1,2 text.txt

Output:

This is, an example program

The above command is used to split the fields using delimiter and cut the first two
fields.

 What is Linux date Command?

Explanation
date COMMAND:
date command prints the date and time.

SYNTAX:
The Syntax is
date [options] [+format] [date]

OPTIONS:

Slowly adjust the time by sss.fff seconds (fff represents fractions of a


-a second). This adjustment can be positive or negative.Only system admin/
super user can adjust the time.
-
Sets the time and date to the value specfied in the datestring. The datestr
s date-
may contain the month names, timezones, 'am', 'pm', etc.
string
-u Display (or set) the date in Greenwich Mean Time (GMT-universal time).

Format:

%a Abbreviated weekday(Tue).
%A Full weekday(Tuesday).
%b Abbreviated month name(Jan).
%B Full month name(January).
%c Country-specific date and time format..
%D Date in the format %m/%d/%y.
%j Julian day of year (001-366).
%n Insert a new line.
%p String to indicate a.m. or p.m.
%T Time in the format %H:%M:%S.
%t Tab space.
%V Week number in year (01-52); start week on Monday.
EXAMPLE:

1. date command

date

The above command will print Wed Jul 23 10:52:34 IST 2008

2. To use tab space:

date +"Date is %D %t Time is %T"

The above command will remove space and print as


Date is 07/23/08 Time is 10:52:34

3. To know the week number of the year,

date -V

The above command will print 30

4. To set the date,

date -s "10/08/2008 11:37:23"

The above command will print Wed Oct 08 11:37:23 IST 2008

 What is Linux dd Command?

Explanation
dd COMMAND:
dd command is used to dump the data. The data in a file or device or partition can be
dumped to another file or device or partition. This command is also used for creating
bootable devices.

SYNTAX:
The Syntax is
dd [options]
OPTIONS:

Specifies the input device or partition (or) file from which data is to
-if
be dumped
Specifies the output device or partition (or) file to which data is to be
-of
dumped
Specifies how many bytes is to be readed from a input file at a time
-ibs
during the dumping process
Specifies how many bytes is to be written to the output file at a time
-obs
during the dumping process
Specifies how many bytes is to be readed and written at a time during
-bs
the dumping process
-
Specifies how many bytes is to be dumped from 'if' to 'of'
count=[bytes]

EXAMPLE:

1. To create bootable floppy :

dd if=diskboot.img of=/dev/fd0

This command creates the bootable floppy.

In above command:
diskboot.img -Is the bootable image
/dev/fd0 -Is a floppy disk

2. To import the data from one hard-disk to another hard-disk:

dd if=/dev/sda of=/dev/sdb
In above command:
/dev/sda -Is the hard-disk from which data is dumped
/dev/sdb -Is the hard-disk to which data is dumped

3. To import the data from one partition to another partition:

dd if=/dev/sda1 of=/dev/sda2
/dev/sda1 -Is the partition from which data is dumped
/dev/sda2 -Is the partition to which data in /dev/sda1 is dumped

4. To Specify number of bytes readed and written at a time during dumping:

dd if=/dev/sda1 of=/dev/sda2 bs=2100

The above command will dump data from /dev/sda1 to /dev/sda2 by reading and
writing 2100 bytes at a time.
 What is Linux df Command?

Explanation
df COMMAND:
df command is used to report how much free disk space is available for each mount you
have. The first column show the name of the disk partition as it appears in the /dev directory.
Subsequent columns show total space, blocks allocated and blocks available.

SYNTAX:
The Syntax is
df [options]

OPTIONS:

-a Include dummy file systems.


-h Print sizes in human readable format.(e.g., 1K 234M 2G)
-H Print sizes in human readable format but use powers of 1000 not 1024.
-i List inode information instead of block usage.
-l Limit listing to local file systems.
-P Use the POSIX output format.
-T Print file system type.
EXAMPLE:

1. df

Output:

Filesystem 1K-blocks Used Available Use% Mounted on


/dev/mapper/VolGroup00-LogVol00
150263916 14440324 128067408 11% /
/dev/sda1 101086 10896 84971 12% /boot
tmpfs 253336 0 253336 0% /dev/shm

In the above output:


/dev/mapper/VolGroup00-LogVol00 -> Specifies FileSystem.
/dev/sda1 -> Specifies FileSystem.
tmpfs -> Specifies FileSystem.

Prints default format.

2. df -h

Output:

Filesystem Size Used Avail Use% Mounted on


/dev/mapper/VolGroup00-LogVol00
144G 14G 123G 11% /
/dev/sda1 99M 11M 83M 12% /boot
tmpfs 248M 0 248M 0% /dev/shm

Print size in human readable format.


3. df -H

Output:

Filesystem Size Used Avail Use% Mounted on


/dev/mapper/VolGroup00-LogVol00
154G 15G 132G 11% /
/dev/sda1 104M 12M 88M 12% /boot
tmpfs 260M 0 260M 0% /dev/shm

Print size in human readable format but use powers of 1000 not to 1024.

 What is Linux diff Command?

Explanation
diff COMMAND:
diff command is used to find differences between two files.

SYNTAX:
The Syntax is
diff [options..] from-file to-file

OPTIONS:

-a
Treat all files as text and compare them line-by-line.
-b
Ignore changes in amount of white space.
-c
Use the context output format.
-e
Make output that is a valid ed script.
Use heuristics to speed handling of large files that have numerous scattered
-H
small changes.
-i Ignore changes in case; consider upper- and lower-case letters equivalent.
Prints in RCS-format, like -f except that each command specifies the
-n
number of lines affected.
Output RCS-format diffs; like -f except that each command specifies the
-q
number of lines affected.
-r When comparing directories, recursively compare any subdirectories found.
-s Report when two files are the same.
-w Ignore white space when comparing lines.
-y Use the side by side output format.
EXAMPLE:

Lets create two files file1.txt and file2.txt and let it have the following data.

Data in file1.txt Data in file2.txt


HIOX TEST
HIOX TEST
hscripts.com
HSCRIPTS.com
with friend ship
with friend ship
hiox india
1. Compare files ignoring white space:

diff -w file1.txt file2.txt

This command will compare the file file1.txt with file2.txt ignoring white/blank space
and it will produce the following output.

2c2
< hscripts.com
---
> HSCRIPTS.com
4d3
< Hioxindia.com

2. Compare the files side by side, ignoring white space:

diff -by file1.txt file2.txt

This command will compare the files ignoring white/blank space, It is easier to
differentiate the files.

HIOX TEST HIOX TEST


hscripts.com | HSCRIPTS.com
with friend ship with friend ship
Hioxindia.com <

The third line(with friend ship) in file2.txt has more blank spaces, but still the -b
ignores the blank space and does not show changes in the particular line, -y printout
the result side by side.

3. Compare the files ignoring case.

diff -iy file1.txt file2.txt

This command will compare the files ignoring case(upper-case and lower-case) and
displays the following output.

HIOX TEST HIOX TEST


hscripts.com HSCRIPTS.com
with friend ship | with friend ship
Hioxindia.com <

 What is Linux du Command?


Explanation
du COMMAND:
du command is used to report how much disk space a file or directory occupies.

SYNTAX:
The Syntax is
du [options] directories

OPTIONS:

-a
Displays the usage of space that each file is taking up.
Write the files size in units of 1024 bytes, rather than the default 512-byte
-k
units.
Instead of the default output, report only the total sum for each of the
-s
specified files.
Process symbolic links by using the file or directory which the symbolic
-L
link references, rather than the link itself.
When evaluating file sizes, evaluate only those files that have the same
-x
device as the file specified by the file operand.
EXAMPLE:

1. du -a images

Output:

12 images/daisy.jpg
20 images/flo.gif
76 images/CHILD.gif
12 images/indigo.gif
152 images/flower.gif
12 images/sunflower.jpg
12 images/tulip-flower-clipart5.gif
12 images/flower.jpg
8 images/thumbnail.aspx
8 images/baby.jpg
12 images/woodpecker.gif
168 images/baby.gif
8 images/thumbnail.jpg
1012 images/house.bmp
12 images/peacock.gif
1544 images

Displays the size of each file in the specified directory.

2. du -s images

Output:

1544 images
Displays the total disk space used by the specified directory.

3. du -h

Output:

84K

Displays the current folder capacity.

4. du -h file1.php

Output:

8.0K file1.php

Displays the storage capacity of file1.php.

 What is Linux dump Command?

Explanation
dump COMMAND:
dump command makes backup of filesystem or file and directories.

SYNTAX:
The Syntax is
dump [options] [dump-file] [File-system or file or directories].

OPTIONS:

-[level] The dump level any integer


-f Make the backup in a specified file
-u Updates /etc/dumpdats file for the backup made
-v Displays Verbose Information
-e Exclude inode while making backup
EXAMPLE:

1. To make a backup for a directory or file :

dump -0uf databackup /home/user1/data

This command creates a dump-file called databackup which is the backup of


/home/user1/data directory.

In above command:
-0 -Is the dump-level [0 specifies full-backup]
databackup -Is a dump-file [or backup-file]
/home/user1/data -Is a directory for which a backup is created
2. To make a backup for a directory or file which is already backedup with dump level
0:

dump -1uf databackup /home/user1/data

This command backups all the new files added to /home/user1/data directory after
level-0 dump is made.

-1 -Is the dump-level [1 specifies incremental backup]


databackup -Is a dump-file [or backup-file]
-Is a directory for which a backup is created
/home/user1/data

 What is Linux echo Command?

Explanation
echo COMMAND:
echo command prints the given input string to standard output.

SYNTAX:
The Syntax is
echo [options..] [string]

OPTIONS:

-n do not output the trailing newline


-e enable interpretation of the backslash-escaped characters listed below
-E disable interpretation of those sequences in STRINGs

Without -E, the following sequences are recognized and interpolated:

the character whose ASCII code is NNN


\NNN
(octal)
\a alert (BEL)
\\ backslash
\b backspace
\c suppress trailing newline
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
EXAMPLE:

1. echo command

echo "hscripts Hiox India"

The above command will print as hscripts Hiox India


2. To use backspace:

echo -e "hscripts \bHiox \bIndia"

The above command will remove space and print as hscriptsHioxIndia

3. To use tab space in echo command

echo -e "hscripts\tHiox\tIndia"

The above command will print as hscripts Hiox India

 What is Linux egrep Command?

Explanation
egrep COMMAND:
egrep command is used to search and find one or more files for lines that match the given
string or word.

SYNTAX:
The Syntax is
egrep [options] pattern [file]

OPTIONS:

-b Print the byte offset of input file before each line of output.
-c Print's the count of line matched.
-e pattern
Searches the pattern list.
list
-h Print matched lines but not filenames.
Ignore changes in case; consider upper- and lower-case letters
-i
equivalent.
-n Print line and line number.
-q Prints in quite mode, prints nothing.
-r Recursively read all files in directories and in subdirectories found.
-v Prints all the lines that do not match.
-V Print Version.
-w Match on whole word only.
You can also use Patterns for search operation.
. Matches single character.
* Wild Character.
^ Starting with.
$ Ending with.
EXAMPLE:
Lets assume that we have a file file1.txt and it has the following data.
hscripts has many valuable free scripts
It is the parent site of www.forums.hscripts.com
hscripts include free tutorials and free gif images
free DNS lookup tool
Purchase scripts from us
A webmaster/web master resource website

1. To search more words from a file :

egrep 'hscripts|forums|free' file1.txt

The output will be.


hscripts has many valuable free scripts
It is the parent site of www.forums.hscripts.com
hscripts include free tutorials and free gif images
free DNS lookup tool

2. To print the lines containing "free" followed by images:

egrep 'free.*images' file1.txt

The output will be.


hscripts include free tutorials and free gif images

What is Linux fdisk Command?

Explanation
fdisk COMMAND:
fdisk command is used for partition table manipulator. Hard disks can be divided into one or
more logical disks called partitions.

SYNTAX:
The Syntax is
fdisk [options]

OPTIONS:

-l List the partition tables for the specified devies and then exit.
-u When listing partition tables, give sizes in sectors instead of cylinders.
-s The size of the partition is printed on the standard output.
-b Specify the sector size of the disk.
-C Specify the number of cylinders of the disk.
-H Specify the number of heads of the disk.
-S Specify the number of sectors per track of the disk.
EXAMPLE:

1. fdisk /dev/hdb

It prints the partition table and configuration information.

 What is Linux fg Command?


Explanation
fg COMMAND:
fg command is used to place a job in foreground.

SYNTAX:
The Syntax is
fg [specify job]

OPTIONS:
There is no options for fg command.

EXAMPLE:

1. To move a process in foreground:

Lets start some three jobs and suspend those running process in background.

kmail- start the email client application.

Press ctrl+z to stop the current job.

xmms- music player application.

Press ctrl+z to stop the current job.

sleep 120- a dummy job.

Press ctrl+z to stop the current job.

jobs

The above command will display the jobs in the shell.

[1] Stopped kmail


[2]- Stopped xmms
[3]+ Stopped sleep 120
fg 1

The above command will run the kmail application process in foreground.

 What is Linux fgrep Command?

Explanation
fgrep COMMAND:
fgrep command is used to search one or more files for lines that match the given string or
word. fgrep is faster than grep search, but less flexible: it can only find fixed text, not regular
expressions.

SYNTAX:
The Syntax is
fgrep [options] pattern [file]
OPTIONS:

-a Don't suppress output lines with binary data, treat as text.


-b Print the byte offset of input file before each line of output.
-c Print's the count of line matched.
-h Print matched lines but not filenames.
Ignore changes in case; consider upper- and lower-case letters
-i
equivalent.
-n Print line and line number.
-q Prints in quite mode, prints nothing.
-r Recursively read all files in directories and in subdirectories found.
-v Prints all the lines that do not match.
-V Print Version.
-w Match on whole word only.
EXAMPLE:
Lets assume that we have a file file1.txt and it has the following data.
hscripts is the parent site of www.forums.hscripts.com
ask your technical doubts in our forum
our forums is free

1. To search and print the lines containing forum :

fgrep 'forum' file1.txt

fgrep command prints the output as.


hscripts is the parent site of www.forums.hscripts.com
our forums is free

 What is Linux file Command?

Explanation
file COMMAND:
file command tells you if the object you are looking at is a file or a directory.

SYNTAX:
The Syntax is
file [options] directoryname/filename

OPTIONS:

Check the magic file for format errors. For reasons of efficiency, this
-c
validation is normally not carried out.
-h Do not follow symbolic links.
-m Use mfile as an alternate magic file.
-f ffile contains a list of the files to be examined.
EXAMPLE:
1. file *.txt

Output:

aprlist.txt: ASCII English text


cal.txt: ASCII text
marchlist.txt: ASCII English text
text.txt: ASCII text

Prints the 'txt' files.

2. file nimi

Output:

nimi: directory

Print the given object nimi is an directory or file.

 What is Linux find Command?

Explanation
find COMMAND:
find command finds one or more files assuming that you know their approximate
filenames.

SYNTAX:
The Syntax is
find path [options]

OPTIONS:

It search for the given file, in the current directory or any other
-name
subdirectory.
True if the file was accessed n days ago. The access time of
-atime n
directories in path is changed by find itself.
-ctime n True if the file's status was changed n days ago.
True if the file belongs to the group gname. If gname is numeric and
-group gname
does not appear in the /etc/group file, it is taken as a group ID.
-mtime n True if the file's data was modified n days ago.
True if the file is n blocks long (512 bytes per block). If n is
-size n[c]
followed by a c, the size is in bytes.
EXAMPLE:

1. find -name 'cal.txt'

The system would search for any file named 'cal.txt' in the current directory and any
subdirectory.

2. find / -name 'cal.txt'


The system would search for any file named 'cal.txt' on the root and all subdirectories
from the root.

3. find -name '*' -size +1000k

The system would search for any file in the list that is larger than 1000k.

 What is Linux finger Command?

Explanation
finger COMMAND:
finger command displays the user's login name, real name, terminal name and write status
(as a ''*'' after the terminal name if write permission is denied), idle time, login time, office
location and office phone number..

SYNTAX:
The Syntax is
finger [-lmsp] [user ...] [user@host ...]

OPTIONS:

Prints all the information described by -s option and also the user's home
directory, home phone number, login shell, mail status, and the contents of
-l
the files ".plan",".project",".pgpkey", and ".forward" from the users home
directory.
- m Match arguments only on user name (not first or last name).
Supress the prinitng format of -l, It will not display the contents of
-p
".plan",".project", and ".pgkey" files.
- s Prints the output in short format.
EXAMPLE:

1. To Print the user information in short format:


2. finger -s hiox

3. Login Name Tty Idle LoginTime Office OfficePhone


4. HIOX HIOX INDIA *:0 Sep 14 09:07
5. HIOX HIOX INDIA *pts/0 9 Sep 14 09:08
6. HIOX HIOX INDIA *pts/1 1:29 Sep 14 09:12

finger command prints the user information as user's login name, real name, terminal
name and write status, idle time, login time, office location and office phone number.

 What is Linux free Command?

Explanation
free COMMAND:
free command displays information about free and used memory on the system.

SYNTAX:
The Syntax is
free [options] [-V]

OPTIONS:

- b Prints the memory information in bytes.


- k Prints the memory information in kilo-bytes.
- m Prints the memory information in mega-bytes.
-s
Prints the output continously. Type the delay time to print the output continously.
delay
prints a line containing totals.
EXAMPLE:

1. To Print the memory size information:


2. free

3. total used free shared buffers cached


4. Mem: 223740 219492 4248 0 3756 73212
5. -/+ buffers/cache: 142524 81216
6. Swap: 1052216 66732 985484

The free command displays all the memory information of the system like total
memory used and free memory.

7. To Print memory information from file:


8. cat /proc/meminfo

9. MemTotal: 223740 kB
10. MemFree: 8512 kB
11. Buffers: 4432 kB
12. Cached: 67860 kB
-t 13. SwapCached: 15032 kB
14. Active: 172484 kB
15. Inactive: 20168 kB
16. HighTotal: 0 kB
17. HighFree: 0 kB
18. LowTotal: 223740 kB
19. LowFree: 8512 kB
20. SwapTotal: 1052216 kB
21. SwapFree: 985488 kB
22. Dirty: 52 kB
23. Writeback: 0 kB
24. Mapped: 166064 kB
25. Slab: 14860 kB
26. Committed_AS: 541000 kB
27. PageTables: 3260 kB
28. VmallocTotal: 794616 kB
29. VmallocUsed: 3056 kB
30. VmallocChunk: 791084 kB
31. HugePages_Total: 0
32. HugePages_Free: 0
33. Hugepagesize: 4096 kB

The above command prints the memory information of the system.


 What is Linux grep Command?
Explanation
grep COMMAND:
grep command selects and prints the lines from a file which matches a given string or
pattern.

SYNTAX:
The Syntax is
grep [options] pattern [file]

OPTIONS:

-A Print num lines of text that occur after the matching line.
-a Don't suppress output lines with binary data, treat as text.
-b Print the byte offset of input file before each line of output.
-c Print's the count of line matched.
Define action for accessing the directories
-d read read all files in the directories.
action skip skip directories.
recurse recursively read all files and directories
-e
Search for pattern.
pattern
-h Print matched lines but not filenames.
-i Ignore changes in case; consider upper- and lower-case letters equivalent.
-n Print line and line number.
-q Prints in quite mode, prints nothing.
-r Recursively read all files in directories and in subdirectories found.
-v Prints all the lines that do not match.
-V Print Version.
-w Match on whole word only.
You can also use Patterns for search operation.
. Matches single character.
* Wild Character.
^ Starting with.
$ Ending with.
EXAMPLE:
Lets assume that we have a file file1.txt and it has the following data.
pts has many valuable free scripts
is the parent site of www.forums.hscripts.com
scripts include free tutorials and free gif images
urchase scripts from us
webmaster/web master resource website

1. To print all lines containing hscripts :

grep 'hscripts' file1.txt


The output will be.
hscripts has many valuable free scripts
It is the parent site of www.forums.hscripts.com
hscripts include free tutorials and free gif images

2. To print the count of line that matches hscripts.

grep -c 'hscripts' file1.txt

The output will be.


3

3. To print the lines that starts as hscripts.

grep '^hscripts' file1.txt

The output will be.


hscripts has many valuable free scripts
hscripts include free tutorials and free gif images

4. To Search the files in HEC directory which has the string "include":

grep -c 'include' HEC/*

The above command will print the file name and count of line that matched the
string "include"
Sample output:
HEC/admin.php:3
HEC/auth.php:1
HEC/calendar.php:3
HEC/checklogin.php:0
HEC/colors.php:0

What is Linux groupadd Command?

 What is Linux groupadd Command?

Explanation
groupadd COMMAND:
groupadd command is used to create a new group account.This is an admin command.

SYNTAX:
The Syntax is
groupadd [options] groupname

OPTIONS:

The numerical value of the group's ID. This value must be


-g unique.Values between 0 and 99 are typically reserved for system
accounts.
This flag instructs groupadd to add a system account.This option is
-r
suitable for Redhat linux only.
EXAMPLE:

1. groupadd hioxindia

Create a newgroup named as hioxindia.

What is Linux groupdel Command?

Explanation
groupdel COMMAND:
groupdel command is used to delete(remove) a group. This is an admin command.

SYNTAX:
The Syntax is
groupdel groupname

OPTIONS:
There is no options for groupdel command. Directly give the groupname.

EXAMPLE:

1. groupdel hiox

Delete(Remove) the group hiox.

 What is Linux groupmod Command?

Explanation
groupmod COMMAND:
groupmod command is used to modify group. This is an admin command.

SYNTAX:
The Syntax is
groupmod [options] newname oldname

OPTIONS:

The numerical value of the group's ID. This value must be


-g
unique.Values between 0 and 99 are typically reserved for system
accounts.The value must be non-negative.
-n The name of the group will be changed from group to group.
EXAMPLE:
1. groupmod -n vizhi vizhi1

In the above example the groupmod command would change the group 'vizhi' to
'vizhi1'.

 What is Linux groups Command?

Explanation
groups COMMAND:
groups command is used to print the groups a user is in.

SYNTAX:
The Syntax is
groups

OPTIONS:

--help Print help message and exit


--
Print version and exit
version
EXAMPLE:

1. Prints the groups of user.

$ groups

Output:

hiox apache

2. Prints the groups of super user.

# groups

Output:

root bin daemon sys adm disk wheel.

 What is Linux halt Command?

Explanation
halt COMMAND:
halt command is used to shutdown the computer.

SYNTAX:
The Syntax is
halt [-d | -f | -h | -n | -i | -p | -w]
reboot [-d | -f | -i | -n | -w]
poweroff [-d | -f | -h | -n | -i | -w]

OPTIONS:

-d
Don't write wtmp record(into /var/log/wtmp file). The -n flag implies -d
put all harddrives in the system in standby mode before the system is
-h
halted or turnedoff
- n Don't sync before reboot or halt
- i shutdown all network interface.
While halting the system, also turnoff the system. This is default when
-p
halt is called as poweroff.
Don't actually reboot or halt but only write wtmp record (into
-w
/var/log/wtmp file)
EXAMPLE:

1. To halt the system:

halt

This command is similar to poweroff, which shutdown the system.

2. To Poweroff the system:

poweroff

Poweroff command used for turnoff the system.

3. To reboot the system:

reboot

Reboot command used for reboots/restarts the system.

 What is Linux head Command?

Explanation
head COMMAND:
head command is used to display the first ten lines of a file, and also specifies how
many lines to display.

SYNTAX:
The Syntax is
head [options] filename

OPTIONS:

-n To specify how many lines you want to display.


-n The number option-argument must be a decimal integer whose sign
number affects the location in the file, measured in lines.
The number option-argument must be a decimal integer whose sign
-c number
affects the location in the file, measured in bytes.
EXAMPLE:

1. head index.php

This command prints the first 10 lines of 'index.php'.

2. head -5 index.php

The head command displays the first 5 lines of 'index.php'.

3. head -c 5 index.php

The above command displays the first 5 characters of 'index.php'.

 What is Linux host Command?

Explanation
host COMMAND:
host command is used to find the ip address of the given domain name and also prints
the domain name for the given ip.

SYNTAX:
The Syntax is
host [-aCdlnrTwv] domain-name/ipaddress

OPTIONS:

-aPrints all the DNS records for the given hostname.


-CPrints the SOA records and authorative name servers.
-dIt is equivalent to -v.
-l
Lists all hosts in a domain using AXFR.
used to select the query type.
-t
Query Type: CNAME,NS,SOA,KEY etc,.
-W Specifies how long to wait for a reply.
-v Verbose output is generated by host.
Use TCP instead of UDP to query nameserver. This is
-T implied in queries that require TCP, such as AXFR
requests.
EXAMPLE:

1. To find the ipaddress of a hostname


2. host 123456789.co.in

123456789.co.in has address 69.65.102.222


By typing the hostname along with the host command you can get its ipaddress.
The ip address of 123456789.co.in is 69.65.102.222

3. To Print SOA record information:


4. host -C 123456789.co.in

5. Nameserver ns1.dnshorizon.com:
6. 123456789.co.in SOA ns1.dnshorizon.com. saisan.gmail.com.
7. 2007062001 86400 7200 3600000 86400
8. Nameserver ns2.dnshorizon.com:
9. 123456789.co.in SOA ns1.dnshorizon.com. saisan.gmail.com.
10. 2007062001 86400 7200 3600000 86400

The above cmd prints the host's nameserver and its SOA record.

 What is Linux hostid Command?

Explanation
hostid COMMAND:
hostid command prints the numeric identifier or id of the current host in hexadecimal.

SYNTAX:
The Syntax is
hostid

OPTIONS:

--help Print help message and exit


--
Print version and exit
version
EXAMPLE:

1. To Print host id:


2. hostid

3. a3b50706

This command prints the hostid in hexadecimal.

 What is Linux hostname Command?

Explanation
hostname COMMAND:
hostname specifies the name of the host.

SYNTAX:
The Syntax is
hostname [-a | -d | -f | -h | -i | -s]

OPTIONS:

-a Displays the alias name of the host, if used.


-d Displays DNS domain name
-f Displays fully qualified domain name.
-h Displays help message.
-i Displays IP address of the host.
-s Trim domain name from display.
EXAMPLE:

1. hostname command

hostname

The above command will print as username.com

2. hostname -a

The above command will remove space and print as username

3. To display DNS domain name

hostname -d

The above command will print as .com

 What is Linux id Command?

Explanation
id COMMAND:
id command prints the effective(current) and real userid(UID)s and groupid(GID)s.

SYNTAX:
The Syntax is
id [options]

OPTIONS:

-a Reports user name, use ID and all the groups to which the user belongs.
-G Output all real and effective group IDs,using the format "%u\n".
-g Output only the effective group IDs,using the format "%u\n".
-u Output only the effective user Id,using the format "%u\n".
EXAMPLE:

1. id -a

Output:

uid=501(username) gid=501(username) groups=48(apache),


501(username)

Prints real and current group IDs.

2. id -G

Output:

501 48

Prints in the format of "%u\n"

3. # id

Output:

uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),


4(adm),6(disk),10(wheel) context=user_u:system_r:unconfined_t

The above example display the rootuser uid, gid, groups and context.

 What is Linux info Command?

Explanation
info COMMAND:
info command is used to display the readable online documentation for the specified
command .

SYNTAX:
The Syntax is
info commandname

OPTIONS:

-n Specify nodes in first visited info file.


-f Specify info file to visit.
EXAMPLE:

1. info man

Display the readable online documentation for the man command.

 What is Linux ifconfig Command?


Explanation
ifconfig COMMAND:
ifconfig command displays information about the network interfaces attached to the
system and also used to configure the network interface.

SYNTAX:
The Syntax is
ifconfig [options]

OPTIONS:

dispalys information about both active and inactive


-a
Interface
[interface-name] dispalys information about interface
[interface-name] up Activates the interface
[interface-name] down Inactivates the interface
[interface-name] [IP Address]
Assigns IP address to the interface and activates it
up
EXAMPLE:

1. To get information of active network-interfaces:

ifconfig

The sample output of above command:

eth0
Link encap:Ethernet HWaddr 00:14:85:9C:CC:55
inet addr:192.168.0.12 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::214:85ff:fe9c:cc55/64 Scope:Link
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:7856 errors:0 dropped:0 overruns:0 frame:0
TX packets:7856 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:492016 (480.4 KiB) TX bytes:398 (398.0 b)
Interrupt:201 Memory:e1000000-0
lo
Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0
inet6 addr: ::1/128 Scope:Host
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1455 errors:0 dropped:0 overruns:0 frame:0
TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:1917382 (1.8 MiB) TX bytes:1917382 (1.8 MiB)
In above output:
Link encap:Ethernet -Specifies the type Interface
HWaddr 00:14:85:9C:CC:55 -Specifies the Hardware or MAC address
inet addr:192.168.0.12 -Specifies the IP address assigend to network-interface

2. To Assign IP address to Network Interface[Ethernet Card]:

ifconfig eth0 192.168.0.12 up


The above command will Assign IP address 192.168.0.12 to Ethernet card with
name eth0.

3. To inactivate the Network Interface[Ethernet Card]:

ifconfig eth0 down

The above command inactivates the ethernet card.

 What is Linux jobs Command?

Explanation
jobs COMMAND:
jobs command is used to list the jobs that you are running in the background and in the
foreground. If the prompt is returned with no information no jobs are present.

SYNTAX:
The Syntax is
jobs [options]

OPTIONS:

-l
Report the process group ID and working directory of the jobs.
-n
Display only jobs that have stopped or exited since last notified.
Displays only the process IDs for the process group leaders of the
-p
selected jobs.
EXAMPLE:

1. jobs -l

Lists the jobs that you are running in the foreground (or) background.

2. jobs -p

Display only the process Id for the listed jobs.

 What is Linux kill Command?

Explanation
kill COMMAND:
kill command is used to kill the background process.

SYNTAX:
The Syntax is
kill [-s] [-l] %pid

OPTIONS:

-s Specify the signal to send. The signal may be given as a signal name or
number.
Write all values of signal supported by the implementation, if no
-l
operand is given.
-pid Process id or job id.
-9 Force to kill a process.
EXAMPLE:

Step by Step process:

 Open a process music player.


xmms

press ctrl+z to stop the process.

 To know group id or job id of the background task.


jobs -l
 It will list the background jobs with its job id as,
 xmms 3956
kmail 3467

 To kill a job or process.


kill 3956

kill command kills or terminates the background process xmms.

 What is Linux last Command?

Explanation
last COMMAND:
last command is used to display the last logged in users list. Last logged in users
informations are read from the file /var/log/wtmp.

SYNTAX:
The Syntax is
last [options]

OPTIONS:

-n
Specify how many lines to show.
-R
Suppresses the display of the hostname field.
-x
Display the system shutdown entries and run level changes.
Display the hostname in the last column. Useful in combination with the
-a
next flag.
EXAMPLE:

1. last

Displays the last logged in users list.

2. last -x
Displays the logged in users list with shutdown entries and run level changes.

 What is Linux lastlog Command?

Explanation
lastlog COMMAND:
lastlog command is used to print the last login times for system accounts. Login
information is read from the file /var/log/lastlog.

SYNTAX:
The Syntax is
lastlog [options]

OPTIONS:

-t n Print only logins more recent than 'n' days ago..


-u username Print only login information for username.
EXAMPLE:

1. lastlog -t 5

Displays the login information, 5 days ago.

2. last -u username

Displays the login information for the specified user.

 What is Linux less Command?

Explanation
less COMMAND:
less command is used to display text in the terminal screen. It just prints the text in the
given file, you cannot edit or manipulate the text here. To display the file from the
specified line, enter the line number followed by colon(:). It allows Forward and
backward movement in the file.

SYNTAX:
The Syntax is
less [options] filename

OPTIONS:

-c Clear screen before displaying.


+n Starts up the file from the given number.
:p Examine the pervious file in the command line list.
:d Remove the current file from the list of files.
EXAMPLE:

1. less +3 index.php
Start printing from 3rd line of the file.

 What is Linux link Command?

Explanation
link COMMAND:
link command is used to create a link to a file. It is also called as hard link. Inode will
be same for source and destination.

SYNTAX:
The Syntax is
link existingfilename newfilename (or) link source destination

OPTIONS:

--help Print help message and exit


--
Print version and exit
version
EXAMPLE:

1. link test.php test1.php

Create a link to 'test1.php' file. Here inode for 'test.php' and 'test1.php' will be
same.

 What is Linux ln Command?

Explanation
ln COMMAND:
ln command is used to create link to a file (or) directory. It helps to provide soft link
for desired files. Inode will be different for source and destination.

SYNTAX:
The Syntax is
ln [options] existingfile(or directory)name newfile(or directory)name

OPTIONS:

Link files without questioning the user, even if the mode of target
-f
forbids writing. This is the default if the standard input is not a terminal.
-n Does not overwrite existing files.
-s Used to create soft links.
EXAMPLE:

1. ln -s file1.txt file2.txt

Creates a symbolic link to 'file1.txt' with the name of 'file2.txt'. Here inode for
'file1.txt' and 'file2.txt' will be different.
2. ln -s nimi nimi1

Creates a symbolic link to 'nimi' with the name of 'nimi1'.

 What is Linux ls Command?

Explanation
ls COMMAND:
ls command lists the files and directories under current working directory.

SYNTAX:
The Syntax is
ls [OPTIONS]... [FILE]

OPTIONS:

Lists all the files, directories and their mode, Number of links, owner of
-l
the file, file size, Modified date and time and filename.
-t Lists in order of last modification time.
-a Lists all entries including hidden files.
-d Lists directory files instead of contents.
-p Puts slash at the end of each directories.
-u List in order of last access time.
-i Display inode information.
-ltr List files order by date.
-lSr List files order by file size.
EXAMPLE:

1. Display root directory contents:

ls /

lists the contents of root directory.

2. Display hidden files and directories:

ls -a

lists all entries including hidden files and directories.

3. Display inode information:

ls -i
7373073 book.gif
7373074 clock.gif
7373082 globe.gif
7373078 pencil.gif
7373080 child.gif
7373081 email.gif
7373076 indigo.gif
The above command displays filename with inode value.

 What is Linux lsattr Command?

Explanation
lsattr COMMAND:
lsattr command is used to list the attributes of the specified file or directory.

SYNTAX:
The Syntax is
lsattr [options]

OPTIONS:

-R Recursively list attributes of directories and their contents.


-a List all files in directories, including files that start with `.'.
-d List directories like other files, rather than listing their contents.
EXAMPLE:

1. List attributes:

lsattr

Lists the attributes of the current directory.

2. Set the attribute:

chattr +i test.txt

Set the attribute for 'test.txt' file.

3. lsattr test.txt

Lists the attributes of the 'test.txt' file.

----i-------- ./test.txt

 What is Linux mail Command?

Explanation
mail COMMAND:
mail command is used to send and receive mails locally and globally.

SYNTAX:
The Syntax is
mail

OPTIONS:
-s
Specify subject on command line.
-c
Send carbon copies to list of users.
Send blind carbon copies to list. List should be a comma-separated list
-b
of names.
Read in the contents of your mbox for processing; when you quit, mail
-f
writes undeleted messages back to this file.
Ignore tty interrupt signals. This is particularly useful when using mail
-i
on noisy phone lines.
EXAMPLE:

1. Receive mails

mail
The above command display the messages. Press Enter to view the next message after '&' symbol.

2. Sent mails

mail [email protected] (or) mail [email protected]


Starts a new mail and sent to [email protected].
To terminate the message, type a period(.) and press Enter (or)
press ctrl+d and press Enter.

 What is Linux man Command?

Explanation
man COMMAND:
man command which is short for manual, provides in depth information about the
requested command (or) allows users to search for commands related to a particular
keyword.

SYNTAX:
The Syntax is
man commandname [options]

OPTIONS:

-a Print a one-line help message and exit.


-k Searches for keywords in all of the manuals available..
EXAMPLE:

1. man mkdir

Display the information about mkdir command.

 What is Linux mkdir Command?

Explanation
mkdir COMMAND:
mkdir command is used to create one or more directories.

SYNTAX:
The Syntax is
mkdir [options] directories

OPTIONS:

-m Set the access mode for the new directories.


-p Create intervening parent directories if they don't exist.
-v Print help message for each directory created.
EXAMPLE:

1. Create directory:

mkdir test

The above command is used to create the directory 'test'.

2. Create directory and set permissions:

mkdir -m 666 test

The above command is used to create the directory 'test' and set the read and write
permission.

 What is Linux more Command?

Explanation
more COMMAND:
more command is used to display text in the terminal screen. It allows only backward
movement.

SYNTAX:
The Syntax is
more [options] filename

OPTIONS:

-c
Clear screen before displaying.
Exit immediately after writing the last line of the last file in the
-e
argument list.
-n Specify how many lines are printed in the screen for a given file.
+n Starts up the file from the given number.
EXAMPLE:

1. more -c index.php
Clears the screen before printing the file .

2. more -3 index.php

Prints first three lines of the given file. Press Enter to display the file line by line.

 What is Linux mv Command?

Explanation
mv COMMAND:
mv command which is short for move. It is used to move/rename file from one
directory to another. mv command is different from cp command as it completely
removes the file from the source and moves to the directory specified, where cp command
just copies the content from one file to another.

SYNTAX:
The Syntax is
mv [-f] [-i] oldname newname

OPTIONS:

This will not prompt before overwriting (equivalent to --reply=yes).


-f
mv -f will move the file(s) without prompting even if it is writing over
an existing target.
-i Prompts before overwriting another file.
EXAMPLE:

1. To Rename / Move a file:

mv file1.txt file2.txt

This command renames file1.txt as file2.txt

2. To move a directory

mv hscripts tmp

In the above line mv command moves all the files, directories and sub-directories
from hscripts folder/directory to tmp directory if the tmp directory already exists.
If there is no tmp directory it rename's the hscripts directory as tmp directory.

3. To Move multiple files/More files into another directory

mv file1.txt tmp/file2.txt newdir

This command moves the files file1.txt from the current directory and file2.txt
from the tmp folder/directory to newdir.
 What is Linux netstat Command?

Explanation
netstat COMMAND:
nestat command displays statistics information and current state of network
connections, protocol, ports/ sockets and devices.

SYNTAX:
The Syntax is
netstat [options]

OPTIONS:

-s
dispalys statics information about protocols.
-i
dispalys statistics information about the network interface.
-r
diplays routing table.
-c
displays statistics information and updates every second.
-l
displays information about all sockets that are in listening state.
displays information about all sockets that are in listening and non-
-a
listening state.
-p displays information about sockets with ProcessName and PID.
EXAMPLE:

1. To get statistics of network connections:

netstat

The sample output of above command:

Active Internet connections (w/o


servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 vhost:32803 LocalHost:smtp TIME_WAIT
tcp 0 0 vhost:32803 google.com:http ESTABLISHED

Where,
Proto -Specifies the Protocol used for connection.
Recv-Q -Specifies the Number of Bytes which are not recevied.
Send-Q -Specifies the Number of Bytes not send to destination.
Local Address -Specifies the local or source address and port.
Foreign Address -Specifies the destination address and port.
State -Specifies the current state of conection to the socket.

o ESTABLISHED - Connection is Established.


o TIME_WAIT - Waiting to receive packets.
o LISTEN - Listening to establish connection.

2. To Get Statistics of Protocols:

netstat -s

The Sample output of above command:

IP:
5193 incoming packets delivered
4813 requests sent out
Tcp:
4033 segments received
4813 segments send out
Icmp:
41 ICMP messages received
178 ICMP messages sent

3. To Get statistics of Network Interface:

netstat -i

The sample output of above command:

Kernel Interface table


Iface MTU Met RX-OK RX-ERR TX-OK TX-ERR Flg
eth0 1500 0 1308 0 1345 0 BMRU

This is the statistics information of Ethernet Card[eth0].

 What is Linux passwd Command?

Explanation
passwd COMMAND:
passwd command is used to change your password.

SYNTAX:
The Syntax is
passwd [options]

OPTIONS:

-aShow password attributes for all entries.


-lLocks password entry for name.
Deletes password for name. The login name will not be prompted for
-d
password.
Force the user to change password at the next login by expiring the
-f
password for name.
EXAMPLE:
1. passwd

Entering just passwd would allow you to change the password. After entering
passwd you will receive the following three prompts:

Current Password:
New Password:
Confirm New Password:

Each of these prompts must be entered correctly for the password to be


successfully changed.

 What is Linux paste Command?

Explanation
paste COMMAND:
paste command is used to paste the content from one file to another file. It is also used
to set column format for each line.

SYNTAX:
The Syntax is
paste [options]

OPTIONS:

-s Paste one file at a time instead of in parallel.


-d Reuse characters from LIST instead of TABs .
EXAMPLE:

1. paste test.txt>test1.txt

Paste the content from 'test.txt' file to 'test1.txt' file.

2. ls | paste - - - -

List all files and directories in four columns for each line.

 What is Linux pidof Command?

Explanation
pidof COMMAND:
pidof linux command is used to find the process ID of a running program.

SYNTAX:
The Syntax is
pidof [options..] program

OPTIONS:

-s Single shot - this instructs the program to only return one pid.
Scripts too - this causes the program to also return process id's of shells
-x
running the named scripts.
Tells pidof to omit processes with that process id. The special pid
-o %PPID can be used to name the parent process of the pidof program, in
other words the calling shell or shell script.
EXAMPLE:

1. To find a process id of a particular console:

pidof -s console

This command prints the process id of the console.

3189

 What is Linux ping Command?

Explanation
ping COMMAND:
System administration command. Confirm that a remote host is online and responding.
Ping is used for verifying connectivity between two hosts on a network. It sends Internet
Control Message Protocol (ICMP) echo request packets to a remote IP address and
watches for ICMP responses.

SYNTAX:
The Syntax is
ping [options] host

OPTIONS:

-a Make ping audible. Beep each time response is received.


-b Ping a broadcast address.
Stop after sending count ECHO_REQUEST packets. With deadline
-c count option, ping waits for count ECHO_REPLY packets, until the timeout
expires.
Show network addresses as numbers. ping normally displays addresses
-n
as host names.
Quiet output�nothing is displayed except the summary lines at
-q
startup time and when finished.
Specify the interval between successive transmissions. The default is
-i
one second.
-t Set the IP Time to Live to n seconds.
-w Exit ping after n seconds.

1. ping google.com -c 3

Display ECHO_REQUEST 3 times only because we set count for three.


2. ping -n google.com

Here the network addresses displays as numbers,normally it displays as


hostnames.

 What is Linux printf Command?

Explanation
printf COMMAND:
printf command is used to write formatted output.

SYNTAX:
The Syntax is
printf format [argument]....

OPTIONS:
The format characters and their meanings are:
\b Backspace.
\n Newline.
\t Horizontal tab
\v Vertical tab.
EXAMPLE:

1. printf "hello\n"

Use '\n' returns 'hello' to the new line.

2. printf "hel\blo"

Output:

helo

Here '\b' is used for backspace.

 What is Linux ps Command?

Explanation
ps COMMAND:
ps command is used to report the process status. ps is the short name for Process
Status.

SYNTAX:
The Syntax is
ps [options]

OPTIONS:

List information about all processes most frequently requested: all those
-a
except process group leaders and processes not associated with a
terminal..
-A or e List information for all processes.
-d List information about all processes except session leaders.
-e List information about every process now running.
-f Generates a full listing.
-j Print session ID and process group ID.
-l Generate a long listing.
EXAMPLE:

1. ps

Output:

PID TTY TIME CMD


2540 pts/1 00:00:00 bash
2621 pts/1 00:00:00 ps

In the above example, typing ps alone would list the current running processes.

2. ps -f

Output:

UID PID PPID C STIME TTY TIME CMD


nirmala 2540 2536 0 15:31 pts/1 00:00:00 bash
nirmala 2639 2540 0 15:51 pts/1 00:00:00 ps -f

Displays full information about currently running processes.

 What is Linux pwd Command?

Explanation
pwd COMMAND:
pwd - Print Working Directory. pwd command prints the full filename of the current
working directory.

SYNTAX:
The Syntax is
pwd [options]

OPTIONS:

-P The pathname printed will not contain symbolic links.


-L The pathname printed may contain symbolic links.
EXAMPLE:

1. Displays the current working directory.

pwd
If you are working in home directory then, pwd command displays the current
working directory as /home.

 What is Linux restore Command?

Explanation
restore COMMAND:
restore - command restores the data from the dump-file or backup-file created using
dump command.

SYNTAX:
The Syntax is
restore [options]

OPTIONS:

-f Used to specify the backup or dump file


-C Used to compare dump-file with original file
-i Restore in Interactive mode
-v Displays Verbose Information
-e Exclude inode while making backup

Commands used in interactive mode:


ls List the files and directories in backup file
add Add files in dump-file to current working directory
cd Changes the directory
pwd Displays the current working directory
extract Extract the files from the dump
quit Quit from the interactive mode
EXAMPLE:

1. To restore file and directories from backup-file :

restore -if databack


Where,
i -To make restore with interactive mode
f -To restore from the backup-file specifed
databack -Is a name of backup-file or dump-file

This command gets you to interactive mode as follows:

restore >
Now the following commands are entered to restore:
restore > ls -Lists files and directories in dump file
restore > add -add files to the current directory
restore > ls -Lists the file added from the backup file to current directory
restore > extract -Extracts the file from the backup file to current directory
restore > quit -Quits from the interactive mode

2. To compare and display any dump-file with the original file:

restore -Cf databack

This command will compare,

-1 -Is the dump-level [1 specifies incremental backup]


databackup -Is a dump-file [or backup-file]
-Is a directory for which a backup is created
/home/user1/data

 What is Linux rm Command?

Explanation
rm COMMAND:
rm linux command is used to remove/delete the file from the directory.

SYNTAX:
The Syntax is
rm [options..] [file | directory]

OPTIONS:

-f Remove all files in a directory without prompting the user.


Interactive. With this option, rm prompts for confirmation before
-i
removing any files.
Recursively remove directories and subdirectories in the argument list.
The directory will be emptied of files and removed. The user is
-r (or) -R
normally prompted for removal of any write-protected files which the
directory contains.
EXAMPLE:

1. To Remove / Delete a file:

rm file1.txt

Here rm command will remove/delete the file file1.txt.

2. To delete a directory tree:

rm -ir tmp

This rm command recursively removes the contents of all subdirectories of the


tmp directory, prompting you regarding the removal of each file, and then
removes the tmp directory itself.
3. To remove more files at once

rm file1.txt file2.txt

rm command removes file1.txt and file2.txt files at the same time.

 What is Linux rmdir Command?

Explanation
rmdir COMMAND:
rmdir command is used to delete/remove a directory and its subdirectories.

SYNTAX:
The Syntax is
rmdir [options..] Directory

OPTIONS:

Allow users to remove the directory dirname and its parent directories
-p
which become empty.
EXAMPLE:

1. To delete/remove a directory

rmdir tmp

rmdir command will remove/delete the directory tmp if the directory is empty.

2. To delete a directory tree:

rm -ir tmp

This command recursively removes the contents of all subdirectories of the tmp
directory, prompting you regarding the removal of each file, and then removes the
tmp directory itself.

 What is Linux route Command?

Explanation
route COMMAND:
route command displays routing table resides in kernel and also used to modify the
routing table.The tables which specifies how packets are routed to a host is called routing
table.

SYNTAX:
The Syntax is
route [options]

OPTIONS:
dispalys routing table in numerical[IP Address]
-n
format
-e dispalys routing table in Hostname format
add Adds a new route to the routing table
del Deletes a route from the routing table

Options used with add and del :


-net Indicate the target is network
-host Indicate the target is host
gw Specifies the gateway of target host/network
Used to specifiy the subnet-mask of destination
netmask
network/host
Specify the device or interface where the packets will
dev
be sent
reject rejects the packets sent to particular route/host
EXAMPLE:

1. To dispaly the routing table:

route -n

The above command will print:

Destination Gateway Genmask Flags Metric Ref Use Iface


192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0

In above table:
Destination -Indicates the IP address of desination host/network
Gateway -Indicates gateway from which desination host/network could be reached
Genmask -Indicates the subnetmask destination
Flags -Indicates the current status of route

o U - Route is up
o H - Target is a host
o G - Use gateway

Iface -Indicates the interface

2. To add static route to a network in the routing table:

route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0


In above command:
add -Indicates that the route is added to routing table.
-net -Indicates that desination is a network.
192.168.0.1 -Indicates IP address of destination network.
netmask -Indicates the subnetmask of destination network.
gw
-Indicates the gateway of destination network.
192.168.1.1
-Indicates that the packets are routed via the interface
dev eth0
eth0.

3. To delete a route from the routing table:

route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0

The above command will delete the route to 192.168.1.0 from the routing table.

 What is Linux sort Command?

Explanation
sort COMMAND:
sort command is used to sort the lines in a text file.

SYNTAX:
The Syntax is
sort [options] filename

OPTIONS:

-r Sorts in reverse order.


-u If line is duplicated display only once.
-o filename Sends sorted output to a file.
EXAMPLE:

1. sort test.txt

Sorts the 'test.txt'file and prints result in the screen.

2. sort -r test.txt

Sorts the 'test.txt' file in reverse order and prints result in the screen.

 What is Linux sed Command?

Explanation
sed COMMAND:
sed is a stream editor. sed command helps to edit or delete all occurrences of one
string to another within a file. It takes a file as input and prints the result on screen or
redirects the output to a specified file.

SYNTAX:
The Syntax is
sed [options] '{command}' [filename]

OPTIONS:
Command and its function
-n do not output the trailing newline
-e enable interpretation of the backslash-escaped characters listed below
-E disable interpretation of those sequences in STRINGs

Without -E, the following sequences are recognized and interpolated:


the character whose ASCII code is NNN
\NNN
(octal)
\a alert (BEL)
\b Backspace
\c suppress trailing newline
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
EXAMPLE:
Lets assume that we have a file file1.txt and it has the following data.
hscripts has many valuable free scripts
It is the parent site of www.forums.hscripts.com
hscripts include free tutorials and free gif images
free DNS lookup tool
Purchase scripts from us
A webmaster/web master resource website
1. sed G file1.txt>file2.txt
2. In the above example, using the sed command with G would double space the file
file1.txt and output the results to the file2.txt.
3. sed = file1.txt | sed 'N;s/\n/\. /'

In the above example, sed command is used to output each of the lines in file1.txt
with the line number followed by a period and a space before each line.

4. sed 's/scripts/javascript/g' file1.txt

Opens the file file1.txt and searches for the word 'scripts' and replaces every
occurrence with the word 'javascript'.

5. sed -n '$=' file1.txt

The above command count the number of lines in the file1.txt and output the
results.

 What is Linux Shutdown Command?

Explanation
Shutdown COMMAND:
Shutdown - Turn off the computer immediately or at a specified time.

Shutdown / Turn off brings the system down in a secure way. All logged-in users are
notified that the system is going down, and login(1) is blocked. It is possible to shut the
system down immediately or after a specified delay. All processes are first notified that
the system is going down by the signal SIGTERM.

This gives programs like vi(1) the time to save the file being edited, mail and news
processing programs a chance to exit cleanly, etc. Shutdown does its job by signalling the
init process, asking it to change the runlevel. Runlevel 0 is used to halt the system,
runlevel 6 is used to reboot the system, and runlevel 1 is used to put to system into a state
where administrative tasks can be performed; this is the default if neither the -h or -r flag
is given to shutdown.

To see which actions are taken on halt or reboot see the appropriate entries for these
runlevels in the file /etc/inittab.

SYNTAX:
The Syntax is
/sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message]

OPTIONS:

-a Use /etc/shutdown.allow.
Tell init(8) to wait sec seconds between sending processes the
-t sec
warning and the kill signal, before changing to another runlevel.
Don’t really shutdown; only send the warning messages to
-k
everybody.
-r Reboot after shutdown.
-h Halt or poweroff after shutdown.
Halt action is to halt or drop into boot monitor on systems that
-H
support it.
-P Halt action is to turn off the power.
-f Skip fsck on reboot.
-F Force fsck on reboot.
-c Cancel an already running shutdown.
EXAMPLE:

shutdown 10:00
Shutdown the computer at 10-oclock

 What is Linux tail Command?

Explanation
tail COMMAND:
tail command is used to display the last or bottom part of the file. By default it
displays last 10 lines of a file.
SYNTAX:
The Syntax is
tail [options] filename

OPTIONS:

-l To specify the units of lines.


-b To specify the units of blocks.
-n To specify how many lines you want to display.
The number option-argument must be a decimal integer whose sign
-c number
affects the location in the file, measured in bytes.
The number option-argument must be a decimal integer whose sign
-n number
affects the location in the file, measured in lines.
EXAMPLE:

1. tail index.php

It displays the last 10 lines of 'index.php'.

2. tail -2 index.php

It displays the last 2 lines of 'index.php'.

3. tail -n 5 index.php

It displays the last 5 lines of 'index.php'.

4. tail -c 5 index.php

It displays the last 5 characters of 'index.php'.

 What is Linux tar Command?

Explanation
tar COMMAND:
tar command is used to create archive and extract the archive files.

SYNTAX:
The Syntax is
tar [options] [archive-file] [File or directory to be archived]

OPTIONS:

-c Creates Archive
-x Extract the archive
-f creates archive with give filename
-t displays or lists files in archived file
-u archives and adds to an existing archive file
-v Displays Verbose Information
-A Concatenates the archive files
EXAMPLE:

1. To archive a directory or file :

tar -cvf backup.tar /etc

This command creates a tarfile called backup.tar which is the archive of /etc
directory.

Where,
backup.tar - Is a tar file created
/etc - Is a directory archived

2. To archive a directory or file and store it in a storage device:

tar -cvf /dev/fd0 /home/user1/HGB

This command will archive /etc directory and store it in floppy-disk.

Where,
/dev/fd0 - Is a floppy-disk name where the archive is stored
/home/user1/HGB - Is a directory archived

3. To Extract the archive:

tar -xvf backup.tar

This command will extract the backup.tar file

4. To List The File In An Archive:

tar -tvf backup.tar

The above command will display the files and directories that archived in
backup.tar.

 What is Linux useradd Command?

Explanation
useradd COMMAND:
useradd - Adds new user to the linux system, with specified user-name. When a new
user is added then a corresponding entry is made in files /etc/passwd, /etc/group and
/etc/shadow

SYNTAX:
The Syntax is
useradd [options] [username]
OPTIONS:

-d Specifies the users home directory


-s Specifies the users shell
-g Specifies the users primary group
-G Specifies the users secondary groups
-M Specifies not to create home directory for the user
-e Specifies the expire date of the user
-uid Specifies the user-id of the user
EXAMPLE:

1. To add new user:

useradd hiox

This command will add a new user with name hiox.

2. To add user but not allow to login in the system:

useradd -s /bin/nologin hiox

This command will add user hiox but not allow to login.

In above command:
hiox -Is the user-name
/bin/nologin -Is Shell assigned to the user

3. To set expire date of the user:

useradd -e 2008-06-30 hiox

This command will add user hiox and set the expire date to 2008-06-30.

In above command:
hiox -Is the user-name
2008-06-30 -Is date on which the user-account will be expired

4. To create user without creating home directory:

useradd -M hiox

The above command will create user hiox but home directory will not be created.

 What is Linux who Command?

Explanation
who COMMAND:
who command can list the names of users currently logged in, their terminal, the time
they have been logged in, and the name of the host from which they have logged in.

SYNTAX:
The Syntax is
who [options] [file]

OPTIONS:

Print the username of the invoking user, The 'am' and 'i' must be space
am i
separated.
-b Prints time of last system boot.
-d print dead processes.
-H Print column headings above the output.
Include idle time as HOURS:MINUTES. An idle time of . indicates
-i
activity within the last minute.
-m Same as who am i.
-q Prints only the usernames and the user count/total no of users logged in.
-T,-w Include user's message status in the output.
EXAMPLE:

1. who -uH

Output:

NAME LINE TIME IDLE PID COMMENT


hiox ttyp3 Jul 10 11:08 . 4578

This sample output was produced at 11 a.m. The "." indiacates activity within the
last minute.

2. who am i

who am i command prints the user name.

 What is Linux whois Command?

Explanation
whois COMMAND:
whois command lists the information about the domain owner of the given domain.

SYNTAX:
The Syntax is
whois [option] query

OPTIONS:

-h Host which holds the identification information in its database.


-p connect to the specified port.
EXAMPLE:
1. whois hscripts.com

Output:
The above command will produce the following output.

[Querying whois.internic.net]
[Redirected to whois.PublicDomainRegistry.com]
[Querying whois.PublicDomainRegistry.com]
[whois.PublicDomainRegistry.com]
Registration Service Provided By: HIOX INDIA
Contact: +91.4226547769

Domain Name: HSCRIPTS.COM

Registrant:
HIOX INDIA
Rajesh Kumar ([email protected])
32, North Street, Krishnapuram, Singanallur
Coimbatore
tamil nadu,641005
IN
Tel. +91.04225547769

Creation Date: 06-Oct-2004


Expiration Date: 06-Oct-2008

Domain servers in listed order:


ns1.hscripts.com
ns2.hscripts.com

Administrative Contact:
HIOX INDIA
Rajesh Kumar ([email protected])
32, North Street, Krishnapuram, Singanallur
Coimbatore
tamil nadu,641005
IN
Tel. +91.04225547769

Technical Contact:
HIOX INDIA
Rajesh Kumar ([email protected])
32, North Street, Krishnapuram, Singanallur
Coimbatore
tamil nadu,641005
IN
Tel. +91.04225547769

Billing Contact:
HIOX INDIA
Rajesh Kumar ([email protected])
32, North Street, Krishnapuram, Singanallur
Coimbatore
tamil nadu,641005
IN
Tel. +91.04225547769
Status:ACTIVE

The data in this whois database is provided to


you for information purposes only, that is,
to assist you in obtaining information about or
related to a domain name registration record.
We make this information available "as is",
and do not guarantee its accuracy. By submitting a
whois query, you agree that you will use this data
only for lawful purposes and that, under no
circumstances will you use this data to:
(1) enable high volume, automated, electronic
processes that stress or load this whois database
system providing you this information; or
(2) allow, enable, or otherwise support the
transmission of mass unsolicited, commercial
advertising or solicitations via fascimile,
electronic mail, or by telephone. The compilation,
repackaging, dissemination or other use of this data
is expressly prohibited without prior written consent
from us. The registrar of record is PublicDomainRegistry.
We reserve the right to modify these terms at any time.
By submitting this query, you agree to abide
by these terms.

 What is Linux yes Command?

Explanation
yes COMMAND:
yes command repeatedly prints the given string separated by a space and followed by a
newline until it is killed. If no string is given, it just prints 'y' repeatedly until it is killed. It
is normally used in scripts, its output is piped to a command or program that prompts you
to do this or that (do you want to delete this file press 'y' or 'n')

SYNTAX:
The Syntax is
yes [string..]
yes [options..]

OPTIONS:

--help Print help message and exit


--
Print version and exit
version
EXAMPLE:

1. Print the given string repeatedly:

yes "hscripts"

The above command will print hscripts repeatedly until it is killed(CTRL+C).

2. To delete a file without pressing any key when it prompts:


yes | rm -i *.txt

In the above example, the yes command is piped with rm command. Normally rm
-i will prompt you to remove the file, to remove the file you have to type either
y(yes) or n(no). When it is piped with yes by default, the yes will print y and all
the txt files will be removed automatically, so that you dont need to type y for
every txt files.

yes n | rm -i *.txt

The above example says not to remove a file when rm -i prompts to remove the
file.

You might also like