Presentation is loading. Please wait.

Presentation is loading. Please wait.

OCCC CS – Linux – Fall ‘07 Find Command and Links

Similar presentations


Presentation on theme: "OCCC CS – Linux – Fall ‘07 Find Command and Links"— Presentation transcript:

1 OCCC CS2183-001 – Linux – Fall ‘07 Find Command and Links
by Gary Miller September 4, 2007

2 Find Cmd Examples find . –print
List out all files under the current directory find . -type f -ctime +10 -exec mv {} /tmp \; Move and files older than 10 days find . -type f -ctime -10 -exec ls –lia {} \; 2>/dev/null List any files newer than 10 days

3 Soft and Hard Links Soft links
Pointers to programs, files, or directories located elsewhere (just like Windows shortcuts) If the original program, file, or directory is renamed, moved, or deleted, the soft link is broken.  If you type ls -F you can see which files are soft links because they end To create a soft link called myfilelink.txt that points to a file called myfile.txt, use this: ln -s myfile.txt myfilelink.txt

4 Soft and Hard Links Hard links
Pointers to programs and files, but NOT directories If the original program or file is renamed, moved, or deleted, the hard link is NOT broken Hard links cannot span disk drives, so you CANNOT have a hard link on /dev/hdb that refers to a program or file on /dev/hda To create a hard link called myhardlink.txt that points to a file called myfile.txt, use this: ln myfile.txt myhardlink.txt

5 Find Broken Links Description
Code: (Bash) find . -type l | (while read FN ; do test -e "$FN" || ls -ld "$FN"; done) Code: (Just using find utility and test) find / -type l ! -exec test -r {} \; -print Description The find command finds all symbolic links in the current directory, “.”, and writes their names to its standard output. That gets piped into the parenthesized while loop, which tests each link. If the link points to an existing file, nothing happens, but if the link's target does not exist, the ls command gets executed and detailed information about the link and its intended target are sent to the standard output.


Download ppt "OCCC CS – Linux – Fall ‘07 Find Command and Links"

Similar presentations


Ads by Google