Delete all empty directories found with find
find -depth -type d -empty -exec rmdir {} \;
Tag: directory
-
Delete empty directories
-
Getting size of a directory using du
Get the size of the current directory (.) or another one (foldername) with du command.
du -sh .
du -sh foldername -
Bash check if a directory exists
How to find if a directory exists in bash:
DIR="/etc"
if [ -d $DIR ]; then
echo "Folder ${DIR} exists"
else
echo "Folder ${DIR} does NOT exists"
fi -
Find latest file in a directory methods
Sometimes there are so many files in a directory that it’s hard to find the last file in the directory. We show you here 2 ways for finding it out.
With awk we print the last argument of the last line:
$ ls -lrt | awk '{ f=$NF }; END{ print f }'Reverse ordering with ls and then getting the first line:
$ ls -t1 | head -n1