From my code below, I am to search for files of size zero, and prompt the user to delete them, if they so wish. However I am lost as the script should allow for directories to be specified as command line parameters. I must use the current directory as default, if no directory is specified on the command line. I think I am on the right track, but can not seem to figure out how to prompt the user to enter the path to the file he wishes to delete.
#!/bin/bash
ls -lR | grep '^-' | sort -k 5 -rn
echo "Files of size zero, relative to current directory, are as follows:"
find . -size 0 -print
echo "Would you like to delete the files of size zero?: Type yes or no"
read answer
if [[ $answer == "yes" ]]
then
find . -type f -empty -delete
echo "List of files with size zero files deleted:"
ls -lR | grep '^-' | sort -k 5 -rn
else
echo "User wishes to not delete files"
fi
ls
line are just there for debug. However you will not get a list of deleted files, by looking at existing files (theecho
andls
, in the then clause). – ctrl-alt-delor Jul 02 '18 at 21:52ls
line are just there for debug. Do not tell the user ”User wishes to not delete files”, they know (and this is very un-Unix). – ctrl-alt-delor Jul 02 '18 at 21:52