Delete all empty directories found with find
bash |copy code |?
1 find -depth -type d -empty -exec rmdir {} \;
Delete all empty directories found with find
bash |copy code |?
1 find -depth -type d -empty -exec rmdir {} \;
Get the size of the current directory (.) or another one (foldername) with du command.
bash |copy code |?
1 du -sh .2 du -sh foldername
How to find if a directory exists in bash:
bash |copy code |?
1 DIR="/etc"2 if [ -d $DIR ]; then3 echo "Folder ${DIR} exists"4 else5 echo "Folder ${DIR} does NOT exists"6 fi
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:
bash |copy code |?
1 $ ls -lrt | awk '{ f=$NF }; END{ print f }'
Reverse ordering with ls and then getting the first line:
bash |copy code |?
1 $ ls -t1 | head -n1