This document provides a summary of basic Unix commands for directories, files, permissions, editing, compression, scripting, and more. Some key commands include:
- mkdir to create directories
- ls to list files in a directory
- mv to move or rename files
- cp to copy files
- rm to delete files
- chmod to set file permissions
- vi, emacs, or pico for text editing
- gzip or zip to compress files
- tar to archive groups of files
- ps to view running processes
- kill to terminate running processes
- sh, csh, ksh for scripting
This document provides a summary of basic Unix commands for directories, files, permissions, editing, compression, scripting, and more. Some key commands include:
- mkdir to create directories
- ls to list files in a directory
- mv to move or rename files
- cp to copy files
- rm to delete files
- chmod to set file permissions
- vi, emacs, or pico for text editing
- gzip or zip to compress files
- tar to archive groups of files
- ps to view running processes
- kill to terminate running processes
- sh, csh, ksh for scripting
mkdir directory-name make a new directory Viewing File Contents
rmdir directory-name remove a directory (must page filename go through file one page at a time be empty of all files) less filename page through file with capability cd directory-name change to a directory to go backwards cd change to your home directory cd .. change to directory one level up head options filename view the first few lines tail options filename view the last few lines ~ home directory . current directory .. directory one level back Printing Getting Started / entire filesystem root To select a new printer: UNIX commands are used while connected LPDEST printername directly to bama through an SSH or terminal export LPDEST interface. Our recommended programs include Working With Files lp option filename print file SSH Security Shell, TeraTerm with SSH, and ls options filename list files in a directory cancel printjob cancel print job in queue. Get Macintosh Terminal. More information is available online at ncs.ua.edu. Options for ls include: printjob name from lp command result -a show all files including hidden ones enscript options filename format file for Commands are entered by giving the command (those beginning with a “.”) PostScript printer name, any desired options, then any filenames or -l long list showing ownership, permission lpstat –p printername check printer queue. Use directory names all separated by spaces. When and links printername “all” to see full list. “enter” is pressed, the command is processed by -t time-ordered list bama. -F mark directories with “/”, links with “@” UNIX is case sensitive. All UNIX commands are and executables with “*” Other Useful Commands lower-case. Type commands demonstrated on mv options filename new-filename rename a file clear clear the screen this reference card exactly as shown. File and mv options filename directory-name pine text-based email program directory names can be mixed-case but always move file to a new directory date current date and time must be typed exactly as named. mv options directory-name new-directory-name script keep a record of terminal session For complete lists of options use the “man” move a directory and all of its contents to a quota -v show disk space usage and quota command. new directory, keeping the structure intact. cat file1 >> file2 append file1 to file2. New directory must already exist. ispell options filename spell-check cp options filename new-filename copy file grep string filename search for string in filename rm options filename delete file wc options filename count lines, words, and The most useful option for mv, cp, and rm is -i. characters This will cause command to verify (inquire) filep options filename print a file w/ formatting before execution. Compressing and Archiving Editing compress (uncompress) options filename(s) compress (uncompress) using LZ algorithm. vi options filename standard (vi)sual editor emacs options filename terminal-based editor gzip (gunzip) options filename(s) Scripting slightly more efficient compress/uncompress pico options filename simple text editor Programs can be be scripted using the any of the zip (unzip) options filename(s) compress textedit options filename X-windows editor following. Login startup files are in ( ). (uncompress) and archive (unarchive) tar options -f archive-name filename(s) /bin/ksh (.profile, .kshrc [if setup]) work with “tar” archive of files: /bin/sh (.profile) Permissions and Security tar -cvf archive files(s) create archive /usr/local/bin/bash (.bash_login, .bash_profile, chmod permission filename(s) set level of access. tar -xvf archive extract files .profile) permissions pertain to (u)ser, (g)roup and tar -tvf archive list files /bin/csh (.login, .chsrc) (o)ther and include (r)ead, (w)rite, and /usr/local/bin/tcsh (.login, .chsrc) e(x)ecute. /usr/local/bin/perl Turn access on with “+” Working With Processes /usr/local/bin/wish8.0 Turn access off with “-” /usr/local/bin/rexx ps option show running jobs on system. Set access exactly to with “=“ ps -fu userid show jobs running as userid chmod go-rwx filename(s) protect your files kill pid kill job given by process id pid. Compilers from prying eyes Use ps -fu userid to find the pid. control-z stop the foreground job f77 options filename.f FORTRAN77 (Sun) bg (fg) put a stopped job into the f90 options filename.f90 FORTRAN90 (Sun) Shell Commands background (foreground) cc options filename.c C (Sun) jobs show user’s running and CC options filename.cc C++ (Sun) history show previously-run commands suspended jobs gcc options filename.c C (gnu) escape (repeat k or j) move up or down nohup command & run command in the g++ options filename.cc C++ (gnu) through history of commands. Press “enter” background; it will not stop when you logout. pc options filename.p Pascal (Sun) to re-execute (ksh only). alias newcommand command-string create new (applies to ksh only) Options are compiler-specific. Execute the command that runs command-string, including compiled binary with ./binary-name all of the given options If not specified, binary will be called “a.out” X-Windows command > outputfile command ’s output replaces . enableX sets user DISPLAY. outputfile (>> will append) Xwindows server must be enabled on PC command < inputfile command ’s input comes netscape start Netscape Navigator from inputfile textedit filename edit filename command1 | command2 command1’s output jws Java Workshop programming suite becomes command2 ’s input ws Sun Workshop programming and debugging suite