UNIX cheat

Hostname: naic.nasa.gov
Directory path: files/general_info/
Filename: unix-cheat.txt
Updated: July 13, 1993 (mks)


The following started as a UNIX cheat sheet for VMSers.  It quickly
grew into a list of very useful UNIX commands, their VMS counterparts
if they exist, and an example or two.  It is in no way complete.  Many
less useful unix commands have been excluded, as have most command
parameters.


Unix cmd   VMS Counterpart or explanation
--------   ------------------------------


alias      $SHOW SYMBOLS/GLOBAL/ALL  This can also be used to show an
           individual symbol eg:
              UNIX> alias when
              time
              UNIX>
           
            In this example, the symbol "when" is equated to the command "time"

            It can also be used to set a symbol eg
              UNIX> alias dir ls
            In this example, "dir" is set up to be equivalent to the command
            "ls"

at          $RUN/DETACH/AFTER= (execute a command at a later time)
            eg  UNIX> at 23 blow
                run commands in file "blow" at 23:00

awk        pattern scanner.  Can be used as a single line command or
           as a complete programming language.  Altho it's more complex
           then VMS lexicals, it can ultimately perform the same functions
           as f$extract,f$locate etc.

biff n      $SET BROADCAST=NOMAIL  (Turn off mail notification messages.)
            Use "y" to turn back on.  Without argument, it will tell you
            how many mail messages you have.  Xbif opens an xwindow that
            will notify you upon receipt of newmail

cal        types a calendar for this month

cat         $TYPE
             eg UNIX> cat sears.roebuck  = $TYPE SEARS.ROEBUCK

cd          $SET DEF.  If you don't pass it a param, you'll end up in your root
             ie sys$login eg
                 UNIX> cd /usr/bin  = $SET DEF [USR.BIN]

chmod       $SET PROTECTION 
               eg UNIX> chmod g+w *.c   =     $SET PROT=(G:W) *.C

clear       $TYPE/PAGE NL:  clear screen

comm        find lines common to two or more files

cmp         $DIFF  (compare files but stops at first occurance of a difference)

cp          $COPY
               eg
              UNIX> cp file.xx save-file.old  = $COPY FILE.XX SAVE-FILE.OLD

csh         just like the "@" command on VMS for running a comfile
               eg UNIX> csh accounting   =  $ @ACCOUNTING.COM

date        $SHOW TIME

diff        $DIFFERENCES  show differences of two files

df          $SHOW DEVICE D/MOUNT  ie shows which disks are mounted.  Bear
            in mind that this show bytes. (VMS always shows disk blocks
            ie bytes * 512)

du          $DIR/SIZE [...] ie show disk usage.  NB, shown in blocks.

echo        $WRITE SYS$OUTPUT.  To type out a variable, precede with a dollar
                eg UNIX> echo "hello"   = $WRITE SYS$OUTPUT "HELLO"

                eg set x=10
                   echo $x
                   10
                In this example, a variable is assigned and then typed out
                using echo.  Note that it must be precede by a $ to indicate
                that it should not be taken as a literal (Without the $, echo
                will print "x")

ed         $EDIT/SOS (line editor)

egrep      $SEARCH file string  Search file(s) for occurances of a string,
           The order is reversed from VMS.  This command is the same as grep
           but you may use special characters eg ^ indicates beginning of
           line eg.
              UNIX> egrep ^if .login
               This example searchs for "if" at the beginning of a line only
               within the file .login.
               

expr       expression. May be used for calculating values
           You must precede unusual characters (otherwise meaningful
           to UNIX) with a backslash

              eg UNIX> expr 5+6  = $ WRITE SYS$OUTPUT 5+6
                 UNIX> expr 5 \*6 = $ WRITE SYS$OUTPUT 5*6

file        Explain what type of file it is
              eg UNIX> file Mail
                 Mail:    directory

find        $DIR [...]FILE   find a file
                eg UNIX> find / -name yowza -print
                   This will search the entire disk (from / all the way down)
                   for a file named YOWZA and print where it is

finger      FINGER a high powered SHOW USERS/FULL and SHOW SYSTEM

grep        $SEARCH. The arguments are reversed from the VMS order
              eg UNIX> grep host  .login = $SEARCH .LOGIN HOST

history     $RECALL/ALL

head        $TYPE/PAGE  types the beginning of a file

hostname    $WRITE SYS$OUTPUT F$GETSYI("NODENAME") returns your machine name

jobs        $SHOW QUE list all jobs

kill        $STOP/ID  Must be followed by the process id of the job to
            be killed

lp          $PRINT
              eg UNIX> lpr myfile.txt   =  $ PRINT MYFILE.TXT

lprm        $DEL/ENTRY=... SYS$PRINT (remove a print job from a que)
lpq         $SHOW QUE SYS$PRINT (show print ques)
lpstat      $SHOW QUE SYS$PRINt (show print ques)
lpstat -t   $SHOW QUE/DEV/FULL/ALL  (show verbosely all print ques)

ls          $DIR/BRIEF
ls -l       $DIR/PROTECTION
ls -L       $DIR/FULL
ls -ltr     $DIR/SIZE/DATE
ls -ltR     $DIR/SIZE/DATE [...]

mail        $MAIL

elm         a much more friendly mail utility

mesg n      $SET BROADCAST=NONE  (Turn off all messages.) Use "y" to turn
            back on.  Without argument, it will tell you whether or not
            messages are enabled       NB. this works for talk/write class
            messages. To turn off mail notification, see biff

man         $HELP
              eg UNIX> man ls    =  $ HELP LS

mkdir       $CREATE/DIR

more        a high-powered TYPE/PAGE utility

mv          $RENAME
                eg UNIX> mv 1.dat newfile.test  = $RENAME 1.DAT NEWFILE.TEST

passwd      $SET PASSWORD

printenv    $SH PROC/FULL

set         Sorta like SHOW PROCESS.  Like many UNIX commands  without a
            parameter it shows you current settings, with a parameter you
            can change such settings.

setenv      Sets various things within your environment. It can be used to
            set the equivalent of a VMS logical:

            UNIX> setenv dfile /usr/bin/data
                              $DEF/TRANSLATION=CONCEAL DFILE [USR.BIN.DATA.]
            UNIX> ls $dfile/*.dat      $DIR DFILE:*.DAT

            The above example creates what I'll call a "nickname" in both
            environments for that long directory or pathname. Note that in
            UNIX, every time you refer to it, you must precede is with a $
            to indicate it's not a literal but must be interpretted.

set filec   when enabled will make a best-guess at filename you're trying
            to type.  Enter this command then, as an example, enter ls
            followed by the beginning of a filename.  Hit <ESC>. The
            machine will COMPLETE the filename for you!  In fact, if there's
            a conflict (two files similarly named, it will add to what you've
            already typed and stop where uniqueness would begin.  Create
            a .login and .logout file and see what happens when you ls .l <esc>

set history Adjust the size of the recall buffer.  VMS has this hardcode to
            20.


set path    Tells your process where (which directories) to look for commands.
            analogous to making non-native mode VMS commands native eg

            UNIX> set path /usr/bin    =   $NCP:==$MCR NCP
            UNIX> ncp                      $NCP
            NCP>                           NCP>

            In this example, your process is told where to find NCP st
            by entering the command "ncp" one gets into then NCP
            utility (rather than having to enter /usr/bin/ncp or
            $RUN SYS$SYSTEM:NCP each time)

set prompt  $ SET PROMPT="...."

sort        SORT.  Again, the order of parameters is the opposite of in
            VMS.  ie sort output input

ps          $SH SYS (only your processes)
ps aux      $SH SYS (just like ps but shows all processes)

pwd         $SHOW DEFAULT (print working dir)

rm          $DELETE
rmdir       delete a directory

stty        $SHOW TERM or $SET TERM if used with a parameter
            stty all    and    stty everything   will give you a more
            verbose response

stty all    list your current settings. There's an even more verbose command,
            stty everything.  These will list special control characters eg
            ^U will erase to the beginning of the current word you are typing
            if you've made a mistake.

tail        type the end of a file

talk        $TALK talk to a user online (like reply/request or phone but
            meant for talking between different machines)

tar         $BACKUP

tty         a brief $SHOW TERM (only the terminal name)

uptime      display system uptime (since last reboot)

users       $ SHOW USERS

vi          full screen editor (like $EDT)

view        $EDIT/READONLY using the vi editor

w           $SHOW USER/FULL

wc          word count
              eg UNIX> wc file.dat
                 25    48    419     file.dat 
                 The above example returns the following information
                 the file FILE.DAT has 25 line, 48 words and 419 characters

whatis      a brief online help.  Follow it with an unknown command name
            and it will describe what the command does
             eg UNIX> whatis cmp
                cmp (1)     - perform a byte-by-byte comparison of two files

whereis     locate the binary, source and manual pages for a command

which       locate a command. Display its path or alias
            eg UNIX> which nn
               /usr/local/bin/nn

who         $SHOW USERS (not as verbose as "w")

whoami      sh your username

write       like talk.
            eg write stern
               Hey Dave, wanna do lunch?
               ^D
             In this example someone wrote to stern, enter one sentence then
             exitted using <CTRL> D.

special characters and syntaxes

./                []
../               [-] 
../test           [-.test]  ie up and over :up one level and back down to test
~/file.ext        sys$login:file.ext

^                 beginning of line
                    eg grep

$                 End of line or Indicate a variable (depends on context)

*                 wild card. exactly like VMS.

?                %   used to indicate a single character
                      eg ls ?a.txt    =     dir %a.txt
                         (list all files with a single character before "a.txt")

[a-d,xy]        Used to indicate a choice of characters.  In this example
                matches will include anything with the letters a,b,c,d,x,y
                An example of usage could be ls a[a-d,xy]*.txt

>                /output= 
                 eg ls > tmp       =       dir/output=temp

>>               Append the output to an existing file.  See above

^D               control-D is like EOF (end of file), EOD (end of deck) in
                 VMS.  <CTRL> D upon receiving the login prompt is analogous
                 to <CTRL>Z on VMS  ie ignore input and return me to original
                 host

!!               recall (recall last command)

&                 spawn ie put a job in the background.  You can re-attach
                  to it using the fg (foreground) command

                   eg. ls -ltR > temp &   = spawn/nowait dir [...]/out=temp



Comments

Popular posts from this blog

BOTTOM LIVE script

Evidence supporting quantum information processing in animals

ARMIES OF CHAOS