How to get backup of all the files having a specific format in linux


I want to copy every .ttf file to current working directory but nothing seems to happen.

I am currently using this command :

find / | grep .ttf | xargs cp .

The detection is fine, if i run find / | grep .ttf it gives me the exact location
of every .ttf file in my disk.
but it just doesn’t work with xargs cp .

I already tried this method to delete every file containing a word like this:
find / | grep chrome | xargs rm -rf

The method is fine, So what am i missing ?

>Solution :

The syntax is cp <source> <destination>. When you use xargs cp . it expands to cp . <files found> which is why it doesn’t work.

If your cp supports -t option, you can use xargs cp -t . since -t helps you specify the destination directory. But I’d suggest to use find+exec and this will also avoid issues due to shell metacharacters in filenames:

find / -name '*ttf' -exec cp -t . {} +

Leave a ReplyCancel reply