Introduction to Bash/Shell (Continued)
-
File Commands (continued)
wc <filename>
tells you how many lines, words and characters there are in a file
chmod -options <filename>
lets you change the read, write, and execute permissions on your files
gzip <filename>
compresses files
gunzip <filename>
uncompresses files compressed by gzip
gzcat <filename>
lets you look at gzipped file without actually having to gunzip it
-
File Commands (continued)
lpq
check out the printer queue
lprm <jobnumber>
remove something from the printer queue
genscript
converts plain text files into postscript for printing and gives you some options for formatting
dvips <filename>
print .dvi files (i.e. files produced by LaTeX)
grep <pattern> <filenames>
looks for the string in the files
grep -r <pattern> <dir>
search recursively for pattern in directory
-
SSH, System Info & Network Commands
ssh user@host # connects to host as user
ssh -p
whoami # returns your username
passwd # lets you change your password
quota -v # shows what your disk quota is
date # shows the current date and time
cal # shows the month’s calendar
uptime # shows current uptime
w # displays whois online
finger
ping
Input/Output Redirectors.
cmd1|cmd2
pipe; takes standard output of cmd1 as standard input to cmd2
> file
directs standard output to file
< file
takes standard input from file
>> file
directs standard output to file; append to file if it already exists
>|file
forces standard output to file even if noclobber is set
n>|file
forces output to file from file descriptor n even if noclobber is set
<> file
uses file as both standard input and standard output
n<>file
uses file as both input and output for file descriptor n
<<label
here-document
n>file
directs file descriptor n to file
n<file
takes file descriptor n from file
n>>file
directs file description n to file; append to file if it already exists
n>&
duplicates standard output to file descriptor n
n<&
duplicates standard input from file descriptor n
n>&m
file descriptor n is made to be a copy of the output file descriptor
n<&m
file descriptor n is made to be a copy of the input file descriptor
&>file
directs standard output and standard error to file
<&-
closes the standard input
>&-
closes the standard output
n>&-
closes the ouput from file descriptor n
n<&-
closes the input from file descriptor n
Process Handling
- To suspend a job, type CTRL+Z while it is running. You can also suspend a job with
CTRL+Y
. - This is slightly different from
CTRL+Z
in that the process is only stopped when it attempts to read input from terminal. - Of course, to interrupt a job, type
CTRL+C
.
myCommand &
runs job in the background and prompts back the shell
jobs
lists all jobs (use with -l to see associated PID)
fg
brings a background job into the foreground
fg %+
brings most recently invoked background job
fg %-
brings second most recently invoked background job
fg %N
brings job number N
fg %string
brings job whose command begins with string
fg %?string
brings job whose command contains string
kill -l
returns a list of all signals on the system, by name and number
kill PID
terminates process with specified PID
ps
prints a line of information about the current running login shell and any processes running under it
ps -a
selects all processes with a tty except session leaders
trap cmd sig1 sig2
executes a command when a signal is received by the script
trap "" sig1 sig2
ignores that signals
trap - sig1 sig2
resets the action taken when the signal is received to the default
disown <PID|JID>
removes the process from the list of jobs
wait
waits until all background jobs have finished
tar xvzf passwd reset special notations (. and ..) file tree history grep input/output redirection ps du df uptime vi basics scp md5