Linux Commands NPI 1 Auto Saved]

Embed Size (px)

Citation preview

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    1/20

    Linux Commands Vijay

    Jan 12th, 2011

    Confidential

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    2/20

    Linux Basic Commands

    Linux Basic Commands: Types

    File/Directory Basics Backups and Remote StorageFile Viewing Printing

    File Creation and Editing Spelling Operations

    File Properties Processes

    File Location/Search Scheduling JobsFile Text Manipulation Hosts

    File Compression Networking

    File Comparison Audio and Video

    Disks and Filesystems

    Agenda

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    3/20

    File/Directory Basics

    ls List information about the FILEs (the current directory by default).

    Sort entries alphabetically if none of options(--sort) are givencp Copy from SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

    mv Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

    rm Remove (unlink) the FILE(s).

    ln Create links for files, allowing them to be accessed by different names.

    cd Change working directory

    pwd Print current directory name

    mkdir Create directory

    rmdir Remove an existing directory

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    4/20

    ls Syntax : ls [OPTION]... [FILE]

    ls -a Shows you all files, even files that are hidden (these files begin witha dot.)

    ls -A List all files including the hidden files. However, does not display theworking directory (.) or the parent directory (..).

    ls -l Shows you huge amounts of information (permissions, owners, size,and when last modified.)

    ls -c Use time of last modification of the i-node (file created, mode

    changed, and so forth) for sorting (-t) or printing (-l or -n).ls -C Multi-column output with entries sorted down the columns.

    Generally this is the default option.(ls normal)

    ls -x Displays files in columns.

    ls -1 Print one entry per line of output.

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    5/20

    ls command

    ls -F Mark directories with a trailing slash (/), doors with a trailinggreater-than sign (>), executable files with a trailing asterisk (*),FIFOs with a trailing vertical bar (|), symbolic links with a trailing

    at-sign (@), and AF_Unix address family sockets with a trailingequals sign (=).

    ls -g Same as -l except the owner is not printed.

    ls -i For each file, print the i-node number in the first column of thereport.

    ls -u Use time of last access instead of last modification for sorting (withthe -t option) or printing (with the -l option).

    ls -L If an argument is a symbolic link, list the file or directory the linkreferences rather than the link itself.

    ls -m Stream output format; files are listed across the page, separated bycommas.

    ls -o The same as -l, except that the group is not printed.

    ls -t Shows you the files in modification time.

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    6/20

    ls command

    ls -p Displays a slash ( / ) in front of all directories.

    ls -q Force printing of non-printable characters in file names as thecharacter question mark (?).

    ls -r Reverses the order of how the files are displayed.

    ls -R Includes the contents of subdirectories.

    ls -s Give size in blocks, including indirect blocks, for each entry.

    ls ~ List the contents of your home directory by adding a tilde after thels command

    ls / List the contents of your root directory.

    ls ../ List the contents of the parent directory.

    ls */ List the contents of all sub directories.

    ls -d */ Only list the directories in the current directory.

    http://www.computerhope.com/jargon/t/tilde.htmhttp://www.computerhope.com/jargon/r/root.htmhttp://www.computerhope.com/jargon/r/root.htmhttp://www.computerhope.com/jargon/t/tilde.htm
  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    7/20

    cp Syntax: cp [OPTION]... SOURCE... DIRECTORY

    -v, --verbose explain what is being done

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

    -u, --update copy only when the SOURCE file is newer than thedestination file or when the destination file is missing

    --no-dereference never follow symbolic links

    -f, --force if an existing destination file cannot be opened, removeit and try again

    -i, --interactive prompt before overwrite

    -H follow command-line symbolic links

    -R, -r, --recursive copy directories recursively

    -P same as '--no-dereference'

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    8/20

    mv Syntax : mv [-f] [-i] oldname newname

    -f mv will move the file(s) without prompting even if itis writing over an existing target. Note that this is

    the default if the standard input is not a terminal.-i Prompts before overwriting another file.

    oldname The oldname of the file renaming.

    newname The newname of the file renaming.

    filename The name of the file you want to move directory -The directory of were you want the file to go.

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    9/20

    rm Syntax : rm -options [filenames | directory]

    -f Remove all files (whether write-protected or not) ina directory without prompting the user. In a write-protected directory, however, files are never

    removed (whatever their permissions are), but nomessages are displayed.

    -i Interactive. With this option, rm prompts forconfirmation before removing any files. It over- ridesthe -f option and remains in effect even if thestandard input is not a terminal.

    -R Same as -r option.-r Recursively remove directories and subdirectories in

    the argument list.

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    10/20

    ln Syntax : ln [options] sourcename [destname]

    -f Link files without questioning the user, even if the

    mode of target forbids writing. This is the default ifthe standard input is not a terminal.

    -n Does not overwrite existing files.

    -s Makes it so that it does not create a symbolic link(not on System V.) existingfile - The file that youwant to create a new link.

    http://www.computerhope.com/unix/systemv.htmhttp://www.computerhope.com/unix/systemv.htm
  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    11/20

    cd Syntax : cd [directory]

    cd .. Changes the directory to parent directorycd - will switch you to the previous directory

    Cd ~ Change the directory to root directory

    Cd Change the directory to root directory

    pwd Prints present working directory

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    12/20

    mkdir mkdir [options] directories

    -m mode, --mode mode Set the access mode for new directories. See chmodfor an explanation of acceptable formats for mode.

    -p, --parents Create intervening parent directories if they don'texist.

    -v, --verbose Print a message for each directory created.--help Print help message and then exit.--version Print version number and then exit.-Z context,

    --context=context

    Set security context in SELinux.

    Ex: mkdir -m 444 personal

    mkdir -p work/junk/questions

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    13/20

    rmdir Syntax : rmdir [OPTION]... DIRECTORY...

    --ignore-fail-on-non-empty

    ignore each failure that is solely because a directoryis non-empty.

    -p, --parents Remove DIRECTORY and its ancestors. E.g., rmdir-p a/b/c' is similar to `rmdir a/b/c a/b a'.

    -v, --verbose output a diagnostic for every directory processed.

    --version output version information and exit.

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    14/20

    File Viewing commands

    cat Read (concatenate) one or more files and print them on standardoutput.

    less less is a program for paging through files or other output.

    head Print the first few lines (default is 10) of one or more files.

    tail Print the last 10 lines of each named file on standard output.

    nl number lines of files

    tac Named for the common command cat, tac prints files in reverseto standard output.

    more Display the named files on a terminal, one screenful at a time.

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    15/20

    Cat Syntax : cat filename -option

    filename The name of the file or files that you wish to look ator perform tasks on.

    -n Precede each line output with its line number.

    -b Number the lines, as -n, but omit the line numbersfrom blank lines.

    -v Non-printing characters are printed visibly. ASCII controlcharacters (octal 000 - 037) are printed as ^n, where n is thecorresponding ASCII character in the range octal 100 - 137 (@, A, B,C, . . ., X, Y, Z, [, \, ], ^, and _); the DEL character (octal 0177) is

    printed ^?. Other non-printable characters are printed as M-x, where xis the ASCII character specified by the low order seven bits.

    -e A $ character will be printed at the end of each line(prior to the new-line).

    -t Tabs will be printed as Is

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    16/20

    Head Syntax : head [-number | -n number] file.log

    -n number The number of lines you want to display.

    -c num[b|k|m] Print first num bytes or, if num is followed by b, k, orm, first num 512-byte blocks, 1-kilobyte blocks, or 1-megabyte blocks

    -v Print filename headers, even for only one file.

    -q, Quiet mode; never print headers giving filenames.

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    17/20

    Tail Syntax : tail -options [file]

    -n num Print the last num lines.

    -v With multiple files, always output the filenameheaders.

    -q Suppress filename headers.

    -c num[b|k|m] Print last num bytes or, if num is followed by b, k, orm, first num 512-byte blocks, 1-kilobyte blocks, or1-megabyte blocks

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    18/20

    more Syntax : more [options] [files]

    +num Begin displaying at line number num.

    -number Set screen size to number lines.

    -d Display the prompt "[Press space to continue, q' toquit] " instead of ringing the bell

    -f Count logical rather than screen lines. Useful whenlong lines wrap past the width of the screen.

    SPACE Display next screen of text.

    z Display next num lines of text, and redefine a

    screenful to num lines. Default is one screenful.s Skip next num lines of text. Default is one line.

    /pattern Search for pattern, skipping to numth occurrence ifan argument is specified.

    n Repeat last search, skipping to numth occurrence ifan argument is specified.

    !cmd Invoke shell and execute cmd in it.

    . Re-execute previous command.

  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    19/20

    less less [options] [filename]

    Less is a program similar to more (1), but which allows backward movement in the file aswell as forward movement. Also, less does not have to read the entire input file beforestarting, so with large input files it starts up faster than text editors like vi (1).

    -g Highlights just the current match of any searched

    string.-I Case-insensitive searches.

    -M Shows more detailed prompt, including file position.

    -N Shows line numbers (viewing for source code)

    -b Previous page.

    n/N Go to next match/Go to previous match.

    g/G Go to start of file. / Go to end of file.

    ng Jump to line number n. Default is the start of thefile.

    nG Jump to line number n. Default is the end of the file.

    http://en.wikipedia.org/wiki/Source_codehttp://en.wikipedia.org/wiki/Source_code
  • 8/3/2019 Linux Commands NPI 1 Auto Saved]

    20/20

    tac Syntax : tac [options] [file]

    Named for the common command cat, tac prints files in reverse to standard output.Without a filename or with -, it reads from standard input. By default, tac reverses the

    order of the lines, printing the last line first.

    nl Syntax : nl filename

    nl copies each specified file to the standard output, with line numbers added to the lines.The line number is reset to 1 at the top of each logical page. nl treats all of the input files

    as a single document and does not reset line numbers or logical pages between files.