Determine the type of file file by performing a number of tests. by performing a number of tests.
find [directory] [options] [pattern] [directory] [options] [pattern]
Search through directory directory looking for objects that match looking for objects that match pattern pattern.
gunzip [options] [file] [options] [file]
Uncompress an archive created with gzip gzip.
gzip [options] [pattern] [options] [pattern]
Create a compressed archive containing files and directories that match pattern pattern.
ls [options] [pattern] [options] [pattern]
List the contents of a directory, or list only files that match [pattern] [pattern].
mkdir directories directories Create one or more directories directories.
mv source target source target Move or rename files and directories.
rm files files Delete one or more files files from the filesystem. When used recursively (with the from the filesystem. When used recursively (with the -r -r option), option), rm rm also removes directories. also removes directories.
rmdir directories directories Delete directories directories, which must be empty.
tar [options] [files] [options] [files]
Create or extract a Tape Archive, containing either files or a recursive set of files and directories.
touch files files Change the access and/or modification times of files files by default to the present time. by default to the present time.
File-naming wildcards Wildcards (also called file globs file globs) allow the specification of many files at once. A list of commonly used wildcards can be found in Table10-4 Table10-4.
Table10-4.File-naming wildcards
Wildcard Function *
Match zero or more characters.
Match exactly one character.
[characters]
Match any single character from among characters listed between brackets. listed between brackets.
[!characters]
Match any single character other than characters listed between brackets. listed between brackets.
[a-z]
Match any single character from among the range of characters listed between brackets.
[!a-z]
Match any single character from among the characters not in the range listed between brackets.
{frag1,frag2,frag3,...} Brace expansion: create strings frag1, frag2 frag2, and frag3 frag3, etc., such that file_{one,two,three} file_{one,two,three} yields yields file_one file_one, file_two file_two, and file_three file_three.
Objective 103.4: Use Streams, Pipes, and Redirects Concepts A central concept for Linux and Unix systems is that everything is a file everything is a file.
Many system devices are represented in the filesystem using a device file device file, such as /dev/ttyS0 /dev/ttyS0 for a serial port. for a serial port.
Standard I/O The sh.e.l.l provides the standard I/O standard I/O capability, offering three default file descriptors to running programs: capability, offering three default file descriptors to running programs: Standard input ( (STDIN) is a text input stream, by default attached to the keyboard.
Standard output ( (STDOUT) is an output stream for normal program output. By default, this is the screen.
Standard error ( (STDERR) is an output stream meant for error messages. By default, this is the screen.
Pipes and redirection It is possible to tie the output of one program to the input of another. This is known as a pipe pipe and is created by joining commands using the pipe symbol ( and is created by joining commands using the pipe symbol (|).
Pipes are a special form of redirection redirection, which allows you to manage the origin of input streams and the destination of output streams. Redirection syntax for various sh.e.l.ls differs slightly. See Table10-5 Table10-5 for examples of common redirection operators. for examples of common redirection operators.
Table10-5.Common redirection operators
Redirection function Syntax for bash Send STDOUT to to file file.
$ cmd > file
$ cmd 1> file Send STDERR to to file file.
$ cmd 2> file Send both STDOUT and and STDERR STDERR to to file file.
$ cmd > file 2>&1
$ cmd > file 2> file Receive STDIN from from file file.
$ cmd < file="" append="" stdout="" to="" to="" file="">
$ cmd >> file
$ cmd 1>> file Append STDERR to to file file.
$ cmd 2>> file Append both STDOUT and and STDERR STDERR to to file file.
$ cmd >> file 2>&1 Pipe STDOUT from from cmd1 cmd1 to to cmd2 cmd2.
$ cmd1 | cmd2 Pipe STDOUT and and STDERR STDERR from from cmd1 cmd1 to to cmd2 cmd2.
$ cmd1 2>&1 | cmd2 Pipe STDOUT from from cmd1 cmd1 to to cmd2 cmd2 while simultaneously writing it to while simultaneously writing it to file1 file1 using using tee tee.
$ cmd1 | tee file1 | cmd2
Objective 103.5: Create, Monitor, and Kill Processes Concepts Processes have: A lifetime A PID A UID A GID A parent process An environment A current working directory Monitoring commands ps Generate a one-time snapshot of the current processes on standard output.
pstree Display a hierarchical list of processes in a tree format.
top Generate a continuous, formatted, real-time process activity display on a terminal or in a terminal window.
Signaling processes Processes listen for signals signals sent by the kernel or users using the sent by the kernel or users using the kill kill command: command:kill-sigspec[pids]
Send sigspec sigspec to to pids pids.
The killall killall command is used to send signals to processes by program name instead of PID. command is used to send signals to processes by program name instead of PID.
Common kill kill signals are listed in signals are listed in Table10-6 Table10-6.
Table10-6.Common signals
Signal Number Meaning HUP 1 Hangup, reread configuration.
INT 2 Interrupt, stop running.
KILL 9 Exit immediately.
TERM 15 Terminate nicely.
TSTP 18 Stop executing.
Sh.e.l.l job control Sh.e.l.ls can run processes in the background background, where they execute on their own, or in the foreground foreground, attached to a terminal. Each process handled in this way is known as a job job. Jobs are manipulated using job control commands: bg [ [jobspec]
Place jobspec jobspec in the background as if it had been started with in the background as if it had been started with & &.
fg [ [jobspec]
Place jobspec jobspec in the foreground, making it the current job. in the foreground, making it the current job.
jobs [ [jobspecs]
List jobspecs jobspecs on standard output. on standard output.
nohup [ [command] & Execute command command, detach it from the terminal, and allow it to continue running after the user logs out.
Objective 103.6: Modify Process Execution Priorities Concepts A process"s execution priority execution priority is managed by the kernel. is managed by the kernel.
You can bias the execution priority by specifying a nice number nice number in the range of 20 to +19 (default is 0). in the range of 20 to +19 (default is 0).
Positive nice numbers reduce priority; negative nice numbers increase priority and are reserved for the superuser.
Commands nice - -adjustment [ [command]
Apply nice number adjustment adjustment to the process created to run to the process created to run command command.
renice [+|-] [+|-]nicenumber targets Alter the nicenumber nicenumber, and thus the scheduling priority, of one or more running target target processes. processes.
Objective 103.7: Search Text Files Using Regular Expressions Concepts Regular expressions are used to match text. The term is used to describe the loosely defined text-matching language as well as the patterns themselves. A regular expression is often called a are used to match text. The term is used to describe the loosely defined text-matching language as well as the patterns themselves. A regular expression is often called a regex regex or a or a regexp regexp.
Regular expressions are made up of metacharacters metacharacters (with special meaning) and (with special meaning) and literals literals (everything that is not a metacharacter). (everything that is not a metacharacter).
The backslash character () turns off (escapes) the special meaning of the character that follows, turning metacharacters into literals. For nonmetacharacters, it often turns on some special meaning.
Position anchors The operators in Table10-7 Table10-7 match line position. match line position.
Table10-7.Regular expression position anchors
Regular expression Description ^ Match the beginning of a line.
$ Match the end of a line.