Top Banner
Find http://find.unixpin.com/
22

Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

Jan 01, 2016

Download

Documents

Percival Bond
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

Find

http://find.unixpin.com/

Page 2: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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.

Page 3: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for 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.

Page 4: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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!

Page 5: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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

Page 6: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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.

Page 7: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for 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

Page 8: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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.

Page 9: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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.

Page 10: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

Ssh example

• $ whoami• zlizjw1• ssh [email protected]• It is a criminal offence to secure unauthorised

access to any program or ……• pat$ whoami• jrw• pat$

Page 11: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

Example mailx

• pat$ mailx -s "hi from UK" [email protected]

• how is Ningbo• EOT• pat$

Page 12: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

To exit

• pat$ exit• logout• Connection to cs.nott.ac.uk closed.• [zlizjw1@unnc-cslinux ~]$ whoami• zlizjw1• [zlizjw1@unnc-cslinux ~]$

Page 13: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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.

Page 14: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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$

Page 15: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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.

Page 16: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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

Page 17: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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

Page 18: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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

Page 19: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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.

• .

Page 20: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

• http://www.gnu.org/software/tar/• A tar file or compressed tar file is commonly

referred to as a tarball

Page 21: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

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

Page 22: Find . Find basics. find ~ -name myfile –print find directory criteria This will search the home directory (~) looking for files.

Extract from tar file

• To extract the contents from a tar file• Tar xvf tarfile• This extracts the files from the tarfile• X is for extract• T is to give a table of contents.