CMPSC 60: Week 5 Discussion

advertisement
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
–

find / -type d -user cshiflet
–

Find files ending with .txt within home dir up to 2 levels deep
find all directories on the server owned by cshiflet
find ~ -mtime -7
–
find files under your home modified in the last 7 days (week)
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
Grep


search multiple files for a pattern
grep text *
–

grep -r sometext *
–

print the lines of any files that have “text” in them
same as before, searching recursively
grep -l sometext *
–
print only the filenames of files with “sometext”
More Grep

grep -n ‘//’ *.cpp
–

grep -v text file
–

print the lines from all .cpp files that have a ‘//’ in them, and
print the line number it was found on
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
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
Tar examples

tar -tzvf some.tar.gz
–

tar -xzf some.tar.gz
–

List the files in 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
Unix Shells


Program that launches at login and allows
you to enter commands
Examples:
–
–
–
–
CSH / TCSH
BASH
SH
ZSH… and more
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
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)
CSH - Important Normal Variables

prompt - Defines the prompt displayed
–
set prompt=“%M:%~%”

–
set prompt=“[%t] %M:%~%”

–

New prompt: host:~/current%
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
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 %
CSH - Configuration Files



~/.cshrc - Run whenever CSH is started
~/.login - Run when you login with CSH
~/.logout - Run when you logout
CSH - ~/.cshrc

Used to setup initial:
–
–
–
–
–
PATH
prompt
aliases
User defined variables
Anything else you want every time you start CSH
CSH - ~/.login

Put commands here that you only want
execute when you first login
Download