1

I want to move all my FLAC music folders to a new folder called lossless. Currently the FLAC folders are inside a folder with lossy formats such as MP3 and AAC.

I want to filter the folders with "flac" in their name and move them to a new directory.

How can I achieve this?

2
  • 2
    mv *flac* /path/to/lossless?
    – Sparhawk
    Jul 24, 2018 at 10:54
  • @Sparhawk *flac*/, to match directories.
    – Kusalananda
    Jul 24, 2018 at 14:08

3 Answers 3

1

You can use:

 mv *flac* directory_name

The *flac* is a file expansion (not regex, thanks Sparhawk for the correction) for file names containing the word 'flac' within any number of characters so it would capture:

  • hello_flac.mp3
  • file.format_flac_somerandomwords
  • music_file.flac

If you just want files ending in .flac use

mv *.flac directory_name

0
0

Try,

find /path/to/flac -type d -iname '*flac*' -exec mv -t /path/to/newDirectory {} +
2
  • The issue with moving folders with find is that you'll remove folders from the search paths that find may expect to be able to enter. In the example in your code, the first folder that would have been moved is /path/to/flac (since it matches the criteria). You would then get lots of "file not found" errors. To mitigate this, use -mindepth 1 (to avoid the top folder) and -depth (to do a depth-first traversal of the hierarchy).
    – Kusalananda
    Jul 24, 2018 at 14:05
  • Assuming you used -mindepth 1 and -depth, you also do not check whether a folder with the same name exists at the destination. The two folders /path/to/flac/A/flacdir and /path/to/flac/B/flacdir would collide.
    – Kusalananda
    Jul 24, 2018 at 14:05
0

Assuming we're dealing with a single top-level directory where these folders are to be found:

mv -i somefolder/*flac*/ path/to/lossless

This would move all folders that has the string flac in their names ot the indicated target folder, while alerting you when trying to overwrite anything already existing on in the target directory.

By adding / at the end of the filename pattern, we only match directories. This way we will not move any regular files that would have matched the pattern without the trailing /.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .