简体   繁体   中英

How to traverse a directory structure to find files

I am trying to create a script that will traverse through my music directory and eventually convert anything over 192bps to 192bps. So far I have the following...

#!/bin/bash

music="/backup/MUSIC/AC-DC/Back In Black"

for file in `find "$music" -type  f -name '*.mp3'`; do
        echo "$file" | cut -d/ -f6-
done

but I am getting weird output , like 1 word per line, and not even the entire file name. I don't understand what the cut -d/ -f6- is for either...

Any help is appreciated.

Try using a while loop instead:

#!/bin/bash

music="/backup/MUSIC/AC-DC/Back In Black"

find "$music" -type f -name "*.mp3" | while read file; do
  echo "$file"
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM