I need find and copy files in /usr/share/man
Especialy need man7-8 and everything that have "et" in name. I try this:
ls man7 man8 | grep "et"
This works perfectly.
Than i want that files copy with cp but i dont know how to format it properly
ls man7 man8 | grep "et" | xargs -I '{}' cp '{}' /home/marty/homework
But this is not working
It's not working because ls directory
just outputs the filenames, without the directory prefixes. So cp
doesn't know what directory to copy the file from.
But there's need for ls
or grep
, just use a wildcard.
cp man7/*et* man8/*et* /home/marty/homework
Your code would also fail for any filenames containing whitespace, since xargs
treats that as a delimiter by default.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.