What bash command would search through a folder with multiple folders and extract *.ttf to a single folder?
What bash command would search through a folder with multiple folders and extract *.ttf to a single folder?
MS skill level -- I press buttons and stuff happens
Linux skill level -- I copy and paste into the terminal and stuff happens!
Mac skill level -- Wear a black turtleneck and stuff happens
from the current directory try the following but make a backup before you try it!
copy
moveCode:find . -name "*.ttf" -exec cp "{}" /dir \;
Code:find . -name "*.ttf" -exec mv "{}" /dir \;
Last edited by sohlinux; April 15th, 2012 at 09:22 PM.
Fatal Error: Found MS-Windows System -> Repartitioning Disk for Linux...
deleted by edit, because on rereading I realize I misunderstood the question. Please ignore this dumb post.
Last edited by Dreamer Fithp Apprentice; April 16th, 2012 at 06:43 AM.
Thanks. I remember reading that the copy command also pastes? Just need to find where they ended up....![]()
MS skill level -- I press buttons and stuff happens
Linux skill level -- I copy and paste into the terminal and stuff happens!
Mac skill level -- Wear a black turtleneck and stuff happens
.bash_history file stores commands you entered
Code:grep 'find.*-exec' .bash_history
+1 for sohlinux's solution.
However, I would add a little cavet: since you'll be copying or moving from several directories, it is possible that two different files have the same file name. For instance:
Then when moved or copied to dir/, they will be overwritten (just the last one will survive). As a safe measure, you can use the -b option (either on cp or mv). That will create a copy of the file before overwritten it.Code:$ ls -R file.ttf adir/file.ttf
For example:
Cavet's cavet: sadly this will only save the last two copies. If there's a 3rd, or more, file with the same filename, just the last two will survive.Code:find . -name '*.ttf' -exec mv -b '{}' dir/ \;
Just s few thoughts.
Regards.
I did a backup so duplicates won't be an issue. No duplicate files turned up. The grep command gave a no file found.
returned (the last example)Code:find . -name '*.ttf' -exec mv -b '{}' dir/ \;
Which is odd because it worked the first time.Code:mv: cannot move `./lora/Lora-BoldItalic.ttf' to `dir/': Not a directory
When I went to nautilus and put in /dir no dir was found. Should mkdr be used to create an output folder?
MS skill level -- I press buttons and stuff happens
Linux skill level -- I copy and paste into the terminal and stuff happens!
Mac skill level -- Wear a black turtleneck and stuff happens
The target directory has to exist.
In sohlinux's example it was /dir Thats a directory under the root directory (/).
Sorry if I created confusion, but in my example I used a local directory just under the command is executed. To created that directory run:
I hope that clarify things a little bit.Code:mkdir dir
Regards.
Thanks that worked.
Could someone explain all the parts of that command.Code:find . -name '*.ttf' -exec mv -b '{}' /home/username/Documents/newfonts \;
Last edited by tadcan; April 16th, 2012 at 10:08 PM.
MS skill level -- I press buttons and stuff happens
Linux skill level -- I copy and paste into the terminal and stuff happens!
Mac skill level -- Wear a black turtleneck and stuff happens
find <dir> -name <filenames-pattern>
-exec = for each found object perform the following:
mv -b {} destination_dir
{} is a placeholder for the name of the found object
-exec is ended with escaped \; or ';' so it knows where the inner command ends
Bookmarks