I would like to move all files except fora specific one to the trash on a mac from a single directory.
Instead of moving the files and folders within that directory I would like all files and folders to be moved individually to the trash. For this directory:
~/Desktop/script.sh
~/Desktop/File1
~/Desktop/Folder/File2
I would like script.sh to stay on the desktop but for the trash directory to have three elements inside it like this:
~/.Trash/File1
~/.Trash/Folder
~/.Trash/File2
I have found extglob
and for the purposes of my task I will enable and disable it within my script. I am using find
as I would like to move all directories and files and files within directories and when placed into trash I would like all the files and directories to be standalone. As in I would like a file that was in a directory to be outside that directory.
This is the code I have created and I am getting no errors.
shopt -s extglob
find ~/Desktop/ \( !('script.sh') \) -print0 |
while IFS= read -r -d '' f;
do mv -- "$f" ~/.Trash ;
done
shopt -u extglob
echo Complete!
My question is find
the right command for me to use for this task and if so where am I going wrong as I am able to successfully complete my task save for getting files individually sorted rather than in there parent directories within the trash.