More Shell Features
Process Control
- An
&
at the end of a command line will run the command as a background process - Typing
<Ctrl-Z>
will stop a foreground process - Typing
<Ctrl-C>
will (usually) kill a foreground process - A stopped process may be made to run in the background by
typing
bg
- A background or stopped process may be brought to the
foreground by the
fg
command. jobs
displays all background and suspended processes of the current shellkill
will kill a process using the number returned byjobs
or the process ID (found with theps
command)
I/O redirection
- To capture output from a command, redirect "standard
output" with
>
ls myDir >/tmp/myDir.txt ls: myDir: No such file or directory
- To capture output including error messages, redirect "standard
output" and "standard error" with
&>
ls myDir &>/tmp/myDir.txt
- To read responses from a file redirect "standard input"
with
<
pipelines
The output of one command can be piped to the input of another command with the|
symbol.
ls|wc -l 14
Directory Manipulation
- Make a new directory
mkdir newDirectory
- Change current directory
cd newDirectory
- Change back to last directory
cd -
- What is my current directory
pwd
- Current directory is
.
and parent directory is..
Changing permissions
- 3 classes of user -- user (the owner), group, and other
- 3 basic permissions -- read (r), write (w) and execute (x)
- Programs/scripts MUST have the execute bit set in order to run
chmod
-- Change permissions of a file or directory
chmod u+x fileName # Give owner execute permission chmod g+w fileName # Give group write permission chmod go-rwx filename # Remove permissions from all but owner
Previous section: Shell Basics
Next section: Basic Utilities