Linux Blog

Cleaning Up Files & Directories

Filed under: Shell Script Sundays — TheLinuxBlog.com at 8:30 am on Sunday, August 19, 2012

While not really a shell script as such, this is shell related and  it just so happens to be Sunday.

Find Empty Directories:

find . -type d -empty > empty_folders.txt

Find Empty Files

find . -type f -empty > empty_files.txt

The issue with these two commands is that within my jumble of unorganized mess I have an abundance of version control repositories (mostly SVN) and tons of source code with empty, but needed directories. Fear not if you have the same problem, you can filter them out by using:

grep -v empty_files.txt svn

Duplicate File Removal

There are multiple ways to remove duplicate files. I used to think a  recursive md5sum script was the way to go but that was before I found the utility fdupes.
Install via your package manager if it’s available and use recursively like:

fdupes -r [directory] > duplicates.txt

With fdupes you also have the ability to symlink or delete files, although because of the amount of source code, I’d rather review it manually.


With these utilities I was able to merge copies of photos remove a bunch of old files and empty directories and am one step closer to being digitally organized. If you have the same problem, hopefully they will help you too. If you have any cleanup or organization tools, please comment and let me know.

Man Pages for commands in this post »

find
grep

1 Comment »

Comment by Mohammed

September 24, 2012 @ 6:03 am

Hello,

Nice, and informative. Do you know how we can clear multiple files? Is there any script?

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>