linux and unix commands

Upload: ajaybandi

Post on 21-Feb-2018

234 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/24/2019 Linux and Unix Commands

    1/8

    List of Linux and Unix commands

    Here is a list of Linux and Unix commandswhich will be useful for you. These commands can be used as a quick referenceto simplify your Linux or Unixusing experience. The commands are categorized into different categories dependingupon the operation of the command. Almost commands of every type are listed here. The commands are listed with theircategory , command and the operation it does. The list goes as follows..File Commands

    ls directory listing

    ls -al formatted listing with hidden files

    cd dir change directory to dir

    cd change to home

    pwd show current directory

    mkdir dir create a directory dir

    rm file delete file

    rm -r dir delete directory dir

    rm -f file force remove file

    rm -rf dir force remove directory dir

    cp file1 file2 copy file! to file"

    cp -r dir1 dir2 copy dir! to dir"# create dir" if it doesn$t exist

    mv file1 file2 rename or move file! to file" if file" is an existing directory, moves file! into directory file"

    ln -s file link create symbolic link link to file touch file create or update file

    cat > file places standard input into file

    more file output the contents of file

    head file output the first !% lines of file

    tail file output the last !% lines of file

    tail -f file output the contents of file as it grows, starting with the last !% lines

    Process ana!ement

    ps display your currently active processes

    top display all running processes

    kill pid kill process id pid

    killall proc kill all processes named proc

    "! lists stopped or background &obs# resume a stopped &ob in the background

    f! brings the most recent &ob to foreground

    f! n brings &ob n to the foreground

    File Permissions

    chmod octal file' change the permissions of file to octal, which can be found separately for user, group, and world

    by adding ( ' read )r*, " ' write )w*, ! ' execute )x*

    +xamples chmod ###' read, write, execute for all

    chmod #$$' rwx for owner, rx for group and world

    or more options, see man chmod.%%&

    ssh user'host connect to host as user

    ssh -p port user'host connect to host on port port as user

    ssh-copy-id user'host add your key to host for user to enable a keyed or passwordless login

    %earchin!

    !rep pattern files search for pattern in files

    !rep -r pattern dir search recursively for pattern in dir

    command ( !rep pattern search for pattern in the output of command

    locate file find all instances of file

    %ystem )nfo

    date show the current date and time

    cal show this month$s calendar

    uptime show current uptime

    w display who is online

    whoami *who you are logged in as

    fin!er user display information about user

    uname -a show kernel information

    cat +proc+cpuinfo cpu information cat +proc+meminfo memory information

    man command show the manual for command

  • 7/24/2019 Linux and Unix Commands

    2/8

    df *show disk usage

    du *show directory space usage

    free show memory and swap usage

    whereis app show possible locations of app

    which app show which app will be run by default

    Compression

    tar cf file,tar files create a tar named file.tar containing files tar xf file,tar extract the files from file.tar

    tar cf file,tar,! files create a tar with -zip compression

    tar xf file,tar,! extract a tar using -zip

    tar c.f file,tar,"2 create a tar with zip" compression

    tar x.f file,tar,"2 extract a tar using zip"

    !ip file compresses file and renames it to file.gz

    !ip -d file,! decompresses file.gz back to file

    /etwork

    pin! host ping host and output results

    whois domain get whois information for domain

    di! domain get /01 information for domain

    di! -x host reverse lookup host

    w!et file download file

    w!et -c file continue a stopped download

    )nstallation)nstall from source*

    ,+confi!ure

    make

    make install

    dpk! -i pk!,de" install a package )/ebian*

    rpm -Uvh pk!,rpm install a package )234*

    %hortcuts

    Ctrl0C' halts the current command

    Ctrl0' stops the current command, resume with fg in the foreground or bg in the background

    Ctrl0' log out of current session, similar to exit

    Ctrl03' erases one word in the current line

    Ctrl0U' erases the whole line

    Ctrl04' type to bring up a recent command

    55' repeats the last command

    exit' log out of current session

    Linux Commands

    mkdir - make directories5sage

    mkdir 673T8709 /82+:T72;7ptions:reate the /82+:T72;)ies*, if they do not already exist.4andatory arguments to long options are mandatory for short optionstoo.

  • 7/24/2019 Linux and Unix Commands

    3/8

    5se cd to change directories. Type cd followed by the name of a directoryto access that directory.>eep in mind that you are always in a directoryand can navigate to directories hierarchically above or below.mv- chan!e the name of a directoryType mv followed by the current name of a directory and the new name of

    the directory.+x mv testdir newnamedirpwd - print workin! directorywill show you the full path to the directory you are currently in. This isvery handy to use, especially when performing some of the othercommands on this pagermdir - 4emove an existin! directoryrm -r2emoves directories and files within the directories recursively.chown - chan!e file owner and !roup

    5sagechown 673T8709 7?0+266-275399 8@+chown 673T8709 -2753 8@+chown 673T8709

  • 7/24/2019 Linux and Unix Commands

    4/8

    5sagechmod 6

  • 7/24/2019 Linux and Unix Commands

    5/8

    :opy all files from the directory FsrcdirF to the directory FdestdirFpreserving links )

  • 7/24/2019 Linux and Unix Commands

    6/8

    .ftp hostname7pens an T3 connection to the specified host, allowing files to betransferred. The T3 program provides subcommands for accomplishingfile transfers# see the online documentation.head files - 3rints the first several lines of each specified file.ispell files - :hecks the spelling of the contents of the specified files.kill process6idskill < signal processBidskill ills the specified processes, sends the specified processes the specifiedsignal )given as a number or name*, or prints a list of available signals.killall pro!ramkillall < signal program>ills all processes that are instances of the specified program or sends the

    specified signal to all processes that are instances of the specifiedprogram.mail - @aunches a simple mail client that permits sending and receivingemail messages.man titleman section title < 3rints the specified man page.pin! host< 1ends an echo request via T:383 to the specified host. Aresponse confirms that the host is operational.re"oot

  • 7/24/2019 Linux and Unix Commands

    7/8

    File Commands

    ls directory listing

    ls -al formatted listing with hidden files

    cd dir change directory to dir

    cd change to home

    pwd show current directory

    mkdir dir create a directory dir

    rm file delete file

    rm -r dir delete directory dir

    rm -f file force remove file

    rm -rf dir force remove directory dir

    cp file1 file2 copy file! to file"

    cp -r dir1 dir2 copy dir! to dir"# create dir" if it doesn$t exist

    mv file1 file2 rename or move file! to file" if file" is an existing directory, moves file! into directory file"

    ln -s file link create symbolic link link to file

    touch file create or update file

    cat > file places standard input into file

    more file output the contents of file

    head file output the first !% lines of file

    tail file output the last !% lines of file

    tail -f file output the contents of file as it grows, starting with the last !% lines

    Process ana!ement

    ps display your currently active processes

    top display all running processes

    kill pid kill process id pid

    killall proc kill all processes named proc

    "! lists stopped or background &obs# resume a stopped &ob in the background

    f! brings the most recent &ob to foreground

    f! n brings &ob n to the foreground

    File Permissions chmod octal file' change the permissions of file to octal, which can be found separately for user, group, and world

    by adding ( ' read )r*, " ' write )w*, ! ' execute )x*

    +xamples chmod ###' read, write, execute for all

    chmod #$$' rwx for owner, rx for group and world

    or more options, see man chmod.%%&

    ssh user'host connect to host as user

    ssh -p port user'host connect to host on port port as user

    ssh-copy-id user'host add your key to host for user to enable a keyed or passwordless login

    %earchin!

    !rep pattern files search for pattern in files

    !rep -r pattern dir search recursively for pattern in dir

    command ( !rep pattern search for pattern in the output of command locate file find all instances of file

    %ystem )nfo

    date show the current date and time

    cal show this month$s calendar

    uptime show current uptime

    w display who is online

    whoami *who you are logged in as

    fin!er user display information about user

    uname -a show kernel information

    cat +proc+cpuinfo cpu information

    cat +proc+meminfo memory information

    man command show the manual for command

    df *show disk usage

    du *show directory space usage

  • 7/24/2019 Linux and Unix Commands

    8/8

    free show memory and swap usage

    whereis app show possible locations of app

    which app show which app will be run by default

    Compression

    tar cf file,tar files create a tar named file.tar containing files

    tar xf file,tar extract the files from file.tar

    tar cf file,tar,! files create a tar with -zip compression tar xf file,tar,! extract a tar using -zip

    tar c.f file,tar,"2 create a tar with zip" compression

    tar x.f file,tar,"2 extract a tar using zip"

    !ip file compresses file and renames it to file.gz

    !ip -d file,! decompresses file.gz back to file

    /etwork

    pin! host ping host and output results

    whois domain get whois information for domain

    di! domain get /01 information for domain

    di! -x host reverse lookup host

    w!et file download file

    w!et -c file continue a stopped download

    )nstallation)nstall from source*

    ,+confi!ure

    make

    make install

    dpk! -i pk!,de" install a package )/ebian*

    rpm -Uvh pk!,rpm install a package )234*

    %hortcuts

    Ctrl0C' halts the current command

    Ctrl0' stops the current command, resume with fg in the foreground or bg in the background

    Ctrl0' log out of current session, similar to exit

    Ctrl03' erases one word in the current line

    Ctrl0U' erases the whole line

    Ctrl04' type to bring up a recent command

    55' repeats the last command

    exit' log out of current session