0

I'm having a little trouble putting this all together...

I want to make a simple shell script to organize and sort around 60 GB worth of music and movie files that are spread out over 3 or for 4 directories.

I need to separate the .mp3, .wma, Video, etc. files from the erroneonus files and junk don't need. I want to send these straight into a new directory with the audio and video files separated. I'm moving them too a new psychical device, a SD card I bought. I want to accomplish all this from the terminal.

My question is this.. what is the best way to chain all these commands together?

Do I use grep to search for files that end with a suffix str like .mp3 and then pipe the results of that >> to anewfile.txt ?

Or would find be better for that task? Or neither?

I've read documentation for countless hours before asking, because I don't want to waste anyone's time but nothing I try works. I can't seem to get a comprehensive result on my own. When I try and put all of this into a comprehensive practical script to do some simple file manipulation, it fails. I get lost in the man pages.. I need dialogue with folks who I have experience.

This is what my stuff looks like:

cd Volumes/../music/*filesIwant* ; grep -i `'.mp3, .wma'` >> '*new.dir/\Music \Movies*

And frankly a lot of variations of stuff like that can't get it flow...

Any help would be greatly appreciated.

This is what my scripts look like

cd ../hdd_music/ ; cp 

My question: Is this the best way?

1
  • Why is this question tagged bash and zsh? These are two largely different shells.
    – Cyrus
    Commented Sep 23, 2023 at 21:05

1 Answer 1

0

A tool that might work for this is zmv, since it has way to test out a file move command without actually changing anything. Try these commands in zsh:

autoload zmv
cd /Volumes/.../music
zmv -n '*filesIwant*.mp3' '/.../newdir/Music/'
zmv -n '*filesIwant*.wma' '/.../newdir/Music/'
zmv -n '*filesIwant*.mpg' '/.../newdir/Movies/'

With the -n option, the command will just report the file moves that would occur, but not execute them. With the option set, you can experiment with possibilities until finding something that works. Note that the file names and directory names with ... in the examples above are just a placeholders the exact names on your system; the ... is not part of the syntax.

Some quick notes:

  • The underlying command for zmv and for moving files is mv. The basic syntax for that command is something like mv subdir/file.mp3 anotherdir/file.mp3.
  • The cd (change directory) command does not normally use wildcards like * and ?. Just enter something like cd /Users/zjs/Documents.
  • The >> and > symbols are used to change the destination of the printed output and messages; you don't need this in a move command.

Stack Exchange / Super User isn't set up well for an initial dialog about how to approach issues and choose paths; it's really better for more specific questions and answers. You may have better luck with sites that have longer articles about these topics, like this one.

Good luck!

You must log in to answer this question.

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