Unix Shortcuts

Embed Size (px)

Citation preview

  • 8/10/2019 Unix Shortcuts

    1/16

    Keystrokes

    Ctrl-cStops a command or program that is currently being executed.

    Ctrl-dRemoves you from the current environment, this will log you out of the system if

    you are at a shell prompt.

    Ctrl-h, DelDeletes the last character typed and moves back one space. nlike D!S, the

    backspace key does not work"

    Ctrl-#Resumes the command that was halted by Ctrl-s.

    Ctrl-s$emporarily halts the current command being executed, e.g. scrolling of text on

    the screen.

    Ctrl-u, Ctrl-x, %Cancels what you have &ust typed, so that you can start again.

    Ctrl-xDeletes the current line of text being entered.

    Directory Commands

    cdStands for change directory

    df -kStands for disk free, gives you the amount of space available on the disk that you

    are currently on.

    mkdir'eans (make directory(, e.g.

    mkdir usercreates a directory called user in the directory you are in when you issue the

    command.

    pwdStands for print working directory and prints the directory that you are in to the

    screen.

  • 8/10/2019 Unix Shortcuts

    2/16

    rmdir'eans remove directory e.g.

    rmdir userremoves the directory user provided that it is empty"

    System Commands

    -)sing this switch after a command causes it to operate in the background,

    allowing you to continue using the same command line window without having to openanother one.

    *

    $his wildcard character matches any number of characters and is useful in searches, e.g.g*matches all files beginning with (g(.

    +

    $his wildcard character matches any single character, e.g.g++

    matches all three character files beginning with (g(.

    Redirect output from a program to a file, e.g.ls -l listingredirects the listing of ls -l into a file called (listing(.

    Redirect output from a file into a program, e.g.mail &ohn helloredirects the greeting letter called (hello( to ohn, rather than you having to type it.

  • 8/10/2019 Unix Shortcuts

    3/16

    /

    0ipe output from one program to another, e.g.who / wc -l

    gives a count of the users on the system.

    $his append adds the input to an existing file without overwriting the original, e.g.postcript letteradds the contents of (postscript( to an existing file called (letter(.

    chsh

    'eans change shell and changes the shell that the user is using. $he user will beprompted for a password since the (passwd( file is being changed, then the user will needto type the path to the shell e.g. 1bin1bash.

    echo

    $his (echoes( arguments to the screen, e.g.echo 2S3455displays the value of the environment variable S3455. $his could return 1bin1tcsh 65inuxoften uses this shell7 or 1bin1bash. echo 208$3 displays the current path.

    env

    $he environment gives you the variables set up for the particular user that issues thecommand.

    exit, Ctrl-d

    5ogs you out.

  • 8/10/2019 Unix Shortcuts

    4/16

    &obs

    $his lists the &obs running under the current shell in (&ob 9D( order. :ou can type bg;&obid to put a particular &ob running in the background. Ctrl < also suspends a &ob.

    $yping fg ;&obid brings the &ob back to the foreground.

    kill

    $his kills a process e.g.kill =>?@kill the process which has been given the temporary number =>?@. $his process numberis found by using the ps command. Do not use kill > as this kills the system scheduler" 9fa process refuses to die you can type kill -A955 B09D to stop a process immediately

    without any tidying up on exitting. inally, kill -30 B09D tells the process that an eventhas occurred, or a configuration file change has occurred and needs to br reread.

    man

    $he manual command is very useful for finding out comprehensive information on anindividual command e.g.man cdgives all the information on the command cd. $yping man -k mail lists the nixcommands that relate to the word mail.

    passwd

    8llows you or the administrator to change passwords.

    printenv

    $he (prints the environment( variables to the screen.

    ps

  • 8/10/2019 Unix Shortcuts

    5/16

    $he process status command shows the programs currently running. ps -a shows all theprocesses being run by all users. 8n example is the followingEps -ef / grep erpcdwhere (-ef( gets the process number and pipes it to grep which filters on the followingword, in this case for the program (erpcd(.

    $he following information is shownE09D 0rocess 9D.$$: 4ach shell opened has a (character special( called a (tty( 6held in (1dev(7.S$8$ State, either (S(, sleeping, or (R(, running.$9'4 C0 time that the process is taking up.C!''8FD $he command running.$yping ps x shows all the processes relating to G windows, whereas ps ax shows all theprocesses being run by everybody. $yping ps ux gives even more information such as theuser.

    setenv

    $he command set environment variable, sets aside a small amount of memory to holdpaths etc. e.g.setenv H9 1usr1utility1guiIrJsets a variable (H9( with the path that follows to the actual program. $his program cannow be run by typing (H9(.setenv D9S058: EK.Ksets an G window session locally.$hese settings are commonly setup permanently in the user(s .profile 6located in the (1etc(directory7. $his can be edited with any text editor.

    $he following are common environment variablesES3455 $he current shell.3!'4 $he current user(s home directory.3!S$F8'4 $he name of the computer.D9S058: $he G display that the applications are to use.5DI59LR8R:I08$3 $he search path for libraries.08$3 $he search path for applications.9f you wish to append directories to the path then type setenv 08$3 2M08$3N E1search1here. 9n order to use it then you need to cache the new path by typing rehash.

    $he D9S058: variable is made up of three parts (hostname E displaynumber Escreennumber(. $he hostname is the computer, whilst the other variables are (K( unless

  • 8/10/2019 Unix Shortcuts

    6/16

    several machines are connected. G windows looks to this variable to find out where tosend the G Oindows traffic.

    set path

    Sets a path where regularly used programs or data are found e.g.set pathP62path 1usr1utility1guiIrJ1bin7sets the path (1usr1utility1guiIrJ1bin(.

    Some commands used to set the environment come from the C shell. 9n order to checkwhich shell you are running type echo 2S3455, if this does not return (1sbin1csh( thenyou type 1bin1csh.

    su

    $he command switch user switches the login user to another user, e.g.su rootswitches to the (root( login.

    top

    Hives a constantly updating view of the top QK processes 6a real time version of (ps(7, i.e.those that are using the C0 the most.

    who

    $his displays the users currently logged on the system.

    whoami

    Displays who you are currently logged on as. 6e.g. (root(, a user etc.7

    xhost

  • 8/10/2019 Unix Shortcuts

    7/16

  • 8/10/2019 Unix Shortcuts

    8/16

    not set is given binary K. Read permission is (J(, write permission is (Q(, executepermission is (>( and no permissions is given with (K(.chmod ?KK dirname results in drwx------ for the directory which restricts access toeveryone bar the owner.chmod J filename gives -rw-rw-r-- that allows you and your group to read and edit the

    file but all others can only read the file.chmod KK filename gives -rwx------ creates a private file that only you can see and edit.:ou can change permissions for groups of files with one command by using wildcardssuch as *.

    chown

    se this to change ownership of a file e.g.chown dave myfile

    changes the ownership of the file (myfile( to dave. $his can only be carried out by theowner of the original file. 8 way around this is for the recipient to copy the file, then thecopied file becomes their own.

    chgrp

    se this to change group ownership of a file.

    compress

    $his compresses a file e.g.compress myfileresults in a file called (myfile.copies the file (bankletter( from the directory that you are currently in, to the (1user1dave(directory with a new name (bankletter>(.

  • 8/10/2019 Unix Shortcuts

    9/16

    file

    $his returns information on the content of a file, e.g.file myletter

    might return (8SC99( to say that nix guesses that (myletter( contains 8SC99.

    find

    $his finds a file or directory, e.g.find 1 -name na -print )this finds a file with name (na( starting the search from the (root( and printing the result tothe shell window, whilst still allowing you to carry on using it.

    grep

    $his stands for global regular expression and print and is a search utility, e.g.grep T@Q= UictoryTsearches the current directory for files containing the text (@Q= Uictory(.

    gVip

    HF Vip compresses files to create a (**.gV( file.

    head

    $his command followed by a filename, displays the first ten lines of that file.

    less

    $his is a way of displaying a file, it will give a percentage of file so far displayed at thebottom of the screen, and you can progress through reading the file by pressing the spacebar.

    ln

  • 8/10/2019 Unix Shortcuts

    10/16

  • 8/10/2019 Unix Shortcuts

    11/16

  • 8/10/2019 Unix Shortcuts

    12/16

    $his means the tail end, this dynamically displays the file that is being written to in realtime, e.g.tail -f logfileshows the file (logfile( which is being written to.

    tar

    $he command tape archive is an file archiving command. 9t creates a singleuncompressed archive file from several, ideal for sending data over networks. !ften filesare archived, and then compressed using (gVip(. 4.g.tar -tvf tarfiledisplays the contents of a tarfile.tar -xvf tarfileextracts the contents of a tarfile. (x( is extract, (v( means (verbose( and (f( means the file.

    tar -xvf tarfile targetextracts the file target from the tarfile.

    touch

    $his &ust creates an empty file for appending to later on e.g.touch logcreates an empty file called (log( that needs to be available for another program to write toit perhaps.

    uncompress

    $his command uncompresses a (gVip( file, e.g.uncompress myfile.gVuncompresses the file (myfile.gV(.

    wc

    $he command word count counts the words in a particular file, e.g.wc lettercounts the number of words in the file (letter(

    Simple Scripting

  • 8/10/2019 Unix Shortcuts

    13/16

    8 nix script is the e#uivalent of the D!S batch file. sing vi, the following could betyped into a file called (newIscript(Eecho $hese users are on the system

    whoecho 3ere is a detailed listing of the directory you are inls -al

    $he command chmod ux newIscript makes the script file executable by the logged inuser.

    Fetworking Commands

    arp

    Displays the (8ddress Resolution 0rotocol( table e.g.arp -adisplays all arp entries for all connected devices.arp -ddeletes the arp entry for that particular 90 address.

    ftp

    $he command file transfer protocol attaches you to another 90 device e.g.ftp >J>.QK=.>=.>=Jattaches you to the device with address >J>.QK=.>=.>=J. :ou are normally presented witha login and password screen.

    Commands that are used in $0 areEdir - directory listing.#uit - #uit from ftp.cd - change directory.get or mget - get a file 6or multiple files7.put or mput - put a file 6or multiple files7.bin - sets up your system to receive binary files.hash - displays hashes whilst files are being transferred.lcd - local change directory changes the directory on your local machine to which you aresending and receiving files. $his is useful as it saves you having to #uit ftp to carry outthe directory change.

  • 8/10/2019 Unix Shortcuts

    14/16

    $he 3osts file can be found in the directory (1etc(.

    netstat

    $his stands for network statistics, e.g.netstat -rdisplays the routing table of the nix box.netstat -adisplays alll network information.

    nix uses routed to listen to R90 in order to discover the Default Hateway.

    ping

    0ing an 90 device e.g.ping >J>.QK=.=>.Q

    rlogin

    $his works like telnet, e.g.rlogin >J>.QK=.=Q.>takes you to another nix machine only. $o #uit you press (return(, (W(, .( and (return(again.

    telnet

    Ctrl- and then Ctrl- gets you to the telnet prompt where typing close gets you out oftelnet.

    vstat

    $his displays C0 utilisation and gives a list of processes and their share of C0utilisation, e.g.vstat >K

  • 8/10/2019 Unix Shortcuts

    15/16

    displays the C0 utilisation every >K seconds.

    ifconfig

    $his displays the 90 configuration of the box, e.g.ifconfig -a

    displays all 90 configuration.

    9f you want to look at the routing process you can typeEps -ef type grep routed

    to send the (routed( information to a file.

    snoop

    $his command captures the network packets in a readable format, e.g.snoop -p Q@

    captures all 90 traffic using port Q@ 6$elnet7. use Ctrl-C to stop the snoop.

    seful vi commands

    4ach command needs to be preceded by pressing the escape key"

    i insert mode.esc leave insert mode and go into command mode.a append characters to the end of the line.o open a line below your cursor.! open a line above.shiftg go to the bottom of the file.r replace the letter that you are on with the one you type next.x erase the character that you are on.dd delete the line that you are on. 8 number before dd deletes that number of lines.yy copy the line you are on. 8 number before yy copies that number of lines.p paste the line you are on below you.0 paste the line you are on above you.Ew# write and #uit the file that you are editing.Ew#" write and #uit the file that you are editing, even if it is designated as read only"

  • 8/10/2019 Unix Shortcuts

    16/16

    Ew" write to a read only file.E# #uit.E#" discard any editing and #uit.1 this takes you to the bottom of the window where you can type a string and return toperform a search in the file.

    6$he character " is often referred to as pling7

    :ou can use vedit which is vi with more user friendly additions and also ed, or emacs.