I have a directory in my home drive. Within this directory, there are several hundred subdirectories. In each of these subdirectories, there are several types of files, of which I want to take ONE of these types, and move all those files to a single directory. (In this case they are .ttf files that I want to move to ~/.fonts/, but I have wanted to do this in the past with .mp3 files to a USB Drive, so I’ve decided to investigate a bit harder.
Now, I don’t mind using the command line occasionally, so I thought something along the lines of cd ~/fonts/ would do the trick, but it doesn’t. It cannot find *.ttf. I’ve had a read of both the cp man page and the wikipedia entry, but it appears cp doesn’t do this.
cp -r *.ttf ~/.fonts/
Before I go away and attempt to write some sort of script to do this, just wondered if anyone could tell me how to do this, or if it is even possible, with ’standard’ tools?
{ 8 } Comments
If I understand what you’re asking, I think this will do:
cd ~/fonts
fine -iname ‘*.ttf’ -exec cp ‘{}’ ~/.fonts/ \;
and when I say ‘fine’ I really mean ‘find’
That solution will run cp once per font. I suspect there’s a way to use xargs to use only a single invocation of cp.
The best way that I can see is:
(find ~/fonts -iname ‘*.ttf’; echo ~/.fonts) | xargs cp
The `echo` is to put the destination at the end of the argument list. Is there a better way to do this, anyone?
Omahn: With that, nothing gets copied
Will: With that I get
cp: missing destination file operand after `/home/sheepeatingtaz/.fonts'But thanks for the help, it is appreciated.
Hows about renaming the fonts dir?
Martin: I could, but I want to get rid of the subdirectories, so that all the font files are together in one directory, and I want to NOT copy other files that are in the subdirectories.
I’ll try and catch you tomorrow in #lugradio – that command should work.
(as in, it works for me)
Pinched from Grifferz:
$ cd ~/fonts$ find . -type f -iname '*.ttf' -print0 | xargs -I{} -0 cp {} ~/.fonts/
Post a Comment