SIMULATION -
Search files.
Find out files owned by jack, and copy them to directory /root/findresults
SIMULATION -
Search files.
Find out files owned by jack, and copy them to directory /root/findresults
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)
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 ;)
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.
[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'
sudo -i for file in $(find / -user jack -type f); do cp $file /root/findresults/; done
mkdir -p /root/findresults find / -user jack -type f -exec cp -avrf {} /root/findresults/ \; ls -l /root/findresults
find / -user jack -type f -exec cp -rpvf {} /root/findresults\; 2> /dev/null
mkdir /root/findresults find / -user jack -type f -exec cp -a {}/root/findresults/\: ls /root/findresults
useradd -m jack mkdir /root/findresults find / -u jack -type f -exec cp -rfp {} /root/findresults \;
Can't we just do " find / -u jack -type f >> /root/findfiles " ?
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 \;
cp -rfp $(find / -type f -user jack) /root/findfiles/
whats the negative impact if i don't include -type f in the command?
find / -user jack -exec cp -rfp /root/findfiles/ {} \;
find / -user jack -exec cp -rfp {} /root/findfiles/
You've forgotten the line termination \; Line should look like this find / -user jack -exec cp -rfp {} /root/findfiles/ \; # RHEL8
Also should be -type f "for files only" find / -user test -type f -exec cp -rp {} /root/findfiles/ \;
mistake should be: find / -user jack -type f -exec cp -rp {} /root/findfiles/ \
miss ; at the the end of the line
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?