140 likes | 247 Views
BASH Shell Primer. Scott Russell IT Support Engineer Distributed Support Services Office of Information Technologies. Basic Shell Commands. ls -- list directory contents touch -- change file access and modification times (create files) mkdir -- make directories cp -- copy files
E N D
BASH Shell Primer Scott Russell IT Support Engineer Distributed Support Services Office of Information Technologies
Basic Shell Commands • ls -- list directory contents • touch -- change file access and modification times (create files) • mkdir -- make directories • cp -- copy files • mv -- move (rename) files • grep -- print lines matching a pattern • man -- format and display the on-line manual pages
ls Applications Library Pictures Desktop Movies Public Documents Music Sites
ls -aFlh drwxr-xr-x 64 srussel2 srussel2 2K Jun 28 22:04 ./ drwxr-xr-t 4 root admin 136B Jul 7 2006 ../ -rw-r--r-- 1 srussel2 srussel2 21K Jul 10 20:11 .DS_Store drwx------ 4 srussel2 srussel2 136B Jul 10 20:34 .Trash/ -rw------- 1 srussel2 srussel2 11K Jul 9 20:21 .bash_history -rw-r--r-- 1 srussel2 srussel2 797B Jan 5 2007 .profile drwx------ 3 srussel2 srussel2 102B Jul 15 2006 .ssh/ -rw------- 1 srussel2 srussel2 6K Jun 28 20:59 .viminfo drwx------ 78 srussel2 srussel2 2K Apr 26 15:28 Applications/ drwx------ 26 srussel2 srussel2 884B Jun 20 19:13 Desktop/ drwx------ 92 srussel2 srussel2 3K Jul 10 20:44 Documents/ drwx------ 53 srussel2 srussel2 1K Jan 3 2006 Library/ drwx------ 12 srussel2 srussel2 408B Sep 6 2006 Movies/ drwx------ 11 srussel2 srussel2 374B Jan 7 2006 Music/ drwx------ 31 srussel2 srussel2 1K Jan 4 2007 Pictures/ drwx------ 7 srussel2 srussel2 238B Dec 20 2003 Public/ drwx------ 47 srussel2 srussel2 1K Aug 18 2006 Sites/
touch and mkdir touch file.txt touch file{1,2,3}.txt mkdir ~/BASH\ Primer mkdir -p ~/Projects/BASH\ Primer
cp and mv COPY cp old_script.sh ~/Applications/new_script.sh MOVE mv old_script.sh ~/Applications/new_script.sh RENAME mv old_script.sh new_script.sh
grep grep <string to find> <file(s)> grep dscl ~/Applications/UNIX/*.sh adduser.sh: ASSIGNED=`dscl localhost -list /NetInfo/Users uid | grep $UNIQUE_ID` adduser-panther-new.sh: ASSIGNED=`dscl localhost -list /NetInfo/Users uid | grep $UNIQUE_ID` changeHome.sh: sudo dscl localhost -change /Users/$1 NFSHomeDirectory "$OLDHOME" "$NEWHOME” adduser-panther-new.sh: dscl localhost create /users/$USERNAME grep ^\# ~/Applications/UNIX/*.sh
man dscl NAME dscl -- Directory Service command line utility SYNOPSIS dscl [options] [datasource [command]] options: -p prompt for password -u user authenticate as user -P password authentication password -raw don't strip off prefix from DirectoryService API constants -url print record attribute values in URL-style encod- ing -q quiet - no interactive prompt
man -k uuidapropos uuid mbr_uid_to_uuid(3), mbr_gid_to_uuid(3), mbr_uuid_to_id(3), mbr_sid_to_uuid(3), mbr_uuid_to_sid(3) - translate user and group identifiers from one form to another uuid(3) - DCE compatible Universally Unique Identifier library uuid_clear(3) - reset value of UUID variable to the NULL value uuid_compare(3) - compare whether two UUIDs are the same uuid_copy(3) - copy a UUID value uuid_generate(3), uuid_generate_random(3), uuid_generate_time(3) - create a new unique UUID value uuid_is_null(3) - compare the value of the UUID to the NULL value uuid_parse(3) - convert an input UUID string into binary representation uuid_unparse(3) - convert an UUID from binary representation to a string uuidgen(1) - command-line utility to generate a new UUID value
Environment Variables • printenv = print out the environment • HOME, USER • PWD, OLDPWD • PATH
Configuring Your Prompt PS1='\h:\w \u\$ ' Scott-Russells-iBook-G4:/etc srussel2$ \h = hostname to the first “.” \w = present working directory \u = current user http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html
Handful of BASH Utils • bbman -- converts man pages to plain text and opens them in your favorite text editor • smb.sh -- mount NetFile drives using mount_smbfs • touchx -- creates a new executable with boilerplate text in a default folder and opens it for editing http://www.nd.edu/~srussel2/macintosh/bash/
BASH Resources • Advanced BASH Scripting Guide • http://tldp.org/LDP/abs/html/ • PDF and HTML versions available • AWK One-Liners • http://unixnotes.wordpress.com/2006/03/15/awk-one-liners/ • NDMAC Home Page • http://www.nd.edu/~ndmac/