linux a z commands

Upload: jatinder-kumar-sachdeva

Post on 05-Apr-2018

238 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 Linux a Z Commands

    1/58

    Explanation

    alias COMMAND: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 isalias [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 theend 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.

    Explanation

    awk COMMAND: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.

  • 7/31/2019 Linux a Z Commands

    2/58

    -F Print help message and exit.

    EXAMPLE:Lets create a file file1.txt and let it have the following data:

    Data in file1.txt14 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.txtThis command will manipulate and print second column of text file (file1.txt). The output will looklike15

    155625

    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 21015 15 2255 56 2805 25 125Explanation

    autoreconf COMMAND:autoreconf - Update generated configuration files

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

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

    SYNTAX:The Syntax is

  • 7/31/2019 Linux a Z Commands

    3/58

    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,--warnings=CATEGORY report the warnings falling in CATEGORY [syntax]

    Warning categories include:

    'cross' cross compilation issues'gnu' GNU coding standards (default in gnu and gnits 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

    Explanation

    a2p COMMAND:a2p - Awk to Perl translator

    A2p takes an awk script specified on the command line (or from standard input) and produces acomparable perl script on the standard output.

    SYNTAX:The Syntax is

    a2p [options] [filename]

    OPTIONS:

    -D sets debugging flags.

    -F tells a2p that this awk script is always invoked with this -F switch.

    -nspecifies the names of the input fields if input does not have to be splitinto an array.

    - causes a2p to assume that input will always have that many fields.

  • 7/31/2019 Linux a Z Commands

    4/58

    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 ofawk. 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.Explanation

    bc COMMAND: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:

    -c Compile only. The output is dc commands that are sent to the standard output.

    -l Define the math functions and initialize scale to 20, instead of the default zero.

    filenameName of the file that contains the basic calculator commands to be calculatedthis is not a necessary command.

    EXAMPLE:

    1. bcOutput:bc 1.06Copyright 1991-1994,1997,1998,2000 Free Software Foundation,Inc.This is free software with ABSOLUTELY NO WARRANTY.

    For details type `warranty'.9*218The above command used is for mathematical calculations.

    2. bc -lOutput:bc 1.06Copyright 1991-1994,1997,1998,2000 Free Software Foundation,Inc.This is free software with ABSOLUTELY NO WARRANTY.For details type `warranty'.1+23The above command displays the sum of '1+2'.

    3. bc calc.txt

    Output:bc 1.06Copyright 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.Explanation

    bg COMMAND:

  • 7/31/2019 Linux a Z Commands

    5/58

    bg command is used to place a job in background. User can run a job in the background byadding 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.

    -xReplace any job_id found in command or arguments with the correspondingprocess 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 background2. 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.jobsThe above command will display the jobs in the shell.[1] Stopped kmail[2]- Stopped xmms[3]+ Stopped sleep 120bg 2The above command will start running the xmms application. In such way you can start runningthe specific background process.jobs[1]- Stopped kmail[2] Running xmms &[3]+ Stopped sleep 120

    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

  • 7/31/2019 Linux a Z Commands

    6/58

    OPTIONS:

    - c Compress or decompress to standard output.

    - d Force decompression.

    - z The complement to -d. Force compression.

    - t Performs the integrity test. It performs a trial decompression test and prints theresult.

    - f Force overwrite of output file.

    - kKeep the original file. dont delete the input file during compression ordecompression.

    - 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.bz2From 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.Explanation

    cal COMMAND:cal command is used to display the calendar.

    SYNTAX:The Syntax is

    cal [options] [month] [year]

  • 7/31/2019 Linux a Z Commands

    7/58

    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. calOutput:September 2008

    Su Mo Tu We Th Fr Sa

    1 2 3 4 5 67 8 9 10 11 12 1314 15 16 17 18 19 2021 22 23 24 25 26 2728 29 30cal command displays the current month calendar.

    2. cal -3 5 2008Output: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 Sa1 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 1413 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 2120 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 30Here the cal command displays the calendar of April, May and June month of year 2008.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.

    -v Non-printing characters (with the exception of tabs, new-lines and form-feeds)

  • 7/31/2019 Linux a Z Commands

    8/58

    are printed visibly.

    EXAMPLE:

    1. To Create a new file:

    cat > file1.txtThis 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.txtTo append data into the same file use append operator >> to write into the file, else the file willbe overwritten (i.e., all of its contents will be erased).

    3. To display a file:

    cat file1.txtThis command displays the data in the file.

    4. To concatenate several files and display:

    cat file1.txt file2.txtThe above cat command will concatenate the two files (file1.txt and file2.txt) and it will displaythe output in the screen. Some times the output may not fit the monitor screen. In such situationyou 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.txtIn the above example the output is redirected to new file file3.txt. The cat command will createnew file file3.txt and store the concatenated output into file3.txt.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:

  • 7/31/2019 Linux a Z Commands

    9/58

    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".chattr COMMAND:

    chattr command is used to change the file attributes. This is an admin command. Root user onlycan 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.

    Explanation

    chgrp COMMAND:

    chgrp command is used to change the group of the file or directory. This is an admincommand. Root user only can change the group of the file or directory.

    SYNTAX:The Syntax is

    chgrp [options] newgroup filename/directoryname

    OPTIONS:

    -R Change the permission on files that are in the subdirectories of the directory that

  • 7/31/2019 Linux a Z Commands

    10/58

    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 changesto newgroup hiox.

    3. chgrp -c hiox calc.txt

    They above command is used to change the group for the specific file('calc.txt') only.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:

    --add serviceCreate a start or kill symbolic link in every runlevel for the specifiedservice according to default behavior specified in the service'sinitialization script.

    --listPrint whether the specified service is on or off in each level. If noservice is specified, print runlevel information for all services managedby chkconfig.

    --level numbersSpecify by number the runlevels to change. Provide numbers as anumeric string: e.g., 016 for levels 0, 1 and 6. Use this to overridespecified defaults.

    --del service Remove entries for specified service from all runlevels.

    EXAMPLE:

    1. chkconfig --listThe above configuration command list the runlevels and the service status(i.e, on or off).

    2. chkconfig tomcat5 offThe above command is used to set the status for tomcat5 service. Now tomcat5 service status isoff.

    3. chkconfig --list tomcat5

  • 7/31/2019 Linux a Z Commands

    11/58

    Output:tomcat5 0:off 1:off 2:off 3:off 4:off 5:off 6:offThe above command displays the status of tomcat5 service(i.e, on or off).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:

  • 7/31/2019 Linux a Z Commands

    12/58

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

    ls -altThis 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

    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:

    -RChange the permission on files that are in the subdirectories of the directorythat you are currently in.

    -c Change the permission for each file.

    -fPrevents chown from displaying error messages when it is unable to changethe 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 subdirectoriesuser also gets changed.

    3. chown -c hiox calc.txt

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

    Explanation

    chpasswd COMMAND:chpasswd command is used to change password for users. This is an admin command,

  • 7/31/2019 Linux a Z Commands

    13/58

    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.

    -f flagsSpecifies the comma separated list of password flags to set. Validflag values are: ADMIN, ADMCHG, and/or NOCHECK. Refer to thepwdadm command documentation for details about these values.

    -R load_moduleSpecifies the loadable I & A module used to change user'spassword.

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

    user1:passwd1

    user2:passwd2

    ....

    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'

  • 7/31/2019 Linux a Z Commands

    14/58

    c is the alias name for clear 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:

    - c Output differing bytes as characters.

    - lPrint the byte number (decimal) and the differing byte values (octal) for eachdifference.

    - 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

    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 intothe directory (the directory is not overwritten).

    SYNTAX:The Syntax is

    cp [OPTIONS]... SOURCE DESTcp [OPTIONS]... SOURCE... DIRECTORYcp [OPTIONS]... --target-directory=DIRECTORY SOURCE...

  • 7/31/2019 Linux a Z Commands

    15/58

    OPTIONS:

    -a same as -dpR.

    --backup[=CONTROL] make a backup of each existing destination file

    -b like --backup but does not accept an argument.

    -f if an existing destination file cannot be opened, remove it and tryagain.

    -p same as --preserve=mode,ownership,timestamps.

    --preserve[=ATTR_LIST]

    preserve the specified attributes (default:mode,ownership,timestamps) and security contexts, if possibleadditional attributes: links, all.

    --no-preserve=ATTR_LIST

    don't preserve the specified attribute.

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

    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:

  • 7/31/2019 Linux a Z Commands

    16/58

    -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.txtOutput:ThiCut the first three letters from the above line.

    2. cut -d, -f1,2 text.txtOutput:This is, an example programThe above command is used to split the fields using delimiter and cut the first two fields.

    Explanation

    date COMMAND:date command prints the date and time.

    SYNTAX:The Syntax is

    date [options] [+format] [date]

    OPTIONS:

    -aSlowly adjust the time by sss.fff seconds (fff represents fractions of a second).This adjustment can be positive or negative.Only system admin/ super user can

    adjust the time.

    -s date-string

    Sets the time and date to the value specfied in the datestring. The datestr maycontain the month names, timezones, 'am', 'pm', etc.

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

  • 7/31/2019 Linux a Z Commands

    17/58

    %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

    dateThe 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 asDate is 07/23/08 Time is 10:52:34

    3. To know the week number of the year,

    date -VThe 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

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

    SYNTAX:

    The Syntax isdd [options]

    OPTIONS:

    -ifSpecifies the input device or partition (or) file from which data is to bedumped

    -ofSpecifies the output device or partition (or) file to which data is to bedumped

  • 7/31/2019 Linux a Z Commands

    18/58

    -ibsSpecifies how many bytes is to be readed from a input file at a time duringthe dumping process

    -obsSpecifies how many bytes is to be written to the output file at a time duringthe dumping process

    -bsSpecifies how many bytes is to be readed and written at a time during thedumping process

    -count=[bytes]

    Specifies how many bytes is to be dumped from 'if' to 'of'

    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 writing2100 bytes at a time.

    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.

  • 7/31/2019 Linux a Z Commands

    19/58

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

  • 7/31/2019 Linux a Z Commands

    20/58

    Output:

    Filesystem Size Used Avail Use% Mounted on

    /dev/mapper/VolGroup00-LogVol00

    154G 15G 132G 11% /

    /dev/sda1 104M 12M 88M 12% /boottmpfs 260M 0 260M 0% /dev/shm

    Print size in human readable format but use powers of 1000 not to 1024.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.

    -HUse heuristics to speed handling of large files that have numerous scatteredsmall changes.

    -i Ignore changes in case; consider upper- and lower-case letters equivalent.

    -nPrints in RCS-format, like -f except that each command specifies the number oflines affected.

    -qOutput RCS-format diffs; like -f except that each command specifies the numberof 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 TESThscripts.comwith friend shiphiox india

    HIOX TESTHSCRIPTS.comwith friend ship

    1. Compare files ignoring white space:

    diff -w file1.txt file2.txt

  • 7/31/2019 Linux a Z Commands

    21/58

    This command will compare the file file1.txt with file2.txt ignoring white/blank space and it willproduce 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.txtThis command will compare the files ignoring white/blank space, It is easier to differentiate thefiles.

    HIOX TEST HIOX TESThscripts.com | HSCRIPTS.comwith friend ship with friend shipHioxindia.com test1.txtPaste the content from 'test.txt' file to 'test1.txt' file.

    2. ls | paste - - - -List all files and directories in four columns for each line.

    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.

    -xScripts too - this causes the program to also return process id's of shells running

    the named scripts.

    -oTells pidof to omit processes with that process id. The special pid %PPID canbe used to name the parent process of the pidof program, in other words thecalling 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.3189Explanation

    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 ControlMessage Protocol (ICMP) echo request packets to a remote IP address and watches for ICMPresponses.

    SYNTAX:The Syntax is

    ping [options] host

    OPTIONS:

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

    -b Ping a broadcast address.

    -c countStop after sending count ECHO_REQUEST packets. With deadline option,ping waits for count ECHO_REPLY packets, until the timeout expires.

    -nShow network addresses as numbers. ping normally displays addresses ashost names.

  • 7/31/2019 Linux a Z Commands

    49/58

    -qQuiet outputnothing is displayed except the summary lines at startup timeand when finished.

    -iSpecify the interval between successive transmissions. The default is onesecond.

    -t Set the IP Time to Live to n seconds.

    -w Exit ping after n seconds.

    EXAMPLE:

    1. ping google.com -c 3Display ECHO_REQUEST 3 times only because we set count for three.

    2. ping -n google.comHere the network addresses displays as numbers,normally it displays as hostnames.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:heloHere '\b' is used for backspace.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:

    -aList information about all processes most frequently requested: all those exceptprocess group leaders and processes not associated with a terminal..

  • 7/31/2019 Linux a Z Commands

    50/58

    -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. psOutput:PID TTY TIME CMD2540 pts/1 00:00:00 bash2621 pts/1 00:00:00 psIn the above example, typing ps alone would list the current running processes.

    2. ps -f

    Output:UID PID PPID C STIME TTY TIME CMDnirmala 2540 2536 0 15:31 pts/1 00:00:00 bashnirmala 2639 2540 0 15:51 pts/1 00:00:00 ps -fDisplays full information about currently running processes.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.

    pwdIf you are working in home directory then, pwd command displays the current working directoryas /home.Explanation

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

    command.

    SYNTAX:

  • 7/31/2019 Linux a Z Commands

    51/58

    The Syntax isrestore [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 databackThis command will compare,

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

    databackup -Is a dump-file [or backup-file]

    /home/user1/data -Is a directory for which a backup is created

    Explanation

  • 7/31/2019 Linux a Z Commands

    52/58

    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.

    -iInteractive. With this option, rm prompts for confirmation before removing anyfiles.

    -r (or) -RRecursively remove directories and subdirectories in the argument list. Thedirectory will be emptied of files and removed. The user is normally promptedfor removal of any write-protected files which the directory contains.

    EXAMPLE:

    1. To Remove / Delete a file:

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

    2. To delete a directory tree:

    rm -ir tmpThis 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.txtrm command removes file1.txt and file2.txt files at the same time.Explanation

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

    SYNTAX:The Syntax is

    rmdir [options..] Directory

    OPTIONS:

    -pAllow users to remove the directory dirname and its parent directories whichbecome empty.

    EXAMPLE:

  • 7/31/2019 Linux a Z Commands

    53/58

    1. To delete/remove a directory

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

    2. To delete a directory tree:

    rm -ir tmpThis 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.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:

    -n dispalys routing table in numerical[IP Address] 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

    netmaskUsed to specifiy the subnet-mask of destinationnetwork/host

    devSpecify the device or interface where the packets will besent

    reject rejects the packets sent to particular route/host

    EXAMPLE:

    1. To dispaly the routing table:

    route -nThe 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

  • 7/31/2019 Linux a Z Commands

    54/58

    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 upo H - Target is a hosto 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 192.168.1.1 -Indicates the gateway of destination network.

    dev eth0 -Indicates that the packets are routed via the interface 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 eth0The above command will delete the route to 192.168.1.0 from the routing table.

    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.txtSorts the 'test.txt'file and prints result in the screen.

    2. sort -r test.txtSorts the 'test.txt' file in reverse order and prints result in the screen.

  • 7/31/2019 Linux a Z Commands

    55/58

    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 outputto 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:

    \NNN the character whose ASCII code is 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 scriptsIt is the parent site of www.forums.hscripts.comhscripts include free tutorials and free gif imagesfree DNS lookup toolPurchase scripts from usA webmaster/web master resource website

    1. sed G file1.txt>file2.txt2. 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 theword 'javascript'.

    5. sed -n '$=' file1.txtThe above command count the number of lines in the file1.txt and output the results.Explanation

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

  • 7/31/2019 Linux a Z Commands

    56/58

    Shutdown / Turn off brings the system down in a secure way. All logged-in users are notified thatthe system is going down, and login(1) is blocked. It is possible to shut the system downimmediately or after a specified delay. All processes are first notified that the system is goingdown 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 toreboot the system, and runlevel 1 is used to put to system into a state where administrativetasks 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 inthe file /etc/inittab.

    SYNTAX:The Syntax is

    /sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message]

    OPTIONS:

    -a Use /etc/shutdown.allow.

    -t secTell init(8) to wait sec seconds between sending processes the warning andthe kill signal, before changing to another runlevel.

    -k Dont really shutdown; only send the warning messages to everybody.

    -r Reboot after shutdown.

    -h Halt or poweroff after shutdown.

    -H Halt action is to halt or drop into boot monitor on systems that 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:00Shutdown the computer at 10-oclock

    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.

  • 7/31/2019 Linux a Z Commands

    57/58

    -b To specify the units of blocks.

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

    -c numberThe number option-argument must be a decimal integer whose sign affects thelocation in the file, measured in bytes.

    -n numberThe number option-argument must be a decimal integer whose sign affects the

    location in the file, measured in lines.

    EXAMPLE:

    1. tail index.phpIt displays the last 10 lines of 'index.php'.

    2. tail -2 index.phpIt displays the last 2 lines of 'index.php'.

    3. tail -n 5 index.phpIt displays the last 5 lines of 'index.php'.

    4. tail -c 5 index.phpIt displays the last 5 characters of 'index.php'.

    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 /etcThis 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

  • 7/31/2019 Linux a Z Commands

    58/58

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

    tar -cvf /dev/fd0 /home/user1/HGBThis 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.tarThis command will extract the backup.tar file

    4. To List The File In An Archive:

    tar -tvf backup.tarThe above command will display the files and directories that archived in backup.tar.

    http://www.hscripts.com/tutorials/linux-commands/tar.html

    http://www.hscripts.com/tutorials/linux-commands/tar.htmlhttp://www.hscripts.com/tutorials/linux-commands/tar.htmlhttp://www.hscripts.com/tutorials/linux-commands/tar.html