Unix Commands: Command Purpose
Unix Commands: Command Purpose
Command passwd uname date cal man who id cd pwd ls ls -a ls -F ls -l ls -ld file cat wc touch tee mkdir /-p cp -i/ cp -r mv -i rm -i/ rm -r rmdir lp lpstat pr find cmp diff sort grep chmod umask tar compress/uncompress zcat gzip/gunzip gzcat jar cpio volcheck telnet rlogin rsh rcp Purpose Change password Displays operating system information Displays the systems current date and time Displays a calendar for the current month and year Displays the online manual page for any given command Displays a list of users currently logged in to the local system Identifies the user ID, user name, group ID, and group name of a user Changes current working directory Displays the absolute (full) path name of the current working directory List contents of a directory Displays hidden files Displays file types Displays detailed information about the contents of a directory Dislplays detailed information for the directory only, not its contents Shows file type Displays the entire contents of one or more text files on the screen Displays the number of lines, words, and characters contained in a file Creates an empty file Copies standard input to standard output, writing a duplicate Creates directories/ Use -p option to make multiple directories at one time Copies files and directories/ -i prompts for confirmation/ -r copies directories Moves or renames a file or directory Removes files and directories/ -i prompts for confirmation/ -r removes directories Removes empty directories only Qeues text files for printing/ Options d, -o, -n, -m Displays the status of the printer queue? Options p, -o, -d, -t, -s, -a Prints the contents of a file according to different format options Locates files in the directory tree Compares files for differences Finds differences between files Sorts text lines Globally searches for regular expressions in files Modifies permissions on files or directories Shows umask filter value (octal) and can be used to change umask value Creates and extracts files from a tape device or file archive Compresses/ uncompresses a file Allows viewing of a compressed file without uncompressing the file Compresses/ uncompresses a file Allows viewing of a gzipped file without uncompressing the file Packages and compresses multiple files to a single archive file Copies and extracts files from a file archive or tape device Checks for media in a drive - must be used to detect diskettes Uses TCP/IP to connect to another system Establishes a remote login session on another workstation Executes a program on a remote system Enables the copying of files or directories to and from another system 1
Transfer files between systems Lists the processes currently running on the system Terminates a process Terminates a process Used to switch an option on/ used to switch an option off Displays most recently used commands Can be used to create a named pipe Ex. Mkfifo Nameofpipe Allows customization and abbreviation of UNIX commands/ Removes aliases
Control Characters
Control Characters Control-C Control-U Control-S Control-Q Control-D Control-W Purpose Terminates the command currently running Erases all characters on the current command line Stops output to the screen Restarts output to the screen after Control-S has been pressed Indicates end-of-file or exit Erases the last word on the command line
- To return to the previous directory type cd .. - The tilde (~) character represents the home directory - To access CDROM type cd /cdrom/cdrom0 You can enhance the capability of commands by using options and arguments. The basic syntax of a UNIX command includes: Command option(s) argument(s) command option argument Executable (specifies what the system is to do) Modifies the command (this specifies how the command is run). Options start with a - (dash) character A file name, directory name, or text
The following are examples of commands and commands using options and arguments % ls (command) % ls -l (command and option) % ls -l dir1 (command, option, and argument) % cal 12 2008 (command and two arguments) % uname -rpns (command and multiple options)
displays detailed information for the directory only, not its contents displays the contents of a directory and all of its subdirectories (a.k.a. Recursive listing) displays files by last modification time displays files by last modification time in reverse order
wc command with options - wc command displays number of lines, words, and characters in a file wc -l Prints line count wc -w Prints word count wc -m Prints character count wc -c Prints byte count cp (copy) command with options cp -i Prompts for confirmation before overwriting any existing file with the new file cp -r Copies a directory rm (remove) command with options rm -i Prompts for confirmation before removing the file rm -r Removes a directory rmdir Removes empty directories only lp command with options - lp command queues text files for printing lp -d (destination) Specifies the desired printer. If printing to the default printer, the d option is not necessary lp -o (nobanner) Specifies that the banner page is not to be printed lp -n (number) Prints a specified number of file copies lp -m Sends a mail message to you after a job is complete lpstat command with options - lpstat command displays the status of the printer queue lpstat -p Displays the status of all printers lpstat -o Displays the status of all output requests lpstat -d Displays which printer is the system default lpstat -t Displays complete status information for all printers lpstat -s Displays a status summary for all printers lpstat -a Displays which printers are accepting requests pr command with options - pr command is used to format and print the contents of a file according to different format options. pr +page Begins printing on page number specified pr -column Prints file in multi-column format. The default is one column pr -d Prints file in double-space format pr -h Replaces the file name contained in the page header with the pattern header pr -l Resets page length to lines, the default is 66 lines pr -m Merges files side-by-side into text columns. The columns are of equal width. Lines of data that do not fit within a column are truncated pr -t Prints files without the header 3
pr -n Numbers each line diff command with options diff -i Ignores the case of letters; for example, A is equal to a. diff -c Produces a contextual listing of differences grep command with options grep -i Ignores case. Uppercase and lowercase characters are considered identical grep -l Lists only the names of files with matching lines grep -n Precedes each line with its relative line number in the file grep -v Inverts the search to display only lines that do not match the pattern grep -c Prints only a count of the lines that contain pattern grep -w Searches for the expression as a word, ignoring those matches that are substrings of larger words Using the find Command Expressions used with the find command Expression Definition -name filename Finds files matching the specified filename. Metacharacters are acceptable if placed inside quotes -size [+|-]n Finds files that are larger than +n, smaller than n, or exactly n. The n represents 512 byte blocks -atime [+|-]n Finds files that have been accessed more than +n, less than n, or exactly n days -mtime [+|-]n Finds files that have been modified more than +n, less than n, or exactly n days -user loginID Finds all files that are owned by the login ID name -type Finds a file type; for example, f (file) or d (directory) -perm Finds files that have certain access permission bits Actions used with the find command Action Definition -exec command {} \; Executes the specified command on each file located, automatically. A set of braces, {}, delimits where the file name is passed to the command from the preceding expressions. A space, backslash, and semicolon \;, delimits the end of the command. There must be a space before the backslash (\). -ok command {} \; Interactive form of exec. It requires input before find applies the command to the file; otherwise, it behaves as the -exec action. -print Instructs find to print the current path name to the terminal screen. This is the default. -ls Prints the current path name, together with its associated statistics, such as inode number, size in kilobytes, protection mode, number of hard links, and user. Examples of using the find command To search for core files starting at the root (/) directory: % find / -name core To search for core files starting at your home directory and delete each one as it is found: % find ~ -name core exec rm {} \; To look for all files, starting at the current directory that have not been modified in the last 90 days: % find . mtime +90 4
To find files larger than 57 blocks (512-byte blocks) starting at the home directory: % find ~ -size +57 To search for files that end with characters tif, starting at the /usr directory % find /usr name *tif
tar command with options tar c Creates a new tar file. Writing starts at the beginning of the file rather than the end tar t Lists the table of contents of the tar file tar x Extracts the specified files from the tar file tar f Specifies the archive_file or tape device. The default tape device is /dev/rmt/0. If archive_file is -, then the tar command reads from standard input or writes to standard output, whichever is appropriate. tar v Executes in verbose mode tar r Replace. The named files are written at the end of the tape archive tar u Update. If the named files do not exist within the archive or they have been updated since being written to the archive, then the files are written to the end of the archive tar e Exit immediately if any expected errors occur tar h Follow symbolic links as if they were normal files or directories tar m When extracting files from an archive, the file modification timestamp is the time of extraction tar o When extracting from an archive, the file owner is set to the user executing tar tar w The prompt for confirmation of every file to be extracted from or added to the archive