skip to Main Content

we are running out of space on an expensive production NAS. We’ve decided to move all the files to our in house storage server and use the production NAS as a cache for our most streamed and listened to tracks.

Is there a way to delete every file with .m4a extension in specific root folder except ones listed in a .txt file?

The file has over 22.4k lines of absolute paths and the estimated size of files to be deleted is around 9.2TB

Haven’t find any efficient solution

2

Answers


  1. Not the most efficient solution, but it should get the job done. For each file, your "files to keep" text file is scanned.

    find "$yourrootfolder" -name '*.m4a' -exec sh -c '
      for file; do grep -Fqx "$file" keeplist.txt || rm -v "$file"; done
    ' - {} +
    

    Files are deleted without confirmation. Use at your own risk.

    Login or Signup to reply.
  2. I think it’s easier to simply act upon the listed files, rather than to check against the list when performing a separate action:

    mkdir tmpDir/
    while IFS= read -r fileName; do
        mv $fileName tmpDir/
    done < files_to_omit.txt
    rm -f *.m4a
    mv tmpDir/* .
    rmdir tmpDir/
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search