1 / 147

UNIX/Linux

UNIX/Linux. CIS140U Winter 2009 Gary DeRoest. Schedule (general). Part 1: Ways to automate alias, script files, join, awk Part 2: Tools to organize pipes, redirection, grep, uniq, comm, sed, pr, cut, sort, tr Part 3: bash tools if, then, else, test, case, for,

art
Download Presentation

UNIX/Linux

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. UNIX/Linux CIS140U Winter 2009 Gary DeRoest Gary DeRoest

  2. Schedule (general) Part 1: Ways to automate alias, script files, join, awk Part 2: Tools to organize pipes, redirection, grep, uniq, comm, sed, pr, cut, sort, tr Part 3: bash tools if, then, else, test, case, for, let, while, tput cup Part 4: Building an application Gary DeRoest

  3. Schedule (general) Part 5: Installation - SLES 9 YAST, YOU, tar, rpm, cpio Part 6: Boot/Service/User Configuration setup, chkconfig, service Part 7: User/Group configuration tools useradd, usermod, userdel groupadd, groupmod, groupdel GUI tools Part 8: Configuration Documentation Gary DeRoest

  4. Schedule (general) Part 9: Process Management fg, bg, jobs, ps, top Part 10: Administration Responsibilities Part 11: Security Concerns Gary DeRoest

  5. Alias’s A keyboard shortcut for frequently used or long commands. Aliases are processed before internal and external commands Gary DeRoest

  6. Alias Examples For Bash Shell • alias c=‘clear’ • alias ll=‘ls -lA | more’ • alias dir=‘c; ls -l’ • alias cd=‘who -iH’ • cd • unalias cd • alias Gary DeRoest

  7. Viewing All Aliases • alias [garyd@bct2 bin]$ alias alias l.='ls -d .[a-zA-Z]* alias ll='ls -l --color=tty' alias ls='ls --color=tty' alias vi='vim' [garyd@bct2 bin]$ Gary DeRoest

  8. Remembering Aliases Aliases can be set automatically each time you log in Your home directory contains a hidden file named .bashrc which is the usual place where users define aliases .bashrc is executed each time you log in. Any alias definitions will then be defined automatically Gary DeRoest

  9. ~/.bashrc An unmodified .bashrc file might look like this # .bashrc # User specific aliases and functions # Source global definitions if [ -f /etc/bashrc]; then . /etc/bashrc fi Gary DeRoest

  10. .bashrc - Adding Your Own Stuff A modified .bashrc file might look like this # .bashrc # User specific aliases and functions alias c=‘clear’ alias md=‘mkdir’ alias cp=‘cp -i’ # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi Gary DeRoest

  11. /etc/bashrc • Aliases are generally assigned by individual users • Administrators may wish some aliases set for all users • Global aliases are set in a file in the /etc directory • /etc/bashrc • /etc/bashrc is owned and modified by root Gary DeRoest

  12. FAQ I changed my .bashrc file - so why aren’t my aliases working? The .bashrc file is executed when you log into the server. Making changes to .bashrc will not be noticed until you exit and log back in to the server Gary DeRoest

  13. Creating Files • cat>filename • ^d • >filename • touchfilename • vifilename • picofilename • pico -w filename • command>filename • command>>filename Gary DeRoest

  14. Warm-up Activity Gary DeRoest

  15. Script file • A sequence of UNIX commands that you wish to execute can be saved to a text file • This text file must be executable • This text file should be in a directory named in the search PATH • The files ~/.bashrc and ~/.bash_profile are two examples of bash shell scripts (or programs) Gary DeRoest

  16. Bash Scripts viscript1 clear echo -n Welcome to my world. date save the file :x make the file executable chmodu+x script1 execute the program [gd@bct2~]$ script1 or [gd@bct2~]$ ./script1 Gary DeRoest

  17. Bash Scripts In addition to executing external programs like‘who’,‘cal’,and‘sort’,each UNIX or Linux shell has its own set of internal commands and functions. cd, alias, echo, history, set, fg, test, andpwdare internal commands to the bash shell and my not be available in other shell programs. Gary DeRoest

  18. File Management Commands mkdir cp paste rmdir mv cut rm sort grep Gary DeRoest

  19. File Processing Commands awk comm cat cut chmod diff join grep select commands paste head manipulate & transform pr tail sort uniq sed wc tr Gary DeRoest

  20. User must have write permission for the parent directory to create sub-directories mkdir command • cd • mkdir programs • mkdir /user • mkdir ~/files • mkdir /programs/bin • mkdir -p stuff/cis140u Gary DeRoest

  21. rmdir command Cannot delete non-empty Directories With rmdir command • cd • rmdir programs • rmdir /programs/user • rmdir ../../directory Gary DeRoest

  22. cp command • cp fileA fileZ • cd mystuff/fileB yourstuff/ • cp fileC morestuff • cp /junk/*.txt yourstuff • cp -i fileA fileB • cp -r /home/stuff ~/mystuff Gary DeRoest

  23. mv command • mv fileA fileZ • mv mystuff/fileB yourstuff/ • mv fileC morestuff • mv /junk/*.txt yourstuff • mv -i fileA fileB • mv -r /home/stuff ~/mystuff If you cannot delete a file you cannot move it Gary DeRoest

  24. rm command • cd • rm “file name with spaces” • rm-i LinuxWebSites • treehouse • rm-ri house Gary DeRoest

  25. Combining Files output cat dog crow frog bird bear cat fileA fileB file A cat dog crow fileB frog bird bear Gary DeRoest

  26. Combining Files output cat frog dog bird crow bear file A cat dog crow pastefileA fileB fileB frog bird bear paste fileA fileB > fileC paste fileA fileB > “my file” Gary DeRoest

  27. Combining Files output cat:frog dog:bird crow:bear paste –d”:” fileA fileB file A cat dog crow output cat frog dog bird crow bear fileB frog bird bear paste –d”\n” fileA fileB Gary DeRoest

  28. Splitting Files fileC cat:frog:blue dog:bird:black crow:bear:white output frog bird bear cut–f2 –d”:” fileC output cat:blue dog:black crow:white cut–f1,3 –d”:” fileC Gary DeRoest

  29. Splitting Files fileC cat:frog:blue dog:bird:black crow:bear:white cut–c2,5 fileC output af ob r: cut–c2-5,8 fileC output at:fg og:bd row:a Gary DeRoest

  30. Sorting Files sort fileC fileC cat:frog:blue dog:bird:black crow:bear:white output cat:frog:blue crow:bear:white dog:bird:black Gary DeRoest

  31. Sorting Files fileC cat:frog:blue dog:bird:black crow:bear:white sort -t: -k2 fileC sort -t: +1 fileC output crow:bear:white dog:bird:black cat:frog:blue Gary DeRoest

  32. Sorting Files fileC cat:frog:blue dog:bird:black crow:bear:white sort -t: -k1.3 fileC output dog:bird:black crow:bear:white cat:frog:blue Gary DeRoest

  33. Sorting Files sort fileD output 100 20 3 fileD 100 3 20 output 3 20 100 sort -n fileD Gary DeRoest

  34. Search through Files fileE John Henry Joe Montana Henry Ford Sam the Eagle grep “John” fileE output John Henry Gary DeRoest

  35. Search through Files grep -i “h” fileE fileE John Henry Joe Montana Henry Ford Sam the Eagle output John Henry Henry Ford Sam the Eagle Gary DeRoest

  36. Search through Files output 2 grep -c “n” fileE grep -n “y” fileE output 1 John Henry 3 Henry Ford fileE John Henry Joe Montana Henry Ford Sam the Eagle grep “[HS]” fileE output John Henry Henry Ford Sam the Eagle Gary DeRoest

  37. Search through Files grep “Jo..” fileE output John output John Joe Henry Sam fileF John Joe Henry Sam grep “...” fileE output Joe Sam grep -x “...” fileE Gary DeRoest

  38. joincommand Used to combine files using key fields. Relational database tools. 4 Greg 1 Gary 2 Paul 3 Sam 2 McCartney 3 the Eagle 1 DeRoest 4 Brady Gary DeRoest

  39. join command Step one: Sort files on their key fields first last 1 Gary 2 Paul 3 Sam 4 Greg 1 DeRoest 2 McCartney 3 the Eagle 4 Brady Gary DeRoest

  40. join command Step two: use the join command to link key fields and display desired output. join -a1 -1 1 -2 1 -o 1.2 –o 2.2 first last 1 Gary 2 Paul 3 Sam 4 Greg 1 DeRoest 2 McCartney 3 the Eagle 4 Brady Gary DeRoest

  41. join command join –a1 –1 1 –2 1 –o 1.2 –o 2.2 first last 1 Gary 2 Paul 3 Sam 4 Greg File 1 to be joined with file 2 File 1 has key in column 1 File 2 has key in column 1 Print out from file 1, field 2 Print out from file 2, field 2 1 DeRoest 2 McCartney 3 the Eagle 4 Brady Names of file 1 and file 2 Gary DeRoest

  42. join command join –a1 –1 1 –2 1 –o 1.2 –o 2.2 first last 1 Gary 2 Paul 3 Sam 4 Greg 1 DeRoest 2 McCartney 3 the Eagle 4 Brady Gary DeRoest Paul McCartney Sam the Greg Brady Gary DeRoest

  43. join command join –a1 –1 1 –2 1 –o 1.1 –o 2.2 first last 1 Gary 2 Paul 3 Sam 4 Greg 1 DeRoest 2 McCartney 3 the Eagle 4 Brady 1 DeRoest 2 McCartney 3 the 4 Brady Gary DeRoest

  44. join command join –a1 -t: –1 1 –2 1 –o 2.2 –o 1.1 first last 1:Gary 2:Paul 3:Sam 4:Greg 1:DeRoest 2:McCartney 3:the Eagle 4:Brady DeRoest 1 McCartney 2 the Eagle 3 Brady 4 Gary DeRoest

  45. join command 1:Gary 2:Paul 3:Sam 4:Greg join –a1 -t: -e “No Match” –1 1 –2 1 –o 1.2 –o 2.2 –o 1.1 first last 1:DeRoest 2:McCartney 4:Brady Gary DeRoest 1 Paul McCartney 2 Sam No Match 3 Greg Brady 4 Gary DeRoest

  46. join command 1:Gary 2:Paul 3:Sam 4:Greg join –a1 -t: -e “No Match” –1 1 –2 1 –o 1.2 –o 2.2 –o 2.1 first last 1:DeRoest 2:McCartney 4:Brady Gary DeRoest 1 Paul McCartney 2 Sam No Match No Match Greg Brady 4 Gary DeRoest

  47. join command 1:Gary 2:Paul 3:Sam 4:Greg join –a2 -t: -e “No Match” –1 1 –2 1 –o 1.2 –o 2.2 –o 2.1 first last 1:DeRoest 2:McCartney 4:Brady Gary DeRoest 1 Paul McCartney 2 Greg Brady 4 Gary DeRoest

  48. join command join-a2 -t: -e "No Match" -1 3 -2 2 -o 2.3 –o 1.2 file1 file2 file1 1:Apple:Washington 2:Pineapple:Hawaii 3:Orange:Florida 4:Grape:Oregon file2 1:Oregon:Salem 2:Washington:Olympia 3:Florida:Tallahassee 4:California:Sacramento 5:Hawaii:Honolulu Gary DeRoest

  49. join command join-a2 -t: -e "No Match" -1 3 -2 2 -o 2.3 –o 1.2 file1 file2 output Salem:No Match Olympia:Apple Tallahassee:No Match Sacramento:No Match Honolulu:Pineapple Gary DeRoest

  50. join command join-a2 -t: -e "No Match" -1 3 -2 2 -o 2.3 –o 1.2 file3 file4 file3 3:Orange:Florida 2:Pineapple:Hawaii 4:Grape:Oregon 1:Apple:Washington file4 4:California:Sacramento 3:Florida:Tallahassee 5:Hawaii:Honolulu 1:Oregon:Salem 2:Washington:Olympia Gary DeRoest

More Related