bash/. character... denotes your parent directory. It is the directory containing your current directory, unless you are at the root of the file system, in which case the parent directory is the root itself./ separates the directories on the path to your target file or directory.~ character denotes your home directory. It is where you are put when you start a terminal session. In general ~user denotes the home directory of user user.sh — the Bourne shellcsh — the C shelltcsh — the Tenex C Shellksh — the Korn Shellbash — the Bourne-again shellzsh — the Z shellbash) since it is the default shell on the OS X machines in our lab.The format of a bash simple command is
command [flags] [arguments]
where white spaces (blanks or tabs) separate the components. e.g.
$ ls
$ cp *.txt novelHowever, bash is a fullblown scripting language as well as an interpreter. It has regular expressions, conditionals, loops, and functions, e.g.,
$ for f in ch[1-3].ps
do
ps2pdf $f
doneenter key.A valid command is either internal or external. The shell understands an internal command and is able to execute it immediately. Examples of internal commands are
$ pwd
$ alias l=“ls -l”
If the shell does not understand a command, it assumes that it is an external command, and will search all directories as specified in the PATH variable for a file having that command as name. If the file is found and is executable, the shell loads it into memory and executes it. Examples of external commands are
$ ls
$ head file
ls — list files and directoriescd — change directorypwd — print working directorymkdir — make directoryrmdir — remove directoryrm — remove files and directoriesmv — move (or rename) files and directoriescp — copy files and directoriescmp — check if two files are the samediff — list all differences between two filesecho — echo command line argumentscat — concatenate filesless — browse text filesman — read manual page for external commands, system calls, and C APIinfo — similar to manhelp — ask for help with internal commandsnano and TextEdit (in plain text mode).TextWrangler and Sublime Text.emacs and vim.The command
runsprog < infile
prog with its stardard input coming from infile.The command
prog > outfile
runs prog with its stardard output redirected to outfile. If outfile does not exist, it will be created with content of the output from prog. If outfile exists, its old content will be overwritten by the output from prog.
The command
prog >> outfile
runs prog with its stardard output redirected to outfile. If outfile does not exist, it will be created with content of the output from prog. If outfile exists, its content will have the output from prog appended to its old content.
The command
prog1 | prog2
has the effect of running both prog1 and prog2 in parallel, but with the stardard output of prog1 being the stardard input of prog2.