find and locate

Search for file on mounted file systems using the find and locate commands.

Syntax:

find <location> -user <username> -exec <komanda> <tapilan_fayllar> \;

Task 1:

Find the files owned by harry, and ccopy it to cataog: /opt/dir

Solution:

mkdir -p /opt/dir
find / -user harry -exec cp -rfp {} /opt/dir/ \;

Task 2:

Find all files owned by user 'alex' and redirect the output to /home/alex/files

Solution:

find / -user alex -type f > /home/alex/files

Task 3:

Find all sizes of 10K file or directory under the /etcdirectory, and copy to /tmp/findfilesdirectory. Then, find all files or directories with Lucy as the owner, and copy them to /tmp/findfiles

Solution:

find /etc -size 10k -exec cp -r --parents {} /tmp/findfiles \;
find / -user Lucy -exec cp -r {} /tmp/findfiles \;

Last updated

Was this helpful?