Exam EX200 All QuestionsBrowse all questions from this exam
Question 36

SIMULATION -

Search files.

Find out files owned by jack, and copy them to directory /root/findresults

    Correct Answer:

Discussion
kenkct

sudo su mkdir /root/findresults (create folder if doesn't exist) find / -user jack -type f -exec cp {} /root/findresults/ \; ls /root/findresults (to verify)

wizojlo

I have heard from several people that they encountered a slightly modified version of this question, where it was required to include all files with SUID permission. Just add -perm u=s in the command to do so. One person also had this question made so that it must be made into a shell script. So take note ;)

ly01

this is wrong. "find / -perm /u=s" is the correct form. You have to escape it otherwise you will only find files that have only that mode bit set. From the man: -perm mode File's permission bits are exactly mode (octal or symbolic). Since an exact match is required, if you want to use this form for symbolic modes, you may have to specify a rather complex mode string. For example `-perm g=w' will only match files which have mode 0020 (that is, ones for which group write permission is the only permission set). It is more likely that you will want to use the `/' or `-' forms, for example `-perm -g=w', which matches any file with group write permission. See the EXAMPLES section for some illustrative examples.

sugisho

[root@abc ~]# find / -user jack -type f -exec cp -rp {} /root/findfiles/ \; find: ‘/proc/3337/task/3337/fdinfo/6’: No such file or directory find: ‘/proc/3337/fdinfo/7’: No such file or directory cp: cannot create regular file '/root/findfiles/': Not a directory cp: cannot create regular file '/root/findfiles/': Not a directory cp: cannot create regular file '/root/findfiles/': Not a directory cp: cannot create regular file '/root/findfiles/': Not a directory # find / -user jack -type f -exec cp -rp {} /root/findfiles/\; find: missing argument to `-exec'

schwarztrinker

sudo -i for file in $(find / -user jack -type f); do cp $file /root/findresults/; done

cb52

mkdir -p /root/findresults find / -user jack -type f -exec cp -avrf {} /root/findresults/ \; ls -l /root/findresults

brahmimedamine

find / -user jack -type f -exec cp -rpvf {} /root/findresults\; 2> /dev/null

ifbaibz

mkdir /root/findresults find / -user jack -type f -exec cp -a {}/root/findresults/\: ls /root/findresults

vira5489

useradd -m jack mkdir /root/findresults find / -u jack -type f -exec cp -rfp {} /root/findresults \;

ANI_04

Can't we just do " find / -u jack -type f >> /root/findfiles " ?

sirasdf

No that won't copy the files that will just copy the results from the find command to a file. The solution is: find / -type f -user jack -exec cp -v {} /root/findresults \;

Stachomir

cp -rfp $(find / -type f -user jack) /root/findfiles/

xXxM__JxXx

whats the negative impact if i don't include -type f in the command?

Leepipes101

find / -user jack -exec cp -rfp /root/findfiles/ {} \;

rsebayang

find / -user jack -exec cp -rfp {} /root/findfiles/

cytron

You've forgotten the line termination \; Line should look like this find / -user jack -exec cp -rfp {} /root/findfiles/ \; # RHEL8

danielmaziarczyk

Also should be -type f "for files only" find / -user test -type f -exec cp -rp {} /root/findfiles/ \;

danielmaziarczyk

mistake should be: find / -user jack -type f -exec cp -rp {} /root/findfiles/ \

ms200

miss ; at the the end of the line

PTom

When you search for files only why do you need -r for cp command. The cp -r mean recursively copy directories. It's not an error but why?