1 / 13

BASH Shell Primer

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

trista
Download Presentation

BASH Shell Primer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BASH Shell Primer Scott Russell IT Support Engineer Distributed Support Services Office of Information Technologies

  2. 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

  3. ls Applications Library Pictures Desktop Movies Public Documents Music Sites

  4. 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/

  5. touch and mkdir touch file.txt touch file{1,2,3}.txt mkdir ~/BASH\ Primer mkdir -p ~/Projects/BASH\ Primer

  6. 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

  7. 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

  8. 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

  9. 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

  10. Environment Variables • printenv = print out the environment • HOME, USER • PWD, OLDPWD • PATH

  11. 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

  12. 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/

  13. 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/

More Related