Common Unix Concepts and Commands --------------------------------- Shell - way to interact with Unix - line-oriented - syntax: commandName arg1 ... argN - separated by spaces - some args are options, typically prefixed by hyphens Shell-related commands chsh - change shell to e.g. /bin/csh, /bin/tcsh, /bin/bash passwd - change password Directories and files - directories contain files and other directories - form a tree - a directory is a kind of file; anything that can be done to a file can be done to a directory - each user has their own *home directory* - shell has a *current directory* - starts with home directory when log in File names - can be arbitrary length, contain arbitrary characters - / and space treated specially, unless "escaped" Path names - can name files in directories by using dirName/fileName - if fileName is itself a directory, can keep going - use / as separator, starting with outermost directory name - start with / to be *absolute*, otherwise relative to current directory - . names current directory - .. names enclosing directory - ~ names current user's home directory - ~user names user's home directory Directory-related commands ls - list files in current directory - add -a to get names starting with . ls ... - list files in named directories mkdir ... - create directories cd - go to named directory cd - go to home directory pwd - print current directory File-related commands cat ... - print out contents of files more ... - same, but a page at a time less ... - less is more, more or less mv - move/rename a file (overwriting any existing toName) cp - copy a file (overwriting any existing toName) mv ... - move files to given existing directory cp ... - copy files to like-named files in directory [Dangerous!] rm ... - remove files rmdir ... - remove (empty) directories rm -r ... - remove files and directories (and their contents) emacs - start emacs editor emacs - start emacs editor, start editing file [On Cygwin:] notepad - start notepad editor, start editing file lpr ... - print files out to current printer lpr -P ... - print files to named printer lpq - print out current printer's queue lpq -P - print out named printer's queue Getting info on commands man - print documentation about command man -k - print list of manuals mentioning keyword Permissions - every file/directory has an *owner* (a user) and a *group* (a predefined collection of users, e.g. ugrad_cs or fac_cs) - owner is initially the user that created the file - group is typically inherited from enclosing directory's group - every file/directory has a collection of permissions - separate permissions for each of owner, members of group, or anyone - read permission: can look at contents, or list directory's contents - write: can change contents, or create & remove files in directory - execute: can invoke as a program, or cd into directory Permissions-related commands ls -l ... - long listing, including permissions chmod - change permissions of file (only owner) u, g, o - user/owner, group, other/anyone +, - - turn on, turn off r, w, x - read, write, execute permission chgrp - change group of file (only owner) groups - list user's groups Filename patterns - can use patterns to name a bunch of files - embedded in regular filenames - some patterns: - * matches a sequence of 0 or more characters - ? matches exactly 1 character - [...] matches any 1 of the characters in the brackets - [-] matches any 1 of the characters in the range - can combine char sets inside brackets - {,...,} matches any of the subpatterns - a subpattern can be empty, allowing no matches - expand argument containing patterns into multiple real arguments, based on matching file/pathnames Shell variables - can define (and redefine) variables in shell - csh/tcsh: set ... = ... =(...) ... - bash: = - can look at or remove settings set - print out all vars and their values unset ... - undefine var - also have environment variables; subtly different than shell vars - csh/tcsh: setenv unsetenv ... - can reference variables on command line - $ expands into - some variables control the shell's behavior; do man csh/bash - e.g. path, prompt, nonomatch, notify, autolist, history, filec - some variables provide configuration settings - e.g. HOME, USER, SHELL echo ... - print out arguments Path - Unix finds commands, programs using the path (or PATH) variable - not using file extensions! - conceptually, a list of directories to search to find programs being run - csh/tcsh: - set path = ( ... ) - bash: - PATH=::...: - when the shell sees ... , it: - first expands $, *, ~, etc. in s - takes first word, e.g. and tries to run it - if it's a path name, then searches for just that file - if it's a single word, then searches the path for a file with that name in the directories, in order - if find program, verify it's executable, then run it - note: in csh/tcsh, whenever add new programs to a directory in path, execute rehash command so that shell will notice it's there Saving customizations - when logging in, shell automatically runs start-up commands in initial script - csh/tcsh: in ~/.cshrc - bash: in ~/.bash_profile - put any commands you want to run every time you log in there Quoting - can turn off special treatment of some characters by quoting - e.g. spaces, *, ?, [..], $ - single quotes disables all special treatment inside - double quotes still allows $ expansion - \ before character disables just that character (except $!) - \\ means \ - \ at end of line disables the newline, allowing commands across lines