A self-automating bash script for organizing files on your Ubuntu-based Linux desktop into appropriate folders.
Written in Bash 5.1. Edited in Atom 1.59. Tested on Linux Mint 21.2.
The purpose of this script is to perform general cleanup of your Desktop in a way that can be automated. As of Version 1.2, DesktopCleanup.sh schedules itself to run every 15 minutes as a crontab job.
DesktopCleanup.sh moves all files it recognizes into separate filetype-specific 'Unsorted' folders in each of your main Home folders (audio files will be moved to ~/Music/Unsorted, video will be moved to ~/Videos/Unsorted, etc). It also uses perl to bulk rename files with foreign characters found in MacOS filenames and ffmpeg to convert less popular lossy file formats into more universal and less lossy (or lossless) file formats. Below is a complete list of features:
- Automates itself as a
crontabjob to run every 15 minutes - Renames files with common foreign MacOS characters (requires
perl) - Renames files with a timestamp to prevent overwrites.
- Installs
.otf&.ttffonts to ~/.local/share/fonts - Converts (requires
ffmpeg).avif,.bmp,.webppictures to.png.m4a&.mpgaaudio to.wav.divx,.flv,.mov,.mpg,.webmvideo to.mp4
- Moves
- Applications
.deb,.flatpak,.flatpakref,.rpmpackages to ~/Applications/Linux Packages.appimage&.x86_64apps to ~/Applications, makes them executable, and links them to the Desktop.exe&.msiWindows apps to ~/Applications/Windows.appMacOS apps to ~/Applications/MacOS.apkAndroid apps to ~/Applications/Android.xpiMozilla Extensions to ~/Applications/Mozilla Extensions
- Documents
.epub&.pdfbooks to ~/Documents/Books.numbers,.xls,.xlsxto ~/Documents/Spreadsheets.asc,.ctb,.doc,.docx,.eml,.rtf,.txtdocuments to ~/Documents/Unsorted.html,.urlwebpages to ~/Documents/Webpages
- Pictures
.kra,.psd,.xcfprojects to _~/Pictures/Projects- "screenshots" to ~/Pictures/Unsorted/Screenshots
.heic,.gif,.jpg,.jpeg,.png,.raw,.svg,.tiffpictures to ~/Pictures/Unsorted
- Music
.aiff,.flac,.mp3,.m4b,.oga,.ogg,.wavaudio to ~/Music/Unsorted.mid,.midisheet music to ~/Music/Sheet Music.sf2soundfonts to ~/Music/Soundfonts- <1MB sound effects to ~/Music/SFX
- Video
.flb,.kdenlive,.mlt,.osp,.ove,.wmv,.xgesprojects to ~/Videos/Projects.srtsubtitles to ~/Videos/Subtitles.3gp,.avi,.m4v,.mkv,.mp4,ogxvideos to ~/Videos/Unsorted
- Games
.swfFlash games to ~/Games/Flash.nesNES roms to ~/Games/ROMs/Nintendo/NES.smc&.sfcSNES roms to ~/Games/ROMs/Nintendo/SNES.n64&.z64N64 roms to ~/Games/ROMs/Nintendo/N64.gbcGB roms to ~/Games/ROMs/Nintendo/GB.gbaGBA roms to ~/Games/ROMs/Nintendo/GBA.ndsDS roms to ~/Games/ROMs/Nintendo/DS.3ds3DS roms to ~/Games/ROMs/Nintendo/3DS.ips,.rnqsromhacks to ~/Games/ROMs/Hacks.sav,.srm,.oopssave files to ~/Games/Save Files.gblorb,.z3,.z5,.z8text adventures to ~/Games/Text Adventures.ydkdecklists to ~/Games/TCGs.scm&.scxStarcraft maps to ~/.wine/drive_c/Program Files (x86)/StarCraft/Maps
- Downloads
.torrenttorrents to ~/Downloads/Torrents
- Miscellaneous
.m4psongs to ~/Desktop/Dangerous Files.graffle,.icns,.rsrcto ~/Desktop/Unconvertable
- Applications
- Optional Moves: (can be enabled by removing the # from their function)
.applescript,.css,.html,.php,.py,.shscripts to ~/Documents/Scripts.7z,.rar,.tar.gz,.ziparchives to ~/Documents/Unsorted Archives
Install optional dependencies on Debian/Ubuntu via apt:
sudo apt install ffmpeg perl
Installation is very simple, just drag-and-drop this script into your ~/Documents folder and run the following Terminal command:
bash ~/Documents/desktopcleanup.sh
You can easily remove DesktopCleanup.sh from your system by trashing the .sh file in your ~/Documents folder and running the following Terminal command:
crontab -l | grep -v "desktopcleanup.sh" | crontab -