Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 .

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 . {} +
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading