Linux tools

In order to get the list of sorted folders size with folder name on  level 1, I figured out a method which would be helpful all admins.

du -h --max-depth=1 <<folder name>>| perl -e 'sub h{%h=(K=>10,M=>20,G=>30);($n,$u)=shift=~/([0-9.]+)(\D)/;
return $n*2**$h{$u}}print sort{h($b)<=>h($a)}<>;'

Note : Please change <<folder name>> with the required directory path.


In order to make this file immune to editing and deleting we need to use command “chattr”. Chattr changes the attributes of a file on Linux System.

The Syntax of command chattr, for the above purpose is:

# chattr +i example.txt

Now try to remove the file using normal user.

$ rm -r example.txt 

rm: remove write-protected regular empty file `example.txt'? Y 
rm: cannot remove `example.txt': Operation not permitted

Now try to remove the file using root user.

# rm -r example.txt 

cannot remove `example.txt': Operation not permitted

Shred tool overwrites a file repeatedly several times, thus making file recovery for any illegal activity almost nil and practically impossible.

# shred -n 15 -z topsecret.txt

shread – overwrite a file to hide its contents, and optionally delete it.

  1. -n – Overwrites the files n times
  2. -z – Add a final overwrite with zeros to hide shredding.

Note: The above command overwrites the file 15 times before overwriting with zero, to hide shredding.


This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *