I have a folder called "Music" which is my parent folder. This folder contains alot of .mp3- and .m4a-files, some in the root of the folder and others in subfolders that can have several subfolders.
How do I use terminal on my Mac to recursively move all files from the subfolder, up into the root of my Music folder and replace existing/duplicate files?
Thanks!
have a good backup ;-) Seriously!
cd to your Music folder
type find . -type f -iname '*.mp3' -mindepth 2 -print0 | xargs -0 -I{} mv -n '{}' .
Related
The parent directory has 5 sub folders, each subfolder has .mp4s, .txt, and other file extensions, how to be in the parents folder and enter a terminal command to only pull all *.mp4s into another specified folder in Bash.
find /path/to/src -type f -name “*.mp4” | xargs -iF mv F /path/to/dst
I stand in the specified parent directory and move the files to the other specified folder that I assume is ../other-spec-dir ( a folder that is not in the search path of find)
find . -type f -name "*.mp4s" -exec mv {} ../other-spec-dir \;
Note that if there are files with identical name only the last one will survive.
Little help in solving a workflow with shell script using the find command.
Finding all index.html files in every folder.
We can use this with find command for that.
find ./ -type f -name 'index.html'
Renaming the file index.html with the folder names.
After renaming the files, I wanted to move the files one level up.
I'm stuck at renaming and moving the files one level up.
As I have more than 100k files, Xargs will be handy for this.
Here is code I have so far
find ./ -type f -name 'index.html' | xargs -P 4
Any help in in renaming the index.html files and moving the files one level up?
Instead of xargs you can use find -exec. Inside, you can run a small sh-Script:
find . -mindepth 2 -type f -name 'index.html' -exec sh -c '
d="$(dirname "$1")";
mv "$1" "$d/../$(basename "$d").html";
rmdir "$d";
' find-sh {} \;
Received the help from Askubuntu forum for it :)
Reference : https://askubuntu.com/questions/1236564/find-index-html-files-rename-with-folder-name-and-move-file-a-level-up
I have files of type mp3 and flac. Lets say my basic directory structure is
/music/artist/album
I have (already) made
/music/artist/album/flac/
/music/artist/album/mp3/
with a recursive batch operation.
I want to loop through all of /music/ and do the following:
If /music/artist/album/ has mp3s, move them to /music/artist/album/mp3/.
If /music/artist/album/ has flacs, move them to /music/artist/album/flac/.
Some folders have mp3 and flac. Looking for either script file or command line solutions
find /music/ -name '*.mp3' -execdir mv {} mp3/ \;
find /music/ -name '*.flac' -execdir mv {} flac/ \;
-execdir runs the specified command in the directory of the current file. This lets you use mp3/ and flac/ directories relative to the current artist/album.
Here you have one way to do it :
find /music -type f -name "*.mp3" | xargs mv $1 /music/artist/album/mp3/
find /music -type f -name "*.flac" | xargs mv $1 /music/artist/album/flac/
Hope it works for you.
Greetings!
Change the current directory to where your music files are, then move mp3s to the mp3 folder and flacs to the flac folder.
cd /music/artist/album/
mv *.mp3 mp3/
mv *.flac flac/
On my Mac I amm trying to move hundreds of files on my NAS drive, from a parent directory with a load of subdirectories (and possibly directories inside them) and put all of the files into one folder.
They don't have the same file extension for all the files.
Is anyone able to help with the terminal command I need to do this? So far I know that find . -type f will list all the files in the directory and subdirectories but Im unsure how to tell it to get them to move them all into another folder.
For anyone else who may have this same issue:
Ive managed to extract just the .jpg's and put them in the parent folder.
find . -type f -iname '*.jpg' -mindepth 2 -print0 | xargs -0 -I{} mv -n '{}' .
Not quite what I wanted - I was hoping to get every single file and put it into a completely different folder if possible but this has got me further than before.
Go inside the source parent directory and use:
find . -type f -exec mv "$PWD"/{} <destination directory> \;
If you want to move all the files to parent directory itself, use it as the destination directory.
I have a directory structure like this:
news_images folder -> subfolder with current date ex. 20140626 -> files
I would like to remove all subfolders with files inside news_images directory that are older than 3 days.
This does remove only files inside news_images directory but do not touch the subfolders.
find news_images -mtime +3 -exec rm {} \;
Did you try to find only subdirectories of news_images (then remove them recursively) ?
Something like (not tested but I think it should work):
find news_images -mindepth 1 -maxdepth 1 -mtime +3 -type d -exec rm -r {} +
rm without options is not able to delete directories. Try option -r.