linux command1

Upload: mkumbhcar

Post on 04-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 Linux Command1

    1/72

    STTy command:

    NAME

    stty - change and print terminal line settings

    SYNOPSIS

    stty [-F DEVICE] [--file=DEVICE] [SETTING]...stty [-F DEVICE] [--file=DEVICE] [-a|--all]stty [-F DEVICE] [--file=DEVICE] [-g|--save]

    DESCRIPTION

    Print or change terminal characteristics.

    -a, --all

    print all current settings in human-readable form

    -g, --save

    print all current settings in a stty-readable form

    -F, --file=DEVICE

    open and use the specified DEVICE instead of stdin

    --help

    display this help and exit

    --version

    output version information and exit

    Optional - before SETTING indicates negation. An * marks non-POSIX settings. The underlying system

    defines which settings are available.

    LS command:

    NAME

    ls - list directory contents

  • 7/31/2019 Linux Command1

    2/72

    SYNOPSIS

    ls [OPTION]... [FILE]...

    DESCRIPTION

    List information about the FILEs (the current directory by default). Sort entries alphabetically if none

    of-cftuSUX nor --sort.

    Mandatory arguments to long options are mandatory for short options too.

    $ lsdir1 dir3 dir5 file2.txt file4.txt$ls l(That shows more options)total 32drwxr-xr-x 2 lubos lubos 4096 Jan 14 17:07 dir1drwxr-xr-x 2 lubos lubos 4096 Jan 14 17:07 dir2

    In Linux, all hidden files and directories start with "." in their file name. By default ls ignores all entries

    starting with . thus not showing hidden files or directories. To display all hidden files and directories

    we can use -a option. For example:

    $ ls -a

    -S options will sort output by file size with smallest file last.

    For Exam:$ ls -Sfile3 file2 file4 file1

    $ ls -SlAsterisk is a most common wildcard. It allows us to list only specific files where part of the filenamecan be replaces with "*" to mach any characters. For example, we want to list only files with txtextension:$ ls *.txt

    ? will represent any single character. For example:

    $ ls file?.txt

    LS command with more Example:

    ls -1 Display output vertically.

  • 7/31/2019 Linux Command1

    3/72

    ls -ld dir Display long listing format of directory dir

    ls -li file Print inode number for a file

    ls -gG Display long listing format but do not show owner and

    group

    ls -m Print comma separated output

    ls -p Display slash after each directory

    ls -l | grep ^d Display only directories

    for i in $( ls *.jpg ); do convert-resize 1024x $i re_$i; done

    Re-size all images with extension JPG in a current working

    directory. Prefix new image with re_

    ls -alct --full-time Display all hidden and non-hidden files and directories

    sorted by creation time with full time exact time

    ls -lact --time-style="+%Y" Display all hidden and non-hidden files and directories

    sorted by creation time. But display only year for each entry

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

  • 7/31/2019 Linux Command1

    4/72

    -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 2008Su Mo Tu We Th Fr Sa

    1 2 3 4 5 67 8 9 10 11 12 13

    14 15 16 17 18 19 2021 22 23 24 25 26 2728 29 30

    cal command displays the current month calendar.

    2. cal -3 5 2008

    Output:

    April 2008 May 2008 June 2008Su 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 76 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 2827 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.

    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.

  • 7/31/2019 Linux Command1

    5/72

  • 7/31/2019 Linux Command1

    6/72

    CD COMMAND

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

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

    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 thespecified service according to default behavior specified in theservice's initialization script.

  • 7/31/2019 Linux Command1

    7/72

    --listPrint whether the specified service is on or off in each level. Ifno service is specified, print runlevel information for all servicesmanaged by chkconfig.

    --levelnumbers

    Specify by number the runlevels to change. Provide numbers asa numeric string: e.g., 016 for levels 0, 1 and 6. Use this tooverride 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 tomcat5service 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

  • 7/31/2019 Linux Command1

    8/72

    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:

    -cDisplays names of only those files whose permissions are beingchanged

    -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

  • 7/31/2019 Linux Command1

    9/72

    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:

    - c Output differing bytes as characters.

    - lPrint the byte number (decimal) and the differing byte values (octal) foreach 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 asfollows.

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

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

  • 7/31/2019 Linux Command1

    10/72

    SYNTAX:The Syntax is

    cp [OPTIONS]... SOURCE DEST

    cp [OPTIONS]... SOURCE... DIRECTORYcp [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.

    -fif an existing destination file cannot be opened, remove itand try again.

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

    --preserve[=ATTR_LIST]

    preserve the specified attributes (default:mode,ownership,timestamps) and security contexts, ifpossible additional 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.

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

  • 7/31/2019 Linux Command1

    11/72

    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 passwd Command?

  • 7/31/2019 Linux Command1

    12/72

    Explanation

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

    SYNTAX:

    The Syntax ispasswd [options]

    OPTIONS:

    -a Show password attributes for all entries.

    -l Locks password entry for name.

    -d Deletes password for name. The login name will not be prompted for password.

    -fForce the user to change password at the next login by expiring the passwordfor name.

    EXAMPLE:

    1. passwd

    Entering just passwd would allow you to change the password. After entering passwd youwill 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 successfullychanged.

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

    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:

    am iPrint the username of the invoking user, The 'am' and 'i' must be spaceseparated.

    -b Prints time of last system boot.

  • 7/31/2019 Linux Command1

    13/72

    -d print dead processes.

    -H Print column headings above the output.

    -iInclude idle time as HOURS:MINUTES. An idle time of . indicates activity withinthe 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 COMMENThiox ttyp3 Jul 10 11:08 . 4578

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

    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:

  • 7/31/2019 Linux Command1

    14/72

    1. whois hscripts.com

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

    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.

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

  • 7/31/2019 Linux Command1

    15/72

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

    What is Linux tar Command?

    tar COMMAND:

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

    SYNTAX:

    The Syntax istar [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

  • 7/31/2019 Linux Command1

    16/72

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

    -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.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 tmpdirectory, prompting you regarding the removal of each file, and then removes the tmpdirectory itself.

    3. To remove more files at once

  • 7/31/2019 Linux Command1

    17/72

    rm file1.txt file2.txt

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

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

    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:

    -cCheck the magic file for format errors. For reasons of efficiency, this validation isnormally 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 textcal.txt: ASCII textmarchlist.txt: ASCII English texttext.txt: ASCII text

    Prints the 'txt' files.

    2. file nimi

    Output:

    nimi: directory

    Print the given object nimi is an directory or file.

  • 7/31/2019 Linux Command1

    18/72

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

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

  • 7/31/2019 Linux Command1

    19/72

    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 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 grep Command?

    Explanation

    grep COMMAND:grep command selects and prints the lines from a file which matches a given string or pattern.

    SYNTAX:

  • 7/31/2019 Linux Command1

    20/72

    The Syntax isgrep [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.

    -d action

    Define action for accessing the directoriesread read all files in the directories.skip skip directories.recurse recursively read all files and directories

    -e pattern Search for 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.

    hscripts has many valuable free scriptsIt is the parent site of www.forums.hscripts.comhscripts include free tutorials and free gif imagesPurchase scripts from usA 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 scriptsIt is the parent site of www.forums.hscripts.comhscripts include free tutorials and free gif images

  • 7/31/2019 Linux Command1

    21/72

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

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

    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 list Searches the pattern list.

    -h Print matched lines but not filenames.

  • 7/31/2019 Linux Command1

    22/72

    -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.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. To search more words from a file :

    egrep 'hscripts|forums|free' file1.txt

    The output will be.hscripts has many valuable free scriptsIt is the parent site of www.forums.hscripts.comhscripts include free tutorials and free gif imagesfree 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

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

  • 7/31/2019 Linux Command1

    23/72

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

    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.

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

    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.comask your technical doubts in our forumour 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.comour forums is free

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

    What is Linux awk Command?

  • 7/31/2019 Linux Command1

    24/72

    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.

    -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 willlook like

    15155625

    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

  • 7/31/2019 Linux Command1

    25/72

    file2.txt : output file

    The above command will redirect the output to file2.txt and it will look like,14 15 21015 15 225

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

    What is Linux diffCommand?

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

    HIOX TESTHSCRIPTS.com

  • 7/31/2019 Linux Command1

    26/72

    with friend shiphiox india

    with friend ship

    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 andit will produce the following output.

    2c2< hscripts.com---> HSCRIPTS.com4d3< 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 todifferentiate the files.

    HIOX TEST HIOX TESThscripts.com | HSCRIPTS.comwith friend ship with friend shipHioxindia.com [ListFldrs] N NextCmd K KBLock

    About pine

    Command line program for Internet News and Email.

    Syntax

    pine [option] [address , address]pinef [option] [address , address]

    address Send mail to address this will open pine direc

    -a Special anonymous mode forUWIN.

    -attach file Send e-mail with the selected file as an attac

    -attach_and_deletefile

    Send e-mail with the selected file as an attac

    -attach file-list Send e-mail with the listed file-list as an atta

    -c context-number context-number is the number corresponding

    argument should be applied. By default the -

    -d debug-level Output diagnostic info at debug-level (0-9) tdebugging off and suppresses the .pine-debu

    -d key[=val] Fine tuned output of diagnostic messages wh

    "timestamp" appends each message with a ti

    representing none to verbose IMAP telemetry

    http://www.computerhope.com/jargon/ju.htmhttp://www.computerhope.com/jargon/ju.htmhttp://www.computerhope.com/jargon/ju.htm
  • 7/31/2019 Linux Command1

    40/72

    corresponding to the number of debug files to mai

    indicating an inverse threshold for message output

    -f folder Open folder (in first defined folder collection, use -

    -F file Open named text file and view with Pine's browser

    -h Help: list valid command-line options.

    -i Start up in the FOLDER Indexscreen.

    -I keystrokes Initial (comma separated list of) keystrokes which

    -k Use function keys for commands. This is the same

    -n number Start up with current message-number set to num

    -nr Special mode forUWIN.

    -o Open first folder read-only.

    About bc

    Calculator.

    Syntax

    bc [-c] [-l] [file]

    -c Compile only. The output is dc commands that are sen

    -l Define the math functions and initialize scale to 20, ins

    file Name of the file that contains the bc commands to be

    http://www.computerhope.com/jargon/ju.htmhttp://www.computerhope.com/jargon/ju.htmhttp://www.computerhope.com/jargon/ju.htm
  • 7/31/2019 Linux Command1

    41/72

    Usage

    L A letter a-z

    E An expression: a (mathematical or logical) value, an oand operators that evaluates to a value.

    S Statement

    /* and /* Comment

    sqrt ( E ) Square root

    length ( E ) Number of significant decimal digits.

    scale ( E ) Number of digits right of decimal point.

    quit Exits the bc command.

    Available Operators

    + - * / % ^(% is remainder; ^ is power)

    ++ -- (prefix and postfix; apply to names)

    == = != < > = =+ =- =* =/ =% =^

    Examples

    bc cal.txt

    Would result in 3, see below notes.

    Within the cal.txt file you could have a simple statement such

    as the example shown below.

    /* Add the value 1+2 /*1+2quit

    When running the above command you will receive the results

  • 7/31/2019 Linux Command1

    42/72

    of the cal.txt file. Which in this case would be 3.

    Another example:

    How to do calculation if I only have command line? If you have BC you can, and you can do a verycomplicated calculation. To perform calculation, you can type bc and start to type your question, orpassing question through pipeline, such as

    echo "56.8 + 77.7" | bc

    Let say you want to convert decimal to hexadecimal, you can do this.

    echo "obase=16; ibase=10; 56" | bc

    ibase is input base, and obase is output base, by specified the base, you can convert number from onebase to another.To perform division is a bit tricky, because the will result usually in floating point. Therefore in order to getthe correct answer, you need to specified scale. scale means the precision of floating point, how manydigit after the point. By default the scale is 0, that means it is integer.5.00500 the scale is 55.005 the scale is 3So the example :

    echo "scale=6; 60/7.02" | bc

    1. Calculation using Single command

    $ echo "4+10" | bc

    14

    2. Calculation using Multiple commands

    $ echo "obase=15;5+9" | bc

    E

    3. Using previous results in the current operation

    In the following example, last represents the result of the previous calculation.

  • 7/31/2019 Linux Command1

    43/72

    echo "1+3;last/2" | bc

    4

    2

    In the following example, . (dot) represents the result of the previous calculation.

    $ echo "1+3;./2" | bc

    4

    2

    4. Another way of executing bc calculation

    bc

  • 7/31/2019 Linux Command1

    44/72

    Figuring out why a program has stopped working since yesterday, even though the user didn't

    change anything; honest!

    Monitoring system security

    Adding new systems to the network

    Talking with vendors to determine if a problem is yours or theirs, and getting them to fix it when

    it is their problem

    Figuring out why "the network" (or "Pine", or "the computer") is so slow

    Trying to free up disc space

    Rebooting the system after a crash (usually happens when you are at home or have to catch a

    bus)

    Writing scripts to automate as many of the above tasks as possible

    What are system configuration files?

    The kernel itself may be considered a "program." Why does the kernel need configuration files?

    The kernel needs to know the list of users and groups in the system, and manage file permissions

    (that is, determine if a file can be opened by a specific user, according to the permissions,

    UNIX_USERS). Note that these files are not specifically read by programs, but by a function

    provided by a system library, and used by the kernel. For instance, a program needing the

    (encrypted) password of a user should not open the /etc/passwd file. Instead, it should call the

    system library function getpw(). This kind of function is also known as a system call. It is up to

    the kernel (through the system library) to open the /etc/passwd file and after that, search for the

    password of the requested user.

    Most of the configuration files in the Red Hat Linux system are in the /etc directory unless

    otherwise specified. The configuration files can be broadly classified into the following

    categories:

    ANOTHER WORK OF configuration files:

    This article explains configuration files on a Linux system that control user permissions, system

    applications, daemons, services, and other administrative tasks in a multi-user, multi-tasking

    environment. These tasks include managing user accounts, allocating disk quotas, managing e-

    mails and newsgroups, and configuring kernel parameters. This article also classifies the config

    files present on a Red Hat Linux system based on their usage and the services they affect.

    VI EDITOR:

    There are many ways to edit files in Unix and for me one of the best ways is using screen-

  • 7/31/2019 Linux Command1

    45/72

    oriented text editor vi. This editor enable you to edit lines in context with other lines in the file.

    Now a days you would find an improved version of vi editor which is called VIM. Here VIM

    stands for Vi IMproved.

    The vi is generally considered the de facto standard in Unix editors because:

    It's usually available on all the flavors of Unix system.

    Its implementations are very similar across the board.

    It requires very few resources.

    It is more user friendly than any other editors like ed or ex.

    You can use vi editor to edit an existing file or to create a new file from scratch. You can also

    use this editor to just read a text file.

    Starting the vi Editor:

    There are following way you can start using vi editor:

    Command Description

    vi filename Creates a new file if it already does not exist, otherwise opens existing file.

    vi -R filename Opens an existing file in read only mode.

    view filename Opens an existing file in read only mode.

    Following is the example to create a new file testfile if it already does not exist in the current

    working directory:

    [amrood]$vi testfile

    As a result you would see a screen something like as follows:

    |~~~~~~

  • 7/31/2019 Linux Command1

    46/72

    ~~~~~~"testfile" [New File]

    You will notice a tilde (~) on each line following the cursor. A tilde represents an unused line. If

    a line does not begin with a tilde and appears to be blank, there is a space, tab, newline, or some

    other nonviewable character present.

    So now you have opened one file to start with. Before proceeding further let us understanding

    few minor but important concepts explained below.

    Operation Modes:

    While working with vi editor you would come across following two modes:

    1. Command mode: This mode enables you to perform administrative tasks such as savingfiles, executing commands, moving the cursor, cutting (yanking) and pasting lines or

    words, and finding and replacing. In this mode, whatever you type is interpreted as a

    command.

    2. Insert mode: This mode enables you to insert text into the file. Everything that's typed inthis mode is interpreted as input and finally it is put in the file .

    The vi always starts in command mode. To enter text, you must be in insert mode. To come ininsert mode you simply type i. To get out of insert mode, press the Esc key, which will put you

    back into command mode.

    Hint: If you are not sure which mode you are in, press the Esc key twice, and then you'll be in

    command mode. You open a file using vi editor and start type some characters and then come in

    command mode to understand the difference.

    Getting Out of vi:

    The command to quit out of vi is :q. Once in command mode, type colon, and 'q', followed byreturn. If your file has been modified in any way, the editor will warn you of this, and not let you

    quit. To ignore this message, the command to quit out of vi without saving is :q!. This lets you

    exit vi without saving any of the changes.

    The command to save the contents of the editor is :w. You can combine the above command

    with the quit command, or :wq and return.

  • 7/31/2019 Linux Command1

    47/72

    The easiest way to save your changes and exit out of vi is the ZZ command. When you are in

    command mode, type ZZ and it will do the equivalent of :wq.

    You can specify a different file name to save to by specifying the name after the :w. For

    example, if you wanted to save the file you were working as another filename called filename2,

    you would type :w filename2 and return. Try it once.

    Moving within a File:

    To move around within a file without affecting your text, you must be in command mode (press

    Esc twice). Here are some of the commands you can use to move around one character at a time:

    Command Description

    k Moves the cursor up one line.

    j Moves the cursor down one line.

    h Moves the cursor to the left one character position.

    l Moves the cursor to the right one character position.

    There are following two important points to be noted:

    The vi is case-sensitive, so you need to pay special attention to capitalization when using

    commands.

    Most commands in vi can be prefaced by the number of times you want the action to

    occur. For example, 2j moves cursor two lines down the cursor location.

    There are many other ways to move within a file in vi. Remember that you must be in command

    mode (press Esc twice). Here are some more commands you can use to move around the file:

    Command Description

    0 or | Positions cursor at beginning of line.

    $ Positions cursor at end of line.

  • 7/31/2019 Linux Command1

    48/72

    w Positions cursor to the next word.

    b Positions cursor to previous word.

    ( Positions cursor to beginning of current sentence.

    ) Positions cursor to beginning of next sentence.

    E Move to the end of Blank delimited word

    { Move a paragraph back

    } Move a paragraph forward

    [[ Move a section back

    ]] Move a section forward

    n| Moves to the column n in the current line

    1G Move to the first line of the file

    G Move to the last line of the file

    nG Move to nth line of the file

    :n Move to nth line of the file

    fc Move forward to c

    Fc Move back to c

    H Move to top of screen

    nH Moves to nth line from the top of the screen

  • 7/31/2019 Linux Command1

    49/72

    M Move to middle of screen

    L Move to botton of screen

    nL Moves to nth line from the bottom of the screen

    :xColon followed by a number would position the cursor on line number

    represented by x

    Control Commands:

    There are following useful command which you can use along with Control Key:

    Command Description

    CTRL+d Move forward 1/2 screen

    CTRL+d Move forward 1/2 screen

    CTRL+f Move forward one full screen

    CTRL+u Move backward 1/2 screen

    CTRL+b Move backward one full screen

    CTRL+e Moves screen up one line

    CTRL+y Moves screen down one line

    CTRL+u Moves screen up 1/2 page

    CTRL+d Moves screen down 1/2 page

    CTRL+b Moves screen up one page

  • 7/31/2019 Linux Command1

    50/72

    CTRL+f Moves screen down one page

    CTRL+I Redraws screen

    Editing Files:

    To edit the file, you need to be in the insert mode. There are many ways to enter insert mode

    from the command mode:

    Command Description

    i Inserts text before current cursor location.

    I Inserts text at beginning of current line.

    a Inserts text after current cursor location.

    A Inserts text at end of current line.

    o Creates a new line for text entry below cursor location.

    O Creates a new line for text entry above cursor location.

    Deleting Characters:

    Here is the list of important commands which can be used to delete characters and lines in an

    opened file:

    Command Description

    x Deletes the character under the cursor location.

    X Deletes the character before the cursor location.

  • 7/31/2019 Linux Command1

    51/72

    dw Deletes from the current cursor location to the next word.

    d^ Deletes from current cursor position to the beginning of the line.

    d$ Deletes from current cursor position to the end of the line.

    D Deletes from the cursor position to the end of the current line.

    dd Deletes the line the cursor is on.

    As mentioned above, most commands in vi can be prefaced by the number of times you want the

    action to occur. For example, 2x deletes two character under the cursor location and 2dd deletes

    two lines the cursor is on.

    I would highly recommend to exercise all the above commands properly before proceeding

    further.

    Change Commands:

    You also have the capability to change characters, words, or lines in vi without deleting them.

    Here are the relevant commands:

    Command Description

    cc Removes contents of the line, leaving you in insert mode.

    cwChanges the word the cursor is on from the cursor to the lowercase w end

    of the word.

    rReplaces the character under the cursor. vi returns to command mode after

    the replacement is entered.

    ROverwrites multiple characters beginning with the character currently under

    the cursor. You must use Esc to stop the overwriting.

    sReplaces the current character with the character you type. Afterward, you

    are left in insert mode.

  • 7/31/2019 Linux Command1

    52/72

    SDeletes the line the cursor is on and replaces with new text. After the new

    text is entered, vi remains in insert mode.

    Copy and Past Commands:

    You can copy lines or words from one place and then you can past them at another place using

    following commands:

    Command Description

    yy Copies the current line.

    yw Copies the current word from the character the lowercase w cursor is onuntil the end of the word.

    p Puts the copied text after the cursor.

    P Puts the yanked text before the cursor.

    Advanced Commands:

    There are some advanced commands that simplify day-to-day editing and allow for more

    efficient use of vi:

    Command Description

    J Join the current line with the next one. A count joins that many lines.

    Shifts the current line to the right by one shift width.

    ~ Switch the case of the character under the cursor.

  • 7/31/2019 Linux Command1

    53/72

    ^GPress CNTRL and G keys at the same time to show the current filename and

    the status.

    URestore the current line to the state it was in before the cursor entered the

    line.

    u Undo the last change to the file. Typing 'u' again will re-do the change.

    J Join the current line with the next one. A count joins that many lines.

    :f Displays current position in the file in % and file name, total number of file.

    :f filename Renames current file to filename.

    :w filename Write to file filename.

    :e filename Opens another file with filename.

    :cd dirname Changes current working directory to dirname.

    :e # Use to toggle between two opened files.

    :n In case you open multiple files using vi, use :n to go to next file in the series.

    :pIn case you open multiple files using vi, use :p to go to previous file in the

    series.

    :NIn case you open multiple files using vi, use :N to go to previous file in the

    series.

    :r file Reads file and inserts it after current line

    :nr file Reads file and inserts it after line n.

    Word and Character Searching:

  • 7/31/2019 Linux Command1

    54/72

    The vi editor has two kinds of searches: string and character. For a string search, the / and ?

    commands are used. When you start these commands, the command just typed will be shown on

    the bottom line, where you type the particular string to look for.

    These two commands differ only in the direction where the search takes place:

    The / command searches forwards (downwards) in the file.

    The ? command searches backwards (upwards) in the file.

    The n and N commands repeat the previous search command in the same or opposite direction,

    respectively. Some characters have special meanings while using in search command and

    preceded by a backslash (\) to be included as part of the search expression.

    Character Description

    ^Search at the beginning of the line. (Use at the beginning of a search

    expression.)

    . Matches a single character.

    * Matches zero or more of the previous character.

    $ End of the line (Use at the end of the search expression.)

    [ Starts a set of matching, or non-matching expressions.

    See the '

  • 7/31/2019 Linux Command1

    55/72

    Set Commands:

    You can change the look and feel of your vi screen using the following :set commands. To use

    these commands you have to come in command mode then type :set followed by any of the

    following options:

    Command Description

    :set ic Ignores case when searching

    :set ai Sets autoindent

    :set noai To unset autoindent.

    :set nu Displays lines with line numbers on the left side.

    :set swSets the width of a software tabstop. For example you would set a shift

    width of 4 with this command: :set sw=4

    :set wsIfwrapscan is set, if the word is not found at the bottom of the file, it will

    try to search for it at the beginning.

    :set wmIf this option has a value greater than zero, the editor will automatically"word wrap". For example, to set the wrap margin to two characters, you

    would type this: :set wm=2

    :set ro Changes file type to "read only"

    :set term Prints terminal type

    :set bf Discards control characters from input

    Running Commands:

    The vi has the capability to run commands from within the editor. To run a command, you only

    need to go into command mode and type :! command.

  • 7/31/2019 Linux Command1

    56/72

    For example, if you want to check whether a file exists before you try to save your file to that

    filename, you can type :! ls and you will see the output of ls on the screen.

    When you press any key (or the command's escape sequence), you are returned to your vi

    session.

    Replacing Text:

    The substitution command (:s/) enables you to quickly replace words or groups of words within

    your files. Here is the simple syntax:

    :s/search/replace/g

    The g stands for globally. The result of this command is that all occurrences on the cursor's line

    are changed.

    IMPORTANT:

    Here are the key points to your success with vi:

    You must be in command mode to use commands. (Press Esc twice at any time to ensure

    that you are in command mode.)

    You must be careful to use the proper case (capitalization) for all commands.

    You must be in insert mode to enter text.

    useradd

    useradd - Adding a new user

    Options:

    -d home directory

    -s starting program (shell)

    -p password

    -g (primary group assigned to the users)

    -G (Other groups the user belongs to)

    -m (Create the user's home directory

  • 7/31/2019 Linux Command1

    57/72

    Example: To add a new user with

    a primary group ofusers

    a second group mgmt

    starting shell /bin/bash

    password ofxxxx home directory ofroger

    create home directory

    a login name ofroger

    useradd -gusers -Gmgmt -s/bin/shell -pxxxx -d/home/roger -m roger

    Linux Users

    Adding a new user(useradd) Modifying an existing user(usermod)

    Where user and group information is

    stored

    Deleting a user(userdel) User's passwdpasswd

    Switch Usersu

    Every user who has access to a Linux system needs a login and a password. Each user must belong

    to a primary group and for security or access purposes can belong to several secondary groups.

    http://www.ahinc.com/linux101/users.htm#Adding%20a%20new%20userhttp://www.ahinc.com/linux101/users.htm#Adding%20a%20new%20userhttp://www.ahinc.com/linux101/users.htm#Modify%20existing%20userhttp://www.ahinc.com/linux101/users.htm#Modify%20existing%20userhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Deleting%20a%20userhttp://www.ahinc.com/linux101/users.htm#Deleting%20a%20userhttp://www.ahinc.com/linux101/users.htm#User%27s%20Passwordhttp://www.ahinc.com/linux101/users.htm#User%27s%20Passwordhttp://www.ahinc.com/linux101/users.htm#Switch%20Userhttp://www.ahinc.com/linux101/users.htm#Switch%20Userhttp://www.ahinc.com/linux101/users.htm#Switch%20Userhttp://www.ahinc.com/linux101/users.htm#User%27s%20Passwordhttp://www.ahinc.com/linux101/users.htm#Deleting%20a%20userhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Modify%20existing%20userhttp://www.ahinc.com/linux101/users.htm#Adding%20a%20new%20user
  • 7/31/2019 Linux Command1

    58/72

    In order to create new logins, modify or delete users, you must already be logged in as root. The

    root login is the highest level and only certain individuals should have access to the root account.

    useradd - Adding a new user

    Options:

    -d home directory

    -s starting program (shell)

    -p password

    -g (primary group assigned to the users)

    -G (Other groups the user belongs to)

    -m (Create the user's home directory

    Example: To add a new user with

    a primary group ofusers

    a second group mgmt

    starting shell /bin/bash

    password ofxxxx

    home directory ofroger

    create home directory

    a login name ofroger

    useradd -gusers -Gmgmt -s/bin/shell -pxxxx -d/home/roger -m roger

    usermod - Modifying existing user

    Options:

    -d home directory

    -s starting program (shell)

    -p password

    -g (primary group assigned to the users)

    -G (Other groups the user belongs to)

    Example: To add the group 'others' to the user roger

    usermod -Gothers roger

  • 7/31/2019 Linux Command1

    59/72

    Linux Users

    Adding a new user(useradd)

    Modifying an existing user(usermod)

    Where user and group information is

    stored

    Deleting a user(userdel)

    User's passwdpasswd

    Switch Usersu

    Every user who has access to a Linux system needs a login and a password. Each user must belong

    to a primary group and for security or access purposes can belong to several secondary groups.

    In order to create new logins, modify or delete users, you must already be logged in as root. The

    root login is the highest level and only certain individuals should have access to the root account.

    useradd - Adding a new user

    Options:

    -d home directory

    -s starting program (shell)

    -p password

    -g (primary group assigned to the users)

    -G (Other groups the user belongs to)

    http://www.ahinc.com/linux101/users.htm#Adding%20a%20new%20userhttp://www.ahinc.com/linux101/users.htm#Adding%20a%20new%20userhttp://www.ahinc.com/linux101/users.htm#Modify%20existing%20userhttp://www.ahinc.com/linux101/users.htm#Modify%20existing%20userhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Deleting%20a%20userhttp://www.ahinc.com/linux101/users.htm#Deleting%20a%20userhttp://www.ahinc.com/linux101/users.htm#User%27s%20Passwordhttp://www.ahinc.com/linux101/users.htm#User%27s%20Passwordhttp://www.ahinc.com/linux101/users.htm#Switch%20Userhttp://www.ahinc.com/linux101/users.htm#Switch%20Userhttp://www.ahinc.com/linux101/users.htm#Switch%20Userhttp://www.ahinc.com/linux101/users.htm#User%27s%20Passwordhttp://www.ahinc.com/linux101/users.htm#Deleting%20a%20userhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Where%20is%20user%20and%20group%20information%20storedhttp://www.ahinc.com/linux101/users.htm#Modify%20existing%20userhttp://www.ahinc.com/linux101/users.htm#Adding%20a%20new%20user
  • 7/31/2019 Linux Command1

    60/72

    -m (Create the user's home directory

    Example: To add a new user with

    a primary group ofusers

    a second group mgmt starting shell /bin/bash

    password ofxxxx

    home directory ofroger

    create home directory

    a login name ofroger

    useradd -gusers -Gmgmt -s/bin/shell -pxxxx -d/home/roger -m roger

    top of page

    usermod - Modifying existing user

    Options:

    -d home directory

    -s starting program (shell)

    -p password

    -g (primary group assigned to the users)

    -G (Other groups the user belongs to)

    Example: To add the group 'others' to the user roger

    usermod -Gothers roger

    top of page

    userdel - Deleting a user

    Options:

    -r (remove home directory)

    Example: To remove the user 'roger' and his home directory

    userdel -r roger

    http://www.ahinc.com/linux101/users.htm#tophttp://www.ahinc.com/linux101/users.htm#tophttp://www.ahinc.com/linux101/users.htm#tophttp://www.ahinc.com/linux101/users.htm#tophttp://www.ahinc.com/linux101/users.htm#tophttp://www.ahinc.com/linux101/users.htm#top
  • 7/31/2019 Linux Command1

    61/72

    passwd - User's Password

    Options:

    user's name (Only required if you are root and want to change another user's password)

    Example: To change the password for the account you are currently logged in as...

    passwd

    Enter existing password

    Enter new password

    Enter new password again (to validate)

    Example: To change the password for the user 'roger' (only you are logged in as root)...

    passwd roger

    Enter existing password (can be either roger's password or root's password)Enter new password

    Enter new password again (to validate)

    Where user and group information stored

    User names and primary groups are stored in/etc/passwd. This file can be directly edited using the

    'vi' editor, although this is not recommended. Format of the file is...

    User (name normally all lower case)

    Password (encrypted - only contains the letter 'x') User ID (a unique number of each user)

    Primary Group ID

    Comment (Normally the person's full name)

    Home directory (normally /home/

    Default shell (normally /bin/bash)

    Each field is separated by a colon.

    Passwords for each user are stored in/etc/shadow. This file should only be changed using the

    passwd command.

    Group information is stored in /etc/group. This file can be directly edited using the 'vi' editor.

    Format of the file is...

    Group name

    Group password (hardly ever used)

    Group ID

    User names (separated by commas)

  • 7/31/2019 Linux Command1

    62/72

    Each field is separated by a colon.

    su - Switch User

    To switch to another user, use the su command. This is most commonly used to switch to the root

    account.

    Example: To switch to root account...

    su

    Enter root's passwd

    Example: To switch to the user 'roger'...

    su roger

    Enter roger's or root's passwd

    To return to original user, enter exit

    In this article, let us review the Linux filesystem structures and understand the meaning of

    individual high-level directories.

    Linux Directory Structure (File System Structure)

    Explained with Examples

  • 7/31/2019 Linux Command1

    63/72

    1. / Root

    Every single file and directory starts from the root directory.

  • 7/31/2019 Linux Command1

    64/72

    Only root user has write privilege under this directory.

    Please note that /root is root users home directory, which is not same as /.

    2. /bin User Binaries

    Contains binary executables. Common linux commands you need to use in single-user modes are located under this directory.

    Commands used by all the users of the system are located here.

    For example: ps, ls, ping, grep, cp.

    3. /sbin System Binaries

    Just like /bin, /sbin also contains binary executables.

    But, the linux commands located under this directory are used typically by system aministrator, for

    system maintenance purpose.

    For example: iptables, reboot, fdisk, ifconfig, swapon

    4. /etc Configuration Files

    Contains configuration files required by all programs.

    This also contains startup and shutdown shell scripts used to start/stop individual programs.

    For example: /etc/resolv.conf, /etc/logrotate.conf

    5. /dev Device Files

    Contains device files.

    These include terminal devices, usb, or any device attached to the system.

    For example: /dev/tty1, /dev/usbmon0

    6. /proc Process Information

    Contains information about system process.

    This is a pseudo filesystem contains information about running process. For example: /proc/{pid}

    directory contains information about the process with that particular pid.

    This is a virtual filesystem with text information about system resources. For example:

    /proc/uptime

    7. /var Variable Files

    var stands for variable files.

    Content of the files that are expected to grow can be found under this directory.

    This includes system log files (/var/log); packages and database files (/var/lib); emails (/var/mail);

    print queues (/var/spool); lock files (/var/lock); temp files needed across reboots (/var/tmp);

    8. /tmp Temporary Files

  • 7/31/2019 Linux Command1

    65/72

    Directory that contains temporary files created by system and users.

    Files under this directory are deleted when system is rebooted.

    9. /usr User Programs

    Contains binaries, libraries, documentation, and source-code for second level programs.

    /usr/bin contains binary files for user programs. If you cant find a user binary under /bin, look

    under /usr/bin. For example: at, awk, cc, less, scp

    /usr/sbin contains binary files for system administrators. If you cant find a system binary under

    /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel

    /usr/lib contains libraries for /usr/bin and /usr/sbin

    /usr/local contains users programs that you install from source. For example, when you install

    apache from source, it goes under /usr/local/apache2

    10. /home Home Directories

    Home directories for all users to store their personal files.

    For example: /home/john, /home/nikita

    11. /boot Boot Loader Files

    Contains boot loader related files.

    Kernel initrd, vmlinux, grub files are located under /boot

    For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic

    12. /lib System Libraries

    Contains library files that supports the binaries located under /bin and /sbin

    Library filenames are either ld* or lib*.so.*

    For example: ld-2.11.1.so, libncurses.so.5.7

    13. /opt Optional add-on Applications

    opt stands for optional.

    Contains add-on applications from individual vendors.

    add-on applications should be installed under either /opt/ or /opt/ sub-directory.

    14. /mnt Mount Directory

    Temporary mount directory where sysadmins can mount filesystems.

    15. /media Removable Media Devices

    Temporary mount directory for removable devices.

    For examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for

  • 7/31/2019 Linux Command1

    66/72

    CD writer

    16. /srv Service Data

    srv stands for service.

    Contains server specific services related data. For example, /srv/cvs contains CVS related data.

    Definition of Operating System:An Operating System is a computer program that manages theresourcesof a computer. It accepts

    keyboard or mouse inputs from users and displays the results of the actions and allows the user to run

    applications, or communicate with other computers via networked connections.

    Types of Operating System:

    There are Many Operating Systems those have be Developed for Performing theOperations those are requested by the user. There are Many Operating Systems whichhave the Capability to Perform the Requests those are received from the System. TheOperating system can perform a Single Operation and also Multiple Operations at a Time.So there are many types of Operating systems those are organized by using their WorkingTechniques.

    1) Serial Processing: The Serial Processing Operating Systems are those whichPerforms all the instructions into a Sequence Manner or the Instructions those are givenby the user will be executed by using the FIFO Manner means First in First Out. All theInstructions those are Entered First in the System will be Executed First and theInstructions those are Entered Later Will be Executed Later. For Running theInstructions the Program Counter is used which is used for Executing all theInstructions. In this the Program Counter will determines which instruction is going toExecute and the which instruction will be Execute after this. Mainly the Punch Cards areused for this. In this all the Jobs are firstly Prepared and Stored on the Card and afterthat card will be entered in the System and after that all the Instructions will be executedone by One. But the Main Problem is that a user doesnt interact with the System

    while he is working on the System, means the user cant be able to enter the data forExecution.

    2) Batch Processing: The Batch Processing is same as the Serial ProcessingTechnique. But in the Batch Processing Similar Types of jobs are Firstly Prepared andthey are Stored on the Card. and that card will be Submit to the System for the Processing.The System then Perform all the Operations on the Instructions one by one. And a usercant be Able to specify any input. And Operating System wills increments his Program

    http://cplus.about.com/od/introductiontoprogramming/g/resourcesdefn.htmhttp://cplus.about.com/od/introductiontoprogramming/g/resourcesdefn.htmhttp://cplus.about.com/od/introductiontoprogramming/g/resourcesdefn.htmhttp://cplus.about.com/od/glossar1/g/applicationdefn.htmhttp://cplus.about.com/od/glossar1/g/applicationdefn.htmhttp://cplus.about.com/od/glossar1/g/applicationdefn.htmhttp://cplus.about.com/od/introductiontoprogramming/g/resourcesdefn.htm
  • 7/31/2019 Linux Command1

    67/72

    Counter for Executing the Next Instruction. The Main Problem is that the Jobs those areprepared for Execution must be the Same Type and if a job requires for any type ofInput then this will not be Possible for the user. And Many Time will be wasted forPreparing the Batch. The Batch Contains the Jobs and all those jobs will be executedwithout the user Intervention. And Operating System will use the LOAD and RUN

    Operation. This will first LOAD the Job from the Card and after that he will executethe instructions. By using the RUN Command. The Speed of the Processing the Job willbe Depend on the Jobs and the Results those are produced by the System in difference ofTime which is used for giving or submit the Job and the Time which is used for Displayingthe Results on the Screen.

    3) Multi-Programming: As we know that in the Batch Processing System there aremultiple jobs Execute by the System. The System first prepare a batch and after that hewill Execute all the jobs those are Stored into the Batch. But the Main Problem is that if aprocess or job requires an Input and Output Operation, then it is not possible and secondthere will be the wastage of the Time when we are preparing the batch and the CPU will

    remain idle at that Time.

    But With the help of Multi programming we can Execute Multiple Programs on theSystem at a Time and in the Multi-programming the CPU will never get idle, because withthe help of Multi-Programming we can Execute Many Programs on the System and Whenwe are Working with the Program then we can also Submit the Second or AnotherProgram for Running and the CPU will then Execute the Second Program after thecompletion of the First Program. And in this we can also specify our Input means a usercan also interact with the System. The Multi-programming Operating Systems never useany cards because the Process is entered on the Spot by the user. But the OperatingSystem also uses the Process of Allocation and De-allocation of the Memory Means

    he will provide the Memory Space to all the Running and all the Waiting Processes. Theremust be the Proper Management of all the Running Jobs.

    4) Real Time System: There is also an Operating System which is known as Real TimeProcessing System. In this Response Time is already fixed. Means time to Display theResults after Possessing has fixed by the Processor or CPU. Real Time System is used atthose Places in which we Requires higher and Timely Response. These Types ofSystems are used in Reservation. So when we specify the Request, the CPU will performat that Time. There are two Types of Real Time System

    1) Hard Real Time System: In the Hard Real Time System, Time is fixed and we cantChange any Moments of the Time of Processing. Means CPU will Process the data as weEnters the Data.

    2) Soft Real Time System: In the Soft Real Time System, some Moments can beChange. Means after giving the Command to the CPU, CPU Performs the Operation aftera Microsecond.

    5) Distributed Operating System. - Distributed Means Data is Stored and Processed on

  • 7/31/2019 Linux Command1

    68/72

    Multiple Locations. When a Data is stored on to the Multiple Computers, those are placedin Different Locations. Distributed means In the Network, Network Collections ofComputers are connected with Each other. Then if we want to Take Some Data Fromother Computer, Then we uses the Distributed Processing System. And we can also Insertand Remove the Data from out Location to another Location. In this Data is shared

    between many users. And we can also Access all the Input and Output Devices are alsoaccessed by Multiple Users.

    6) Multiprocessing: Generally a Computer has a Single Processor means a Computerhave a just one CPU for Processing the instructions. But if we are Running multiple jobs,then this will decrease the Speed of CPU. For Increasing the Speed of Processing then weuses the Multiprocessing, in the Multi Processing there are two or More CPU in a SingleOperating System if one CPU will fail, then other CPU is used for providing backup to thefirst CPU. With the help of Multi-processing, we can Execute Many Jobs at a Time. All theOperations are divided into the Number of CPUs. if first CPU Completed his Work beforethe Second CPU, then the Work of Second CPU will be divided into the First and Second.

    7)Parallel operating systems are used to interface multiple networked computers tocomplete tasks in parallel. The architecture of the software is often a UNIX-basedplatform, which allows it to coordinate distributed loads between multiple computersin a network. Parallel operating systems are able to use software to manage all of thedifferent resources of the computers running in parallel, such as memory, caches, storagespace, and processing power. Parallel operating systems also allow a user to directlyinterface with all of the computers in the network.

    A parallel operating systemworks by dividing sets of calculations into smaller parts anddistributing them between the machines on a network. To facilitate communicationbetween the processor cores and memory arrays, routing software has to either shareits memory by assigning the same address space to all of the networked computers, or distribute its memory by assigning a different address space to each processing core.Sharing memory allows the operating system to run very quickly, but it is usually not aspowerful. When using distributed shared memory, processors have access to both theirown local memory and the memory of other processors; this distribution may slow theoperating system, but it is often more flexible and efficient.

    An operating system is the single most important software when you

    run a computer, it is what takes care of pretty much everything on a computer system, while the

    majority of computers we see happen to be using one type of operating system performing the

    same functions, operating systems can be branched into several different types as well. Its been awhile since Ive shared a fairly technical post on Computer Realm so I guess today would be a good

    http://www.wisegeek.com/what-is-an-operating-system.htmhttp://www.wisegeek.com/what-is-an-operating-system.htmhttp://www.wisegeek.com/what-is-shared-memory.htmhttp://www.wisegeek.com/what-is-shared-memory.htmhttp://www.wisegeek.com/what-is-shared-memory.htmhttp://www.wisegeek.com/what-is-an-operating-system.htm
  • 7/31/2019 Linux Command1

    69/72

    day for one.

    Batch Processing Operating System

    In a batch processing operating system interaction between the user and processor is limited or there

    is no interaction at all during the execution of work. Data and programs that need to be processed

    are bundled and collected as a batch and executed together.

    Batch processing operating systems are ideal in situations where:

    - There are large amounts of data to be processed.

    - Similar data needs to be processed.

    - Similar processing is involved when executing the data.

    The system is capable of identifying times when the processor is idle at which time batches maybe

    processed. Processing is all performed automatically without any user intervention.

    Real-time Operating System

    A real-time operating system processes inputs simultaneously, fast enough to affect the next input orprocess. Real-time systems are usually used to control complex systems that require a lot of

    processing like machinery and industrial systems.

    Single User Operating System

    A single user OS as the name suggests is designed for one user to effectively use a computer at a

    time.

    http://www.computer-realm.net/wp-content/uploads/post-images/2009/08/linux-mac-windows.png
  • 7/31/2019 Linux Command1

    70/72

    Multi-Tasking Operating System

    In this type of OS several applications maybe simultaneously loaded and used in the memory. While

    the processor handles only one application at a particular time it is capable of switching between the

    applications effectively to apparently simultaneously execute each application. This type of

    operating system is seen everywhere today and is the most common type of OS, the Windowsoperating system would be an example.

    Multi-User Operating System

    This type of OS allows multiple users to simultaneously use the system, while here as well, the

    processor splits its resources and handles one user at a time, the speed and efficiency at which it

    does this makes it apparent that users are simultaneously using the system, some network systems

    utilize this kind of operating system.

    Distributed Operating System

    In a distributed system, software and data maybe distributed around the system, programs and files

    maybe stored on different storage devices which are located in different geographical locations and

    maybe accessed from different computer terminals.

    While we are mostly accustomed to seeing multi-tasking and multi-user operating systems, the other

    operating systems are usually used in companies and firms to power special systems.

    Introduction to Vi

    Despite its very limited ergonomics, Vi i is one of the most popular text editors texte under Unix

    type systems (withEmacs andpico). Under Linux, there is a free version ofVi called Vim (Vi

    Improved). Vi (pronounced vee-eye) is an editor that is fully in text mode, which means that all

    actions are carried out with the help of text commands. This editor, although it may appear of little

    practical use at first, is very powerful and can be very helpful in case the graphical interface

    malfunctions.

    The syntax to launch Vi is as follows:

    vi name_of_the_file

    Once the file is open, you can move around by using cursors or the keys h, j, kand l (in case the

    keyboard does not have any arrow cursors).

    Vi modes

    Vi has three operating modes:

  • 7/31/2019 Linux Command1

    71/72

    Regular mode: This is the mode you enter whenever you open a file. This mode allows

    typing commands

    Insertion mode: This mode makes it possible to insert characters you capture inside of the

    document. To switch to insertion mode, just press the keyInserton your keyboard or, by

    default, the key i

    Replacement mode: This mode allows you to replace existing text by the text you capture.Just hit ragain to go to replacementmode and hit the keyEsc to return to regular mode

    Basic commands

    Command Description

    :q Quit the editor (without saving)

    :q! Forces the editor to quit without saving (even if changes were made to the document)

    :wq Saves the document and quits the editor

    :filename Saves the document under the specified name

    Editing commands

    Command Description

    x Deletes the character that is currently under cursor

    dd Deletes the line that is currently under cursor

    dxd Deletesx lines starting with the one currently under the cursor

    nx Deletes n characters starting with the one currently under the cursor

    x>> Indentsx lines to the right starting with the one currently under the cursor

    x

  • 7/31/2019 Linux Command1

    72/72

    to copy n lines:

    nyy

    For example, the following command will copy 16 lines onto the clipboard:16yy

    To past the selection, just type the letterp.

    Cutting-pasting n lines is similar by using the command:

    ndd