Unix Notes for Tutorialv4.Doc Page 1 JFW Unix Notes for Tutorial Inclusion – from OS-X Unix Tutorial V4.Doc from P 10 Which Ls
Total Page:16
File Type:pdf, Size:1020Kb
Unix Notes for Tutorial Inclusion – From OS-X Unix Tutorial v4.doc From p 10 which ls reports where the ls command is found ls -lt long list sorted by time modified ls –h sometimes give help on a command like ls ls .. directory listing of next higher directory touch .hidden creates a hidden file name .hidden if it does not exist, modifies the date if it does exist ls ../.. directory listing of two levels up man tcsh > <file> put man entry for tcsh command into file <file> mv –i <file1…> <file2> rename file1 to file2; if it would overwrite, ask first; if -f then don't ask, just overwrite if needed. rm –i <file1> <file2> delete file1 and file2; ask first to verify; -d to del empty dir as well as files; -f attempts to override permissions, but gives no errors -r delete dir and everything in it, implies -f; -P delete & scrub 3 x echo rm -r * display command as it would actually be executed for each file matched, but no deletions sudo rm -r /Users/Jim\ Deleted danger: admin allowed delete of all of Users/"Jim Delete" mv <file> ~/.Trash/ move file to the desktop trash bin, rather that direct delete From p 19 alias trash mv \:\* ~/.Trash/ creates new command which translates to mv <parameters> ~/.Trash history display the command history file less ~/.tcsh_history look at history in less format !59 recall command #59 from history to command line p20,26 notes on creating new defaults for command via alias p22 pushd <dir> push the <dir> onto the directory stack popd pop the top directory entry on the stack to the command line pushd ~ push to home directory onto the stack dirs –v print the directory stack, one directory per line pushd –v popd –v pushdsilent no stack printed on a pushd or popd man tcsh you can search this for info on pushd and popd mkdir –p <dir> create directory with all nec intermediate directories mkdir –p a/b/c/d create directory d with any of a, b, c if needed ls –R list directory of current working directory recursively example:**** mkdir –p one/too/for/three create a nest of directories mv one/too one/two correct spelling error; too->two mv one/two/for/three one/two ?? mv one/two/for one/two/three/four move dir for from under two to under three and simultaineously correct spelling Unix Notes for Tutorialv4.doc Page 1 JFW ls –R one check current nest ******* p24 mkdir –p a/b/c/d create a nest of dirs rmdir –p a/b/c/d if empty remove the nest of dirs ls –ld <dir> lists not contents of dir but details of dir note: on a mv a trailing slash means treat as if a dir, e.g. mv path1/two path2/ p26 ls b[aeiou]g list dir for dirs bag, beg, big, bog, bug rm .txt does ls [mt]*day[0-9] matches m or t followed by day followed by a digit cp –R <dir> <dir2> copies dir and nested dirs (and files) below to dir2 rm –ri <dir2> deletes the files in dir2 and the subdirectorys but asks for confirmation first rm –r * deletes everything in currect directory; if entered at top level (root) deletes everything without asking for confirmation note: danger*** cp does not copy resource forks; use command ditto rm –rf danger: removes recursively without warning, even if not normally allowed to delete p28 du ~ report size of every dir from home down; units at blocks – 512 bytes = 1/2 k; so divide by 2 to get in units of k du –sk ~ print a single line of total size of directory in units of k df –k show how full each disk and partition is in units of k ls –aF display each file with a trailing character to indicate file type ls –Fsk display each file with file type and file size in units of k file <file> determine file type last reports who loged in since last cleanup, when and what p30 user ; primary group= staff, admin, wheel, shadowy users = daemon, nobody, unknown, www, root spare user—with admin access good idea p31 permissions as three triplets read (r) write (w) execute (x) owner group other r w x r w x r w x Applications/ directory , only admin user can add items, others can read and execute only rwxrwxr-x /System/Library/ only root owner can modify this; others and even those in admin group can only read and execute. rwxr-xr-x ls –l <dir> lists contents of dir with permissions ls –ld <dir> examines the enclosing directory, i.e. the directory itself chmod <who> =<prot> <file> Unix Notes for Tutorialv4.doc Page 2 JFW who can be owner (u), group (g), other (o) prot can be either a set of prots to be enabled or +<prots> to add or -<prots> to disable chmod u=rwx <file> set read, write and execute for owner chmod g=rx <file) set read and execute for group chmod o = r <file> set only read for others chmod u=rwx, g=rx,o=r <file> set all three as stated chmod o-r <file> disable the read on other chmod g+w <file> add write to group chown <user>:<group> <file> chown :admin <file> new group is admin chown weiher:staff <file> new user owner is weiher, new group owner is admin; needs sudo and admin PW p34 /Users/Shared everyone can write to it but only as an append. Note this has the sticky bit (t) set drwxrwxrwt . Others can add to the directory (w) but not remove any files. ~/Public/ others can read but not write ~/Public/Drop\ Box/ others can write and execute, but not read note Finder shows root as System, sounds more Mac-like ~<another user>/ shortcut of home of another user nidump passwd / shows all users nidump group / shows all groups note: in single user mode, these are held as flat files in /etc/passwd and /etc/groups as in many other UNIX systems passwd to change your password id gives your UID, user name, primary GID, group name and list of all groups to which you belong. P38 Shells- The shell is your interface to the UNIX OS; it listens for input, launches other programs as found in the command line, displays output of those programs. Displays a prompt, keeps a command history, allows auto completion, includes framework to enable piping and a scripting language. The Terminal is an Aqua program that runs the shell for you. It adds the cut and paste, drag and drop complete path-filenames, etc for ease of use The Bourne shell (sh) is in every UNIX system, good scripting system, poor interactives csh was an improvement on sh but scriping is different tcsh was a further improvement incorporating many OS-features that DEC developed in their PDP-6, 10, Tops-10 etc systems. Good interactives but different scripting than sh (is default for OSX10.1 and 10.2 bash incorporated many improvements of previous systems, retaining excellent interactive behavior but with a scripting system upward compatible with sh (bourne again shell) is default for OSX10.3 Unix Notes for Tutorialv4.doc Page 3 JFW p40 head *.txt display first 10 or so lines the each file with extension .txt head –25 /var/log/system.log display first 25 lines of system log tail /var/log/system.log display last 10 or so lines of system log tail –f /var/log/system.log display last 10 or so lines of system log but leave it open and display any additions to the file (a command line equivalent of the aqua console program.) ctrl-c to end P41 locate <pattern> using the locate database find all files matching the given pattern. This database is updated weekly if your computer is on all the time. If it is not you need to run the update yourself from the command line (see chrontab) or use a shareware program, Cocktail. Normally the pattern is in quotes. Legal wild cards are *, ?, [] but the pattern must be in quotes and have an asterisk in front. If unquoted and no * before or after the given string it is sent to locate with an asterisk at the start and and the end locate “bio” If an explicit string is given any match anywhere is found locate “Bio.*”If a wild card is included, then the exact absolute path only is searched, so if nothing at top level it will not be found. locate bio is the same as locate “*bio*” or “bio” locate bio.* because not quoted and one (so it is not “*bio*”, the * is expanded by the shell to get the name in the current directory that match a ls of bio.*. If that is more than one the list is sent to locate which fails because locate can take only one argument. If there is only one such entry however, it is sent to locate, and locate finds that item. Note: to see the glob expansion of the shell before executing a command before entering the return, enter ctl-X followed by *. The expanded version will replace the glob pattern locate "Bi[Go]" will not find anything because it includes wildcards and not * at front. locate "*Bi[Go]" will find anything ending in BiG or Bio anywhere locate "*Bi[Go]*" will find any file anywhere containing BiG or Bio locate "MLP*" will not find anything because no * at front locate "*MLP?P" will locate any file ending in MLP(any char)P P42 find [options] <start-dir> [pattern] [action] runs a live search of the file system, from the start- dir down.