0% found this document useful (0 votes)
118 views20 pages

Linux Commands: Appendix A

The document provides an overview of important Linux commands organized into categories such as getting help, managing files and directories, finding files, processing files, managing processes, and managing the file system. For each command, it lists the purpose, syntax, and most common options. The goal is to help the reader find the right command for common system administration tasks.

Uploaded by

zeem91
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views20 pages

Linux Commands: Appendix A

The document provides an overview of important Linux commands organized into categories such as getting help, managing files and directories, finding files, processing files, managing processes, and managing the file system. For each command, it lists the purpose, syntax, and most common options. The goal is to help the reader find the right command for common system administration tasks.

Uploaded by

zeem91
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 20

APPENDIX A

LINUX COMMANDS
This appendix presents alphabetically arranged reference entries for the most impor-tant Linux commands. The goal here is to provide you with an overview of all com-mands needed to manage files and directories, start and stop processes, find files, work with text files, and access online help. If you are looking for a command for a specific task, but dont know which command to use, you may find it helpful to browse through the commands by category. Table A-1 shows the Linux commands organized by categories. Table A-1: Linux Commands Command Name Getting Online Help apropos info man whatis Action

Finds man pages for a specified keyword Displays online help information about a specified command Displays online help information Similar to apropos, but searches for complete words only

Making Commands Easier alias Defines an abbreviation for a long command type Shows the type and location of a command unalias Deletes an abbreviation defined using alias Managing Files and Directories cd Changes the current directory chattr Changes file attributes in Linux ext2 and ext3 file systems chgrp Changes group ownership of file chmod Changes file permissions chown Changes file owner and group cp Copies files ln Creates symbolic links to files and directories ls Displays the contents of a directory mkdir Creates a directory mv Renames a file as well as moves a file from one directory to another rm Deletes files rmdir Deletes directories pwd Displays the current directory touch Updates a files time stamp

APPENDIX A: LINUX COMMAND

Finding Files find lsof locate whereis which Processing Files cat cut dd diff expand file fold grep less lpr more nl paste patch sed sort split tac tail tr uniq wc zcat zless

Finds files based on specified criteria such as name, size, and so on Lists open files Finds files using a periodically updated database Finds files based in the typical directories where executable (also known as binary) files are located Finds files in the directories listed in the PATH environment variable Displays a file on standard output (can be used to concatenate several files into one big file) Extracts specified sections from each line of text in a file Copies blocks of data from one file to another (used to copy data from devices) Compares two text files and finds any differences Converts all tabs into spaces Displays the type of data in a file Wraps each line of text to fit a specified width Searches for regular expressions within a text file Displays a text file, one page at a time (can go backward also) Prints files Displays a text file, one page at a time (goes forward only) Numbers all nonblank lines in a text file and prints the lines to standard output Concatenates corresponding lines from several files Updates a text file using the differences between the original and revised copy of the file Copies a file to standard output while applying specified editing commands Sorts lines in a text file Breaks up a file into several smaller files with specified size Reverses a file (last line first and so on) Displays the last few lines of a file Substitutes one group of characters for another throughout a file Eliminates duplicate lines from a text file Counts the number of lines, words, and characters in a text file Displays a compressed file (after decompressing) Displays a compressed file one page at a time (can go backwards

126

APPENDIX A: LINUX COMMAND

also) zmore Displays a compressed file one page at a time Archiving and Compressing Files bzip2 Compresses files using an algorithm called the Burrows-Wheeler blocks orting text-compression algorithm and Huffman coding bunzip2 Decompresses files compressed by bzip2 (same as bzip2 -d) compress cpio gunzip gzip tar uncompress Managing Processes bg fg free halt kill ldd nice ps printenv pstree reboot shutdown top uname Managing Users chsh groups id passwd su Compresses files Copies files to and from an archive Decompresses files compressed with GNU ZIP (gzip) or compress Compresses files (more powerful than compress) Creates an archive of files in one or more directories (originally meant for archiving on tape) Decompresses files compressed with compress Runs an interrupted process in the background Runs a process in the foreground Displays the amount of free and used memory in the system Shuts down Linux and halts the computer Sends a signal to a process (usually used to terminate a process) Displays the shared libraries needed to run a program Runs a process with lower priority (referred to as nice mode) Displays a list of currently running processes Displays the current environment variables Similar to ps, but shows parent-child relationships clearly Stops Linux and then restarts the computer Shuts down Linux Displays a list of most processor- and memory-intensive processes Displays information about the system and the Linux kernel Changes the shell (command interpreter) Prints the list of groups that includes a specified user Displays the user and group ID for a specified user name Changes the password

