1 / 16

CMPSC 60: Week 5 Discussion

CMPSC 60: Week 5 Discussion. Topics for Today. Some Unix commands Unix shells. Find. Recursively search for files find . -name “*.txt” – list all files ending with “.txt” under the current dir find ~ -name ‘*.txt’ -maxdepth 2

keegan
Download Presentation

CMPSC 60: Week 5 Discussion

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. CMPSC 60: Week 5 Discussion

  2. Topics for Today • Some Unix commands • Unix shells

  3. Find • Recursively search for files • find . -name “*.txt” –list all files ending with “.txt” under the current dir • find ~ -name ‘*.txt’ -maxdepth 2 • Find files ending with .txt within home dir up to 2 levels deep • find / -type d -user cshiflet • find all directories on the server owned by cshiflet • find ~ -mtime -7 • find files under your home modified in the last 7 days (week)

  4. Find (cont.) • find ~ -size 0 -exec rm {} \; • Delete all zero length files under your home dir • find ~ -perm -006 -exec chmod o-rw {} \; • change all files under your home dir that can be read and written by all users so that they cannot

  5. Grep • search multiple files for a pattern • grep text * • print the lines of any files that have “text” in them • grep -r sometext * • same as before, searching recursively • grep -l sometext * • print only the filenames of files with “sometext”

  6. More Grep • grep -n ‘//’ *.cpp • print the lines from all .cpp files that have a ‘//’ in them, and print the line number it was found on • grep -v text file • print all the lines of file that do not have “text” in them • grep -i text * • print the lines of all files with “text” in them, insensitive to case

  7. Tar – Tape ARchive • Copy files to or from an archive • -x to extract • -t to test (list contents) • -c to create • -v to be verbose, print out what it’s doing • -f filename -- specifies input/output archive • -z -- gzip/gunzip the archive • -j -- bzip2/bunzip2 the archive

  8. Tar examples • tar -tzvf some.tar.gz • List the files in some.tar.gz • tar -xzf some.tar.gz • Extract the files in some.tar.gz to the current dir • tar -czf out.tar.gz indir/ • Compress the dir “indir” and all files in it into out.tar.gz

  9. Unix Shells • Program that launches at login and allows you to enter commands • Examples: • CSH / TCSH • BASH • SH • ZSH… and more

  10. CSH - Manipulating Variables • env - List all environment variables • set - Set a normal variable • set class = cs60 • setenv - Set an environment variable for the life of the shell (i.e. until you logout) • setenv PATH ${PATH}:/my/path/dir

  11. CSH - Important Env Variables • PATH - Directories to search when executing a program • HOME - Full path of your home directory • SHELL - Full path/name of your shell • HOSTNAME - Host the shell is running on • USER - User who invoked the shell (YOU)

  12. CSH - Important Normal Variables • prompt - Defines the prompt displayed • set prompt=“%M:%~%” • New prompt: host:~/current% • set prompt=“[%t] %M:%~%” • New prompt: [6:35pm] host:~/current% • Other prompt variables can be found by in the tcsh man page • history - Number of history commands stored • set history=100

  13. More prompt fun • %M – the machine you’re logged into • %~ – your current directory • %t – the current time • %n – your user name • %h – the current history event number set prompt = "\n%n@%M [%t] %~\n%h %

  14. CSH - Configuration Files • ~/.cshrc - Run whenever CSH is started • ~/.login - Run when you login with CSH • ~/.logout - Run when you logout

  15. CSH - ~/.cshrc • Used to setup initial: • PATH • prompt • aliases • User defined variables • Anything else you want every time you start CSH

  16. CSH - ~/.login • Put commands here that you only want execute when you first login

More Related