|
Reserved Words
|
|
|
if
|
then
|
else
|
elif
|
fi
|
|
case
|
esac
|
|
|
|
|
for
|
while
|
until
|
do
|
done
|
|
function
|
in
|
select
|
|
|
|
!
|
{
|
}
|
time
|
|
|
|
|
|
Job Control
|
|
|
|
|
command
|
Starts a command in the foreground.
|
|
command_A &
|
Starts command_A in the background. Inappropriate for interactive jobs (e.g. less.)
|
|
^Z
|
Suspends a running command.
|
|
jobs
|
Lists all jobs.
|
|
fg %n
|
Brings job n back into the foreground. Can be used without %n
|
|
^c
|
Interrupts a running job.
|
|
^\
|
Kills a running job. Use when ^c fails. Leaves core file.
|
|
command_A ; command_B
|
Starts command_A then starts command_B when command_A is complete. If commands become long, using the \ character splits the command line.
|
|
(A ; B) & (C ; D) &
|
Starts A followed by B concurrently with C followed by D. All jobs run in the background.
|
|
nohup command_A &
|
Starts command_A in the background ignores hangups.
|
|
|
|
|
Redirection
|
|
|
command_A | command_B
|
Sends std. output of command_A to command_B as std. input.Example: procinfo | elm username@someaddress.orgMails output of procinfo to username@someaddress.org
|
|
command > filename
|
Directs std. output of command_A to filename. Overwrites (clobbers) existing file.Example:rpm -qa | sort > installed_packagesSends output of rpm -qa (lists all installed packages) to the sort command and then sends the sorted output to the file installed_packages. (Note > is equivalent to 1> where 1 is the file descriptor for standard output. 2 is the file descriptor for standard error.)Example:startx > xerrors 2>&1 &Starts the X server and sends the standard output and standard error to the file xerrors.
|
|
command >> filename
|
Same as > except that it appends the data to filename if it already exists.
|
|
command < filename
|
Take input for command from filename.
Example:
elm s "RPM List" username@someaddress.org < installed_packages
Mails installed_packages file to username@someaddress.org with the title "RPM List."
|
|
command | tee filename
|
Sends output of command to filename and to standard output.
|
|
|
|
|
Filename Expansion (Globbing)
|
|
|
*
|
Matches any filename not starting with . (excludes "hidden" files.)
Example:
*.c Matches all files ending in .c
*c Matches all files ending with c
c* Matches all files starting with c
.c* Matches all files starting with .c ("hidden" files)
|
|
?
|
Matches any single character.
Example:
?ood Matches all files four characters long ending in ood Wood wood 1ood @ood
f? Matches all two charachters long starting with f fe fi fo fm
|
|
[]
|
Matches a range of characters.
Example:
[1-5] Matches 1-5
[c,o] Matches c or o
[c-o] Matches c through o
|
|
|
|
|
Command History
|
|
|
|
|
history
|
Lists previous commands.
|
|
!n
|
Executes command n from the command history.
|
|
!!
|
Executes previous command.
|
|
!string
|
Executes previous command starting with string.
|
|
!?string?
|
Executes previous command containing string.
|
|
|
|
|
Aliases
|
|
|
|
alias somecommand="someothercommand possible_modifiers"
|
Sets alias
|
|
unalias somecommand="someothercommand possible_modifiers"
|
Clears alias.
|
|
Aliases are usually set in .bashrc or /etc/bashrc
Interested in color ls? Add the line
alias ls="ls color=auto"
to your /etc/bashrc file and then
source /etc/bashrc
or reboot.
|
|
|
|
|
|
Emacs and the bash Shell
|
|
|
^a
|
Go to beginning of line.
|
|
^e
|
Go to end of line.
|
|
^w
|
Delete previous word.
|
|
^p
|
(History) Previous command.
|
|
^n
|
(History) Next command.
|
|
^k
|
Kill rest of line.
|
|
^b
|
Back one character.
|
|
^f
|
Forward one character.
|
|
^d
|
Deletes character. Exits bash at blank command line.
|
|
|
|