Skip to content

Instantly share code, notes, and snippets.

@hardiksondagar
Created November 28, 2016 07:23
Show Gist options
  • Save hardiksondagar/d99ea791a75809ecf0a67545bab4f11a to your computer and use it in GitHub Desktop.
Save hardiksondagar/d99ea791a75809ecf0a67545bab4f11a to your computer and use it in GitHub Desktop.
Organizes downloads folder automatically
# Forked from @January's answer on StackOverflow. http://askubuntu.com/a/184265/123595
#!/bin/bash
# define target directories
DOWNLOADS=$HOME/Downloads
VIDEOS=$HOME/Videos/
PICTURES=$HOME/Pictures/
DOCS=$HOME/Documents/
MUSIC=$HOME/Music/
COMPRESSED=$DOWNLOADS/compressed/
SQL=$DOWNLOADS/sql/
TORRENT=$DOWNLOADS/torrent/
SOFTWARES=$DOWNLOADS/softwares/
# this will generate directories in form /home/user/Downloads/archive-2016-11-28
ARCHIVE=$DOWNLOADS/archive-`date +%Y-%m-%d`
cd $HOME
# create folder is not exists
if [ ! -d "$ARCHIVE" ] ; then mkdir "$ARCHIVE" ; fi
if [ ! -d "$COMPRESSED" ] ; then mkdir "$COMPRESSED" ; fi
if [ ! -d "$MUSIC" ] ; then mkdir "$MUSIC" ; fi
if [ ! -d "$SQL" ] ; then mkdir "$SQL" ; fi
if [ ! -d "$TORRENT" ] ; then mkdir "$TORRENT" ; fi
if [ ! -d "$SOFTWARES" ] ; then mkdir "$SOFTWARES" ; fi
# TARS, Engine up
mv $DOWNLOADS/*.{jpg,png,JPEG,jpeg,PNG,tif,tiff,TIF,TIFF,gif,GIF,psd} $PICTURES
mv $DOWNLOADS/*.{mov,avi,wmv} $VIDEOS
mv $DOWNLOADS/*.mp3 $MUSIC
mv $DOWNLOADS/*.{doc,docx,xls,xlsx,pdf,txt,csv} $DOCS
mv $DOWNLOADS/*.{zip,tar,tar.gz,tar.bz2} $COMPRESSED
mv $DOWNLOADS/*.torrent $TORRENT
mv $DOWNLOADS/*.sql $SQL
mv $DOWNLOADS/*.deb $SOFTWARES
# Move the remaining files to archive folder inside the Downaload folder
find $DOWNLOADS/ -maxdepth 1 -type f -print0 | xargs -0 mv -t "$ARCHIVE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment