I'm trying to do as the title states. I have a server with a daily rotating movie list while I'm low on storage. I have a script that goes through and deletes the oldest .mp4. I'm left with left over files that were related to that movie just taking up space. I'd like to delete the entire folder.
Currently this is the code I have:
#Finds oldest *.mp4 and deletes it.
stat --printf='%Y %n\0' "$dir"/New_Movies/*/*.mp4 | sort -z | sed -zn '1s/[^ ]\{1,\} //p' | xargs -0 rm
The following is my failed attempt at finding directories that do not include *.mp4 nor have "!" in the directory name. Example name: "!Action".
for d in "$dir"/New_Movies/*/; do
if ! [ -e "*!*" ]; then
[ -f "$d"*.mp4 ] || printf '%s\n' "$d"
fi
done
While testing, I get 3 different outputs, one each time it's run.
Run 1: It gives me the correct directories as well as all the directories containing "!" (They are shortcuts so I assume they look empty).
Run 2: Same as above but a lot of "-bash: [: too many arguments " between each printf.
Run 3: Breaks the code and doesn't run.
After: Repeats from run 1-3 in order over and over.
Example of directory:
/New_Movies/
/New_Movies/*/index.php
/New_Movies/foo/foo.mp4, foo.jpg, foo.xml
/New_Movies/bar/bar.jpg, bar.xml
After running the script I should only have /New_Movies/foo and its contents left.
! [ -e "*!*" ]
suppose to do?*!*
seems to get expanded (the history of commands), so I don't think it's doing what you think it's doing. That's why you get different results every time.