Starts a new shell as another user or root (when invoked without any argument) Managing the File System df Summarizes free and available space in all mounted storage devices du Displays disk usage information

127

APPENDIX A: LINUX COMMAND

fdformat fdisk fsck mkfs mknod mkswap mount swapoff swapon sync tty umount

Formats a diskette Partitions a hard disk Checks and repairs a file system Creates a new file system Creates a device file Creates a swap space for Linux in a file or a disk partition Mounts a device (for example, the CD-ROM) on a directory in the file system Deactivates a swap space Activates a swap space Writes buffered data to files Displays the device name for the current terminal

Unmounts a device from the file system Working with Date and Time cal Displays a calendar for a specified month or year date Shows the current date and time or sets a new date and time

The rest of this appendix covers individual reference entries for each command shown in Table A-1. Each reference entry is organized as follows: Purpose tells you when to use the command. Syntax shows the syntax of the command with a few common options. Also, typical option values are shown. All optional items are shown in square brackets. Options lists most options, along with a brief description of each option. For many commands, you will find all options listed in this section. However, some commands have too many options to cover here. For those commands, I describe the most commonly used options.

alias
Purpose Syntax Options Define an abbreviation for a long command or view the current list of abbreviations. alias [abbrev=command] None View a list of all man pages that contain a specific keyword. apropos keyword None

apropos
Purpose Syntax Options

bg
Purpose Syntax Run an interrupted process in the background. bg

128

APPENDIX A: LINUX COMMAND

Options

None

bzip2, bunzip2
Purpose Syntax Options Compress file using block-sorting file compression. bzip2 [-cdfktvVL] files -c sends output to the standard output. -d decompress files (equivalent to bunzip2 command). -f overwrites existing output files of the same name. -k keeps input files. -t tests the integrity of a compressed file. -v runs in verbose mode, which shows more information. -L displays license information. -V displays version information.

cal
Purpose Syntax Options View the calendar of any month in any year. cal cal [-jy] [[month_number] year]] -j displays Julian dates (days numbered between 1 and 366). -y displays the calendar for all months of the current year.

cat
Purpose Syntax Options Copy contents of a file to standard output (the screen). cat [-benstvA] files -b numbers nonblank lines. -e shows each end-of-line (as $) and all nonprinting characters. -n numbers all output lines starting with number 1. -s replaces multiple blank lines with a single blank line. -t shows tabs as ^I . -v shows nonprinting characters. -A shows all characters (including nonprinting ones).

cd
Purpose Syntax Options Change the current directory. cd [directory] None

chattr
Purpose Syntax Options Change file attributes in Linux ext2 and ext3 file systems. chattr [ -RV ] [ -v version ][mode ] files... -V verbosely displays permission changes. -v version sets the version number of the file to version.

chgrp
Purpose Syntax Options Change the group ownership of one or more files. chmod [-cfvR] group files -c lists only files whose permissions have changed. -f stops any error message displays. -v verbosely displays permission changes. -R recursively changes the permissions of files in all subdirectories.

129

APPENDIX A: LINUX COMMAND

chmod
Purpose Syntax Options Change the permission settings of one or more files. chmod [-cfvR] permission files -c lists only files whose permissions have changed. -f stops any error message displays. -v verbosely displays permission changes. -R recursively changes permissions of files in all subdirectories.

chown
Purpose Syntax Options Change the user and group ownership of a file. chown [cvfR] username.groupname files -c lists only those files whose ownership has changed. -f stops any error message displays. -v verbosely displays ownership changes. -R recursively changes the ownership of files in all subdirectories.

chsh
Purpose Syntax Options Change the default shell started at login. chsh [-s shell][username] -s shell specifies the name of the shell executable to use (shell can be any program listed in the /etc/shells file, such as /bin/bash and /bin/csh).

compress
Purpose Syntax Options Compress one or more files by using Lempel-Ziv compression. compress [-cdrvV] files -c writes the compressed file to the standard output and retains the original file. -d decompresses the file. -r recursively compresses the files in all subdirectories. -v displays a message as each file is compressed. -V prints the version number and exits.

cp
Purpose Syntax Options Copy files and directories. cp [options] source_files destination_directory cp [options] source_file destination_file -a preserves all file attributes. -b makes a backup copy before copying. -d copies a link but not the file pointed to by the link. -i asks for confirmation before overwriting files. -l creates hard links instead of copying files. -p preserves ownership, permissions, and the file time stamp. -R recursively copies files in all subdirectories. -s creates soft links instead of copying files. -u copies a file only when the file being copied is newer than the destination. -v displays verbose messages as copying progresses. --help displays a Help message about cp.

130

APPENDIX A: LINUX COMMAND

cpio
Purpose Syntax Options Copy files in from, or out to, an archive that can be on a storage medium such as tape or a file on the disk. cpio [-icdv] pattern cpio [-ocBv] pattern cpio [-padm] pattern -i extracts files whose names match the pattern. -o copies files to archive files whose names are provided on standard input. -p copies files to another directory on the same system. -a resets access times of input files. -B copies files using 5,120 bytes per record (the default is 512 bytes per record). -c reads or writes header information as ASCII characters. -d creates directories as needed. -m retains the previous file-modification time. -v prints a list of filenames.

cut
Purpose Syntax Options Copy selected parts of each line of text from a file to standard output. cut [options] file -b list extracts the characters at positions specified in the list. -f list extracts the fields (assumed to be Tab-separated) specified in list. -d char specifies the character that delimits the fields (the default is Tab). -s skips lines that do not contain delimited fields (see the -f option).

date
Purpose Syntax Options Display the current date and time or set a new date and time. date [options] [+format] date [-su] [MMDDHHMM[[CC]YY][.SS]] -u displays or sets the time using Greenwich Mean Time (GMT).

dd
Purpose Syntax Options Copy blocks of data from standard input to standard output (and optionally convert the data from one format to another). dd option1=value1 option2=value2 option3=value3 ... if=file reads from the specified file instead of standard input. of=file writes to the specified file instead of standard output. ibs=nbytes reads blocks of nbytes bytes at a time. obs=nbytes writes blocks of nbytes at a time. bs=nbytes reads and writes blocks of nbyte bytes at a time. cbs=nbytes converts nbytes bytes at a time. skip=nblocks skips nblocks input blocks from the beginning of the input file. seek=nblocks skips nblocks output blocks in the output file. count=nblocks copies nblocks blocks from input to output. conv=code performs conversion; code can be one of following: ascii converts EBCDIC to ASCII. ebcdic converts ASCII to EBCDIC. lcase converts to lowercase. ucase converts to uppercase.

131

APPENDIX A: LINUX COMMAND

swab swaps every pair of input bytes. noerror continues after read errors.

(Note: EBCDIC is a character-encoding format used in IBM mainframes.)

df
Purpose Syntax Options Display the amount of free and used storage space on all mounted file systems. df [options] [filesystem] -a displays information for all file systems. -h displays size information in human-readable format. -i displays inode information (the disk is organized into inodes). -T prints the type of file system. -t type displays information about specified types of file systems only. -x type excludes specified types of file systems from the output. --help displays a Help message.

diff
Purpose Syntax Options Show the difference between two text files (or all files with the same names in two directories). diff [options] from_file to_file -a treats all files as text even if they arent text files. -b ignores blank lines and repeated blanks. -c produces output in a different format. -d tries to find a smaller set of changes (this makes diff slower). -e produces a script for the ed editor to convert from_file to to_file. -f produces output similar to that of -e, but in reverse order. -i ignores case. -l passes the output to the pr command to paginate it. -n works like -f, but counts the number of changed lines. -r recursively compares files with the same name in all subdirectories. -s reports when two files are the same. -t expands tabs to spaces in the output. -u uses the unified output format. -v displays the version of diff. -w ignores spaces and tabs when comparing lines.

du
Purpose Syntax Options Displays summary information about disk usage (in kilobytes). du [options] [directories_or_files] -a displays usage information for all files (not just directories). -b displays usage in bytes (instead of kilobytes). -c displays a grand total of all usage information. -h displays size information in human-readable format. -k displays usage information in kilobytes (default). -s displays total disk usage without per directory details.

expand
Purpose Syntax Options Write files to standard output after expanding each tab into an appropriate number of spaces. expand [options] [files] -n (where n is a number) sets the tabs n spaces apart.

132

APPENDIX A: LINUX COMMAND

-n1 [n2, ...] (where n1, n2, . . . are numbers) specifies the tab stops. -i converts only the initial tab into spaces.

fdformat
Purpose Syntax Options Format a diskette specified by device name (such as /dev/fd0H1440 for a 3.5-inch, high-density diskette in drive A). fdformat [-n] device_name -n disables the verification performed after formatting.

fdisk
Purpose Syntax Options Partition a disk or display information about existing partitions. fdisk [options] [device_name] -l displays partition tables and exits. -s device displays the size of the specified partition. -v displays the version number of the fdisk program.

fg
Purpose Syntax Options Continue an interrupted process in the foreground. fg None

file
Purpose Syntax Options Display the type of data in a file based on rules defined in the /usr/lib/magic file (this is known as the magic file). file [options] files -c displays a parsed form of a magic file (or the default one) and exits. -m file1[:file2 :...] specifies other magic files. -v displays the version number and exits. -z looks inside compressed files.

find
Purpose Syntax Options Display a list of files that match a specified set of criteria. find [path] [options] -depth processes the current directory first, then subdirectories. -maxdepth n restricts searches to n levels of directories. -follow processes directories included through symbolic links. -name pattern finds files whose names match the pattern. -ctime n matches files modified exactly n days ago. -user uname finds files the specified user owns. -group gname finds files the specified group owns. -path pattern finds files whose pathname matches the pattern. -perm mode finds files with the specified permission setting. -size +nK finds files bigger than n kilobytes. -type x finds files of a specified type, where x is one of the following: f matches files. d matches directories. l matches symbolic links. -print displays the names of the files found. -exec command [options]{}\; executes the specified command by passing it the name of the file that was found.

133

APPENDIX A: LINUX COMMAND

fold
Purpose Syntax Options Wrap lines of text to a specified width (the default is 80 characters). fold [options] [files] -b counts bytes instead of columns, so backspaces and tabs are counted. -s breaks lines at word boundaries. -w N (where N is a number) sets line width to N characters.

free
Purpose Syntax Options Display the amount of free and used memory in the system. free [options] -b displays memory in number of bytes. -k displays memory in kilobytes (default). -m displays memory in megabytes. -s n repeats the command every n seconds. -t displays a line containing a summary of the total amounts.

fsck
Purpose Syntax Options Check and repair a Linux file system. fsck [options] device_name -A checks all file systems listed in the /etc/fstab file. -R skips the root file system (when checking all file systems). -T does not show the title on startup. -N shows what might be done but does not actually do anything. -V produces verbose output. -t fstype specifies the file-system type (such as ext2). -n answers all confirmation requests with no (only for the ext2 file system). -p carries out all repairs without asking for confirmation (for ext2). -y answers all confirmation requests with yes (only for the ext2 file system).

grep
Purpose Syntax Options Search one or more files for lines that match a regular expression (a search pattern). grep [options] pattern files -N (where N is a number) displays N lines around the line containing pattern. -c shows the number of lines that contain the search pattern. -f file reads options from a specified file. -i ignores case. -l displays the filenames that contain pattern. -n displays a line number next to lines that contain pattern. -q returns a status code but does not display any output. -v displays the lines that do not contain pattern. -w matches only whole words.

groups
Purpose Syntax Options Show the groups to which a user belongs. groups [username] None

134

APPENDIX A: LINUX COMMAND

gunzip
Purpose Syntax Options Decompresses files the gzip or the compress command compresses. gunzip [options] files See the options for gzip.

gzip
Purpose Syntax Options Compress one or more files. gzip [options] files -c writes output to standard output and retains the original file. -d decompresses the file (same as gunzip). -h displays a Help message. -l lists the contents of a compressed file. -n does not save the original name and time stamp. -r recursively compresses files in all subdirectories. -v displays verbose output. -V displays the version number.

halt
Purpose Syntax Options Terminate all processes and halt the system (you must log in as root). halt [options] -n does not flush out in-memory buffers to disk before halting the system. -f forces a halt without calling the /sbin/shutdown command. -i shuts down all network interfaces before halting the system.

id
Purpose Syntax Options List the user ID, group ID, and groups for a user. id [options] [username] -g displays group ID only. -n displays group name instead of ID. -u displays user ID only. -Z displays the SELinux security context.

info
Purpose Syntax Options View online help information about any Linux command. info [options] command -d dirname adds a directory to a list of directories to be searched for files. -f infofile specifies the file to be used by info. -h displays usage information about info.

kill
Purpose Syntax Options Send a signal to a process. kill [options] process_id -signum (where signum is a number or name) sends the specified signal. -l lists the signal names and numbers.

ldd
Purpose Syntax Display the names of shared libraries required to run a program. ldd [options] programs

135

APPENDIX A: LINUX COMMAND

Options

-v prints the version number of ldd. -V prints the version number of the dynamic linker (ld.so). -d relocates functions and reports missing functions. -r relocates both data and functions and reports missing objects.

less
Purpose Syntax Options View text files one screen at a time (and scroll backward if necessary). less [options] filenames -? displays a list of commands you can use in less. -p text displays the first line where text is found. -s reduces multiple blank lines to a single blank line.

ln
Purpose Syntax Options Set up a hard or symbolic link (shortcut or pseudonym) to files and directories. ln [options] existing_file new_name -b makes backup copy of files about to be removed. -d creates a hard link to a directory (only root can do this). -f removes the existing file with new_name. --help displays a Help message. -s creates a symbolic link. -v displays verbose output.

locate
Purpose Syntax Options From a periodically updated database, list all files that match a specified pattern. locate pattern -u updates the database of files.

lpr
Purpose Syntax Options Print one or more files. lpr [options] [files] -Pprinter prints to the specified printer (the name appears in /etc/printcap). -#N (where N is a number) prints that many copies of each file. -h suppresses the burst page (the first page, with user information). -m sends mail upon completion of a print job. -r removes the file after printing. -J jobname prints this job name on the burst page. -U username prints this user name on the burst page.

ls
Purpose Syntax Options List the contents of a directory. ls [options] [directory_name] -a displays all files, including those that start with a period (.). -b displays unprintable characters in filenames with octal code. -c sorts according to file creation time. -d lists directories like any other file (rather than listing their contents). -f lists directory contents without sorting (exactly as they are in the disk). -i shows the inode information. -l shows the file listing in the long format, with detailed information. -p appends a character to a filename to indicate its type.

136

APPENDIX A: LINUX COMMAND

-r sorts the listing in reverse alphabetical order. -s shows the size (in kilobytes) of each file next to the filename. -t sorts the listing according to the files time stamp. -1 displays a one-column listing of filenames. -R recursively lists the files in all subdirectories.

lsof
Purpose Syntax Options List open files and network connections. lsof [options] [names] -h displays a Help message. -c X displays files for commands that begin with letter X. -i IP shows network connections whose IP address matches IP. -s shows the file size (when available). -t displays terse output. -u names lists the open files for the specified users. -R lists the parent process ID.

man
Purpose Syntax Options View online manual pages (also called man pages). man [options] [section] command -C cfile specifies the man configuration file (the default is /etc/man.config). -P pager specifies the program to use to display one page at a time (for example, less). -a displays all man pages matching a specific command. -h displays a Help message and exits. -w shows the location of the man pages to be displayed.

mkdir
Purpose Syntax Options Create a directory. mkdir [options] directory_name -m mode assigns the specified permission setting to the new directory. -p creates the parent directories if they do not already exist.

mkfs
Purpose Syntax Options Create a Linux file system on a hard-disk partition or a diskette. mkfs [-V] [-t] [options] device_name [blocks] -V produces verbose output needed for testing. -t fstype specifies the file system type (such as ext2). -c checks the device for bad blocks before creating the file system. -l filename reads the bad-block list from specified file.

mknod
Purpose Syntax Options Create a device file with specified major and minor numbers. mknod device_file {b|c} major minor None

mkswap
Purpose Syntax Options Create a swap space for Linux. mkswap [options] device_or_file numblocks -c checks the device for bad blocks before creating the swap space.

137

APPENDIX A: LINUX COMMAND

-f forces creation of swap space even if there are errors, such as the requested size being greater than space available on the device. -P NNN uses NNN as the page size for the swap space. -vN (where N is 0 or 1) creates an old-style swap space if N is 0; if N is 1, creates a new-style swap space.

more
Purpose Syntax Options View text files one screen at a time. more [options] filenames +N (where N is a number) displays the file starting at the specified line number +/pattern begins displaying two lines before the pattern. -s reduces multiple blank lines to a single blank line.

mount
Purpose Syntax Options Associate a physical device to a specific directory in the Linux file system. mount [options] device directory -a mounts all devices listed in the /etc/fstab file. -h displays a Help message and exits. -r mounts the device for read-only (no writing allowed). -t fstype specifies the file system type on the device. -v displays verbose messages. -V displays the version number and exits.

mv
Purpose Syntax Options Rename files and directories or move them from one directory to another. mv [options] source destination -b makes backup copies of files being moved or renamed. -f removes existing files without prompting. -i prompts before overwriting any existing files. -v displays the name of the file before moving it.

nice
Purpose Syntax Options Run a program at a lower or higher priority level. nice [options] program +n (n = number) adds n to the nice value (positive values are lower priority). -n (n = number) subtracts n from the nice value (negative nice value indicates a higher priority).

nl
Purpose Syntax Options Add line numbers to nonblank lines of text in a file and write to standard output. nl [options] [file] -ba numbers all lines. -bt numbers text lines only (the default). -sc separates text from line numbers with the character c (the default is tab). -wn uses n columns to show the line numbers.

138

APPENDIX A: LINUX COMMAND

passwd
Purpose Syntax Options Change password. passwd [username] None

paste
Purpose Syntax Options Write to standard output corresponding lines of each file, separated by a tab. paste file1 file2 [...] -s pastes the lines from one file at a time, instead of one line from each file. -d delim uses delimiters from the list of characters, instead of a tab. - causes paste to use standard input as a file.

patch
Purpose Syntax Options Apply the output of the diff command to an original file. patch [options] < patch_file -c causes the patch file to be interpreted as a context diff. -e forces patch to interpret the patch file as an ed script. -f forces patch to be applied regardless of any inconsistencies. -n causes the patch file to be interpreted as a normal diff. -pn strips everything up to n slashes in the pathname. -R indicates that patch file has been created with new and old files swapped. -u causes the patch file to be interpreted as a unified diff. -v displays the version number.

printenv
Purpose Syntax Options View a list of environment variables. printenv None

ps
Purpose Syntax Options Display status of processes (programs) running in the system. ps [options] Note that unlike other commands, ps options do not have a - prefix. a displays processes of other users. e displays all processes. f displays a family tree of processes. j displays output using jobs format. l displays in long format, with many details for each process. m displays memory usage information for each process. u displays the user name and start time. x displays processes that are not associated with any terminal. Z displays SELinux security context.

pstree
Purpose Syntax Options Display all running processes in the form of a tree. pstree [options] [pid] -a shows command-line arguments. -c does not compact subtrees.

139

APPENDIX A: LINUX COMMAND

-l displays long lines. -n sorts processes by process ID (instead of by name). -p shows process IDs.

pwd
Purpose Syntax Options Display the current working directory. pwd None

reboot
Purpose Syntax Options Terminate all processes and reboot the system (you must log in as root). reboot [options] -n reboots the system without flushing out in-memory buffers to disk. -f forces a halt without calling the /sbin/shutdown command. -i shuts down all network interfaces before rebooting the system.

rm
Purpose Syntax Options Delete one or more files. rm [options] files -f removes files without prompting. -i prompts before removing a file. -r recursively removes files in all subdirectories, including the directories. -v displays the name of each file before removing it.

rmdir
Purpose Syntax Options Delete a specified directory (provided that the directory is empty). rmdir [options] directory -p removes any parent directories that become empty.

sed
Purpose Syntax Options Copy a file to standard output after editing according to a set of commands. sed [options] [editing_commands][file] -e'instructions' applies the editing instructions to the file. -f scriptfile applies editing commands from scriptfile. -n suppresses default output.

shutdown
Purpose Syntax Options Terminate all processes and shut down (or reboot) the system. shutdown [options] time [messages] -t seconds specifies the time between the message and the kill signal. -h halts the system after terminating all the processes. -r reboots the system after terminating all the processes. -f performs a fast reboot. -k sends warning messages but does not shut down the system. -c cancels a shutdown thats in progress.

sort
Purpose Sort or merge lines from a file, and write to standard output.

140

APPENDIX A: LINUX COMMAND

Syntax Options

sort [options] [files] -c checks if files are already sorted and prints error message if not. -m merges files by sorting them as a group. -b ignores leading blanks. -d sorts in phone directory order (using only letters, digits, and blanks). -f treats lowercase letters as equivalent to uppercase letters. -k pos1[,pos2] specifies the sort field as characters between the two positions pos1 and pos2. -o file writes output to the specified file instead of standard output. -r sorts in reverse order. -g sorts numerically after converting the prefix of each line into a floating-point number. -i ignores unprintable characters. -n sorts numerically (used when a number begins each line). -tc specifies the separator character. +n considers characters only from position n onward (0 = first position).

split
Purpose Syntax Options Split a file into several smaller files. split [options] file [prefix] -l n (where n is a number) puts n lines in each file. -n (where n is a number) puts n lines in each file. -b nk (where n is a number) splits the file every n kilobytes. -c nk (where n is a number) puts as many lines as possible in a split file without exceeding n kilobytes per file.

su
Purpose Syntax Options Become another user. su [options] [username] -c command passes the command to the shell. -f prevents reading the startup file (.cshrc) when the shell is csh or tcsh. -l or - makes the new shell a login shell by reading the users startup file. -p preserves the environment variables HOME, USER, LOGNAME, and SHELL. -s shell runs the specified shell instead of the users default shell.

swapoff
Purpose Syntax Options Deactivate the specified swap device or file. swapoff device None

swapon
Purpose Syntax Options Activate the specified swap device or file. swapon [-a] device -a enables all swap devices listed in the /etc/fstab file.

sync
Purpose Syntax Write buffers to disk. sync

141

APPENDIX A: LINUX COMMAND

Options

None

tac
Purpose Syntax Options Copy a file, line by line, to the standard output in reverse order (last line first). tac file -b places the separator at the beginning of each line. -r treats the separator string specified by -s as a regular expression. -s sep specifies a separator (instead of the default newline character).

tail
Purpose Syntax Options View the last few lines of a file. tail [options] file -N (where N is a number) displays last N lines. -n N (where N is a number) displays last N lines. -f reads the file at regular intervals and displays all new lines.

tar
Purpose Syntax Options Create an archive of files or extract files from an archive. tar [options] files_or_directories -c creates a new archive. -d compares files in an archive with files in the current directory. -r extends the archive with more files. -t lists the contents of an archive. -x extracts from the archive. -C directory extracts files into the specified directory. -f file uses the specified file as the archive, instead of a tape. -L n specifies the capacity of the tape as n kilobytes. -N date only archives files newer than the specified date. -T file archives or extracts the filenames specified in file. -v displays verbose messages. -z compresses or decompresses the archive with gzip.

top
Purpose Syntax Options List currently running processes, arranged in order by their share of CPU time. top [q] [d delay] q causes top to run with the highest possible priority (you have to be logged in as root). d delay specifies the delay between updates, in seconds.

touch
Purpose Syntax Options Change a files time stamp. touch [options] files -c stops touch from creating a file that does not exist. -d time uses the specified time. -r file uses the time stamp from the specified file. -t MMDDhhmm[[CC]YY][.ss] uses the specified date and time.

tr
Purpose Copies from standard input to standard output, while substituting one set

142

APPENDIX A: LINUX COMMAND

Syntax Options

of characters with another. tr [options] string1 [string2] -c complements characters in string1 with ASCII codes 001377. -d deletes from the input all characters specified in string1. -s replaces repeated sequences of any character in string1 with a single character.

tty
Purpose Syntax Options Display the device name of the terminal. tty None

type
Purpose Syntax Options Display the type of a command (whether it is a built-in shell command or a separate executable program). type command None

umount
Purpose Syntax Options Disassociate a device from the Linux file system. umount device None

unalias
Purpose Syntax Options Delete an abbreviation defined earlier with alias. unalias abbreviation None

uname
Purpose Syntax Options Display system information, such as type of machine and operating system. uname [options] -a displays all information. -m displays the hardware type (for example, i586). -n displays the machines host name. -p displays the processor type (this appears as unknown). -r displays the operating system release (for example, 2.4.0-0.43.12). -s displays the operating system name. -v displays the operating system version (shown as date of compilation).

uncompress
Purpose Syntax Options Decompress one or more files that have been compressed using the compress command. uncompress [-cdrvV] files -c writes the result to the standard output and retains the original. -r recursively decompresses files in all subdirectories. -v displays a message as each file is decompressed. -V prints the version number and exits.

143

APPENDIX A: LINUX COMMAND

uniq
Purpose Syntax Options Write all unique lines from an input file to standard output. uniq [options] file -n (where n is a number) ignores the first n fields on each line. +n (where n is a number) ignores the first n characters on each line. -c writes the number of times each line occurred in file. -d writes only duplicate lines. -u writes only unique lines (the default).

wc
Purpose Syntax Options Display the byte, word, and line count of a file. wc [options] [files] -c displays only the byte count. -w displays only the word count. -l displays only the line count.

whatis
Purpose Syntax Options Search the whatis database (see apropos) for complete words. whatis keyword None

whereis
Purpose Syntax Options Find the source, binary, and man page for a command. whereis [options] command -b searches only for binaries. -m searches only for man pages. -s searches only for sources.

which
Purpose Syntax Options Search the directories in the PATH environment variable for a command. which command None

zcat, zless, zmore


Purpose Syntax Options View the contents of a compressed text file without having to first decompress the file. zcat filename zless filename zmore filename None

144

You might also like