Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home...
-
Upload
percival-bond -
Category
Documents
-
view
227 -
download
1
Transcript of Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home...
Find basics.
• find ~ -name myfile –print• find directory criteria• This will search the home directory (~) looking
for files whose name (-name) is myfile and displays them (-print)
• You need to say –print if you want to print out the names of files.
Finding Files
• find . -user root -exec wc {} \;• executes wc on all files in cwd owned by user
root• {} is shorthand for the name of that file. • the ; (must be escaped with a \) • terminates the action to be taken.
Remove – with care
• find . -name "this*" -exec rm {} \;• This will remove all the files matching “this*”,
starting in the current directory (.)• Be careful with this sort of command!
Pass find to my script.
• find . -name "myfile*" -exec myFileProcessor.sh {} \;• I can pass what I want to myFileProcessor.sh• echo file is $1• echo "I can do what I want to the file here“• file is ./myfile• I can do what I want to the file here• file is ./myfile2• I can do what I want to the file here
Arguments to Find
• Arguments are of 3 kinds• options which affect behavior• tests which specify which files are to be
selected• action specify what is to be done to the
selected files.
Tests Used by Find
• -empty, file is empty• -links n, file has n hard links• -inum n, file's inode is n• -name pattern, filename matches pattern• -perm mode, file permissions are exactly mode• -size n, file has size blocks of 512 bytes• -type c, file is type c• -user name, file owner is name
Do not forget this webpage
http://find.unixpin.com/There are lots of other good tutorial “out there”Find is one of the hardest commands to master.
Ssh – secure shell
• Other tools are rlogin, rsh, rcp – but these are not used because of security issues.
• Ssh is probably the most popular of these tools.
• A key is sent, so both machines can communicate with encrypted information.
Ssh example
• $ whoami• zlizjw1• ssh [email protected]• It is a criminal offence to secure unauthorised
access to any program or ……• pat$ whoami• jrw• pat$
To exit
• pat$ exit• logout• Connection to cs.nott.ac.uk closed.• [zlizjw1@unnc-cslinux ~]$ whoami• zlizjw1• [zlizjw1@unnc-cslinux ~]$
Non-interactive
• We can just send commands• ssh –l login remote.machine.name command• For example• ssh -l jrw cs.nott.ac.uk mkdir SSHDIRJOHN• There are lots more to this. • This is just the basics.
Secure copy (scp)
scp SourceFile user@host:directory/TargetFile• scp A.TXT [email protected]:SSHDIRJOHN/A.TXT• [email protected]'s password:• A.TXT 100% 0 0.0KB/s 00:00• pat$ cd SSHDIRJOHN/• pat$ ls• A.TXT• pat$
Gzip, gunzip, Compression
• gzip is short for GNU zip• for the compress program used in early Unix
systems, intended for use by the GNU Project• www.gzip.org• Compression is very important in computer
science.
BEFORE
• ls -l• -rwxr--r-- 1 zlizjw1 Domain U 228785 Mar
17 11:05 canonical.pdf• -rw-r--r-- 1 zlizjw1 Domain U 4485370 Mar
17 11:05 canonical.ps
AFTER gzip
• $ gzip canonical.p*• $ ls -l• total 744• -rwxr--r-- 1 zlizjw1 Domain U 201204 Mar
17 11:05 canonical.pdf.gz• -rw-r--r-- 1 zlizjw1 Domain U 548712 Mar
17 11:05 canonical.ps.gz
AFTER gunzip
• gunzip canonical.p*• ls -l• total 4624• -rwxr--r-- 1 zlizjw1 Domain U 228785 Mar
17 11:05 canonical.pdf• -rw-r--r-- 1 zlizjw1 Domain U 4485370 Mar
17 11:05 canonical.ps
Archive, tar• tape archive• standardized by POSIX.1-1988 and later
POSIX.1-2001. • it is now commonly used to collect many files
into one larger file, for distribution or archiving, while preserving file system information such as user and group permissions, dates, and directory structures.
• .
• http://www.gnu.org/software/tar/• A tar file or compressed tar file is commonly
referred to as a tarball
Create a tar file
• tar cvf myTarfile files• c for create• v for verbose• f to specify tarfile• For example• Tar cvf UST.tar *• Will tar everything in your working directory
into a file called tar