Find and delete empty files and directories

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:
    Need to make a script, to remove all empty files and folders from current category.
    It also should show the name and creation date of those items.

  2. Relevant commands, code, scripts, algorithms:
    Must be bash script.

  3. The attempts at a solution (include all code and scripts):

Tried this, but it shows only name of deleted folders...

echo Removed files:
find . -maxdepth 1 -type f -empty;
find . -maxdepth 1 -type f -empty -exec rm {} \;
echo Removed directories:
find . -maxdepth 1 -type d -empty;
find . -maxdepth 1 -type d -empty -exec rmdir {} \;

Then I tried using

ls

... But it gave too much information.. I just need name and creation time (Ok.. Creation time isn't stored in UNIX.. So I think a date of last modification would be enough.. )

echo Removed files:
find . -maxdepth 1 -type f -empty -exec ls -l;
find . -maxdepth 1 -type f -empty -exec rm {} \;
echo Removed directories:
find . -maxdepth 1 -type d -empty -exec ls -l ;
find . -maxdepth 1 -type d -empty -exec rmdir {} \;

But in this code first of all it shows only info about files.. For some reason it doesn't show anything about folders. And secondly: That's not that I need. I need name and date (maybe date, maybe date+time) of creation (last modification).

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Vilniaus Kolegija, Vilnius, Lithuania, M.Liogys, PIN11.

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Maybe you need the "-d" switch to "ls" to make "ls" show the directory not its contents. For consistency the "-d" also works with files.

find . -maxdepth 1 -type f -empty -exec ls -lad {} \;
find . -maxdepth 1 -type d -empty -exec ls -lad {} \;

Obviously be aware that "rm" on a file changes the "last modified" time on the directory which holds that file.

Thank you.
I really appreciate your help :slight_smile: