Saturday

Unix Commands Quick Reference

  • cat filename1 > filename2 :
    This overwrite contents of filename2 with filename1
  • cat filename1 » filename2 :
    This appends contents of filename1 to filename2.
  • cd /usr:
    Changes current directory to /usr directory
  • cd .. :
    Change current directory to previous higher directory.
  • cd :
    Change to home of current userid.
  • chgrp group1 filename1 :
    Change group id to group 1 for filename1.
  • chgrp -R group1 * :
    Changes group id of all files in current and subdirectories to group 1.
  • chmod ugo+rwx filename1:
    Add read/write/execute permission to filename1 for user/owner, group and others (world).
  • chmod o x filename1 :
    Remove execute from others (world)
  • chmod 751 filename1 :
    Set rwx for user/owner, group and others; r=4, w=2, x=1, rwx=7 rx=5, rw=6, wx=3, none=0.
  • chown sam filename1 :
    Change owner of file filename1 to sam.
  • chown -R sam * :
    Change owner to sam for all files in current and subdirectories.
  • clear :
    Clear the terminal screen.
  • compress filename1 :
    Compress file filename1 and replace it with filename1.Z
  • cp filename1 filename2 :
    Copy file filename1 to filename2 destroying the contents of filename2.
  • cp -i * /usr/local/bin :
    Copy all files in current directory to /usr/local/bin directory; Prompt before overwriting files (i)
  • cpio :
    Copy file archives to disk/tape
  • crontab -e :
    Edit crontab file for current user
  • crontab -e bill :
    Edit crontab file for user bill
  • crontab -l :
    List crontab entries for current userid
  • csh :
    Start the c shell process
  • cut -d:
    -f1,5 /etc/passwd
    :
    Extract the 1st and 5th fields (username & real name) from file /etc/passwd where delimiter is colon
  • who | cut -d" " -f1:
    List login names from who command
  • date :
    Display current date string
  • date +%D :
    Display current date, MM/DD/YY format
  • dd :
    Copy file(s) to/from raw devices
  • df :
    Displays free disk blocks and modes on file systems.
  • df -k :
    Displays free space in kilobytes for mounted file systems
  • echo name :
    Displays literal "name" on screen
  • echo $PATH :
    Displays PATH environment variable
  • ed/edit/ex :
    Alternative line editors, see vi
  • env Displays current environment variables or allows setting
  • file filename1 :
    Determines and displays type of file for filename1 (text, data, executable, directory, symbolic link...etc...)
  • find /usr/opt/bin -name "filename1*" -print :
    Starts searching in /usr/opt/bin for files starting with
  • filename1, If found prints the full file names and continues searching subdirectories
  • find . -type f -print | xargs grep -i [PATTERN] :
    Recursive grep for a pattern in a file (searches through files in subdirectories)
  • find . ! -mtime - | /usr/bin/xargs rm -rf :
    Finds and removes files older than specified
  • finger sam :
    Displays data about user session for sam
  • ftp solar :
    Establishes a File Transfer Protocol session over the network between current host and a host named solar; See man pages for additional ftp commands
  • grep jdoe /etc/passwd :
    Searches the file /etc/passwd searching for string "jdoe"; If found, displays
  • grep -i Sam filename1:
    Search filename1 for upper or lower case string of Sam and display lines found
  • groups sam :
    List groups that sam is a member of
  • head filename1 :
    Display first few lines of filename1
  • head -50 filename1:
    Display first fifty lines of filename1
  • id :
    List current user id and any group ids
  • kill -9 1351 :
    Terminate process number 1351
  • ksh:
    Start Korn Shell command interpreter; See man pages; Preferred shell for most users
  • ln -s filename1 /usr/opt/filename2 :
    Create a symbolic link named /usr/opt/filename2 that points to filename1; See man pages
  • lp -d lp1 filename1 :
    Print filename1 on destination printer lp1
  • lpstat -d :
    Displays name of default printer, if any
  • lpstat -a :
    Lists printers accepting print requests
  • lpstat -s :
    Displays most everything regarding printing
  • lpstat -u sam :
    Displays status of sam's print jobs
  • ls -al :
    Displays all files in wide listing
  • ls -al *.doc :
    Displays files ending with .doc
  • ls -al /bin/k*:
    Displays files starting with k in /bin directory
  • man --is Online UNIX manual:
  • man-pages:
    It gives detailed instructions on all of the commands listed here and a lot more.See man man for more...
  • mail sam :
    Starts mail message to sam
  • mailx sam :
    Nicer looking mail utility
  • mkdir -p /usr/opt/dirx:
    Creates dirx below /usr/opt
  • make:
    Code compilation utility
  • mkdir dirx:
    Creates directory dirx
  • more filename1 :
    Displays single pages from filename1 pausing after each page.for many options see man pages
  • mv filename1 /usr/opt/ :
    Moves filename1 to directory /usr/opt; Unlike the cp (copy) command, mv removes file from origin
  • netstat -i:
    Show the TCP/IP network interfaces
  • netstat -r:
    Show network route table
  • netstat -rn:
    Displays routing information but bypasses hostname lookup
  • netstat -a | more :
    Show the state of all sockets
  • newgrp group1 :
    Changes current group to group 1
  • news :
    Displays unread files from /usr/news or /var/news
  • nice/renice :
    Adjusts process’ execution priority
  • Unix Commands from p to z:
  • passwd:
    Allows changing your login password
  • ps :
    Lists all of current user's live processes
  • ps -ef :
    List all users processes that are executing
  • pwd:
    Displays current working directory you are in
  • rcp filename1 hostb:
    /usr/local/bin
    :
    Copies filename1 from current host system to hostb, and places it in the /usr/local/bin directory; The .rhosts or hosts.equiv files must be setup to allow action
  • rksh:
    Starts restricted Korn Shell session
  • rlogin hostb :
    Logs into remote host name hostb
  • rm filename1 :
    Deletes filename1 from the disk without recourse
  • rm -i filename1 :
    Deletes filename1 after prompting for verification
  • rmdir dirx :
    Deletes directory dirx
  • rmdir -r dirx:
    Deletes directory and all contents
  • rsh:
    Restricted version of Bourne Shell for security
  • sar :
    System Activity Reporter
  • sh :
    Bourne Shell command interpreter; Alternative to Korn Shell and C shell but is the default on most systems; Older version that is losing popularity
  • sleep 3 :
    Pauses for 3 seconds and continues
  • stty sane:
    Attempts to restore terminal settings after they are hosed; Use CTRL-J with this command
  • stty erase ^H :
    Use to reset backspace/delete; ^H is the key you may want to use for backspace/delete;
  • su sam:
    Log on as user sam
  • su - sam:
    Log on as sam, and execute his profile too
  • tail filename1 :
    Display last few lines of filename1
  • tail -50 filename1 :
    Display last fifty lines of filename1
  • tail -f :
    Continually reads updating file; Great for monitoring a log file while being written
  • tar -cvf /dev/rmt/0c /usr/bin/* :
    Tape archive utility; Copies all files in /usr/bin directory to tape device /dev/rmt/
  • tar -xvf /dev/rmt/0 /usr/bin/ :
    Extracts all files from tape device /dev/rmt/0 and writes them to /usr/bin/
  • tar -tvf /dev/rmt/0c :
    Read tape on device /dev/rmt/0c and lists contents in verbose mode
  • tee:
    Used in scripts to split output to two outputs. Usually used with a pipe command (|)
  • tee -a /tmp/filename1:
    Append the output to filename1 without overwriting its original content
  • telnet hostb:
    Create a remote terminal on hostb
  • touch filename1 :
    Creates an empty file named filename1; Changes modification time to current time if the file already exists
  • uname -a:
    Lists 0/S revision, host name, hardware
  • uncompress filename1 :
    Uncompresses file with .Zsuffix, created by compress command previously
  • uptime :
    Displays current time, time logged-in,number of users etc
  • users:
    Displays current logged-in users in a listing
  • uucp :
    UNIX-to-UNIX copy utility; See man pages
  • view filename1:
    A read only version of vi editor
  • w :
    Combination of uptime, who and ps -a commands
  • wall :
    Write to all; Allows entry of message to be sent to line 25 of all terminals; End message with a CTRLD command
  • wc -l filename1:
    Utility that counts the number of lines in filename1
  • wc -c filename1 :
    Utility that counts the number of bytes in filename1; -m provides number of characters
  • wc -w filename1 :
    Utility that counts the number of the words in filename1
  • whence filename2:
    Prints path name location of executable filename2
  • which filename2 :
    Similar to whence command
  • who Displays login name, terminal name, date, and time of login, of users currently logged in
  • who am i :
    Displays effective user id of user
  • who -b :
    Displays date/time of last reboot
  • who -r :
    Displays current system run level