rmdotfiles
Script that autmatically removes "dot-files" and 'Apple-double' files and folders from a given path.
WARNING!: The author may not be held responsible for accidental/unwanted deletion and/or corruption of filesystem objects, applications, procedures or whole systems as consequences of the use of this tool.
Please be aware that this tool can transverse/read and, in case, remove/delete only filesystem objects that the user/process running it has corresponding permissions to do.
Syntax
rmdotfiles basepath [logfile]
This script needs a first compulsory argument basepath
as the root folder which the file/directory purging process starts from (and always walks down across that path), plus an optional second argument logfile
as the pathname of a file where error messages and found/deleted object counts are (appended and) logged.
Description
The script attempts to remove files and folders that obey some simple naming convention rules. These filesystem objects are usually "hidden" (as per filesystem metadata) and automatically generated by different Operating System procedures for several reasons, most notably:
- Linux, Microsoft Windows and Apple macOS trash-bin folders (generated in the root dirctory of every volume – one per UID/user in Linux and macOS). "Soft-deleted" filesystem objects are usually moved in here rather than being deleted at filesystem (or block) level. Removing these folders is usually equivalent to the GUI procedure of "emptying the bin(s)".
- Microsoft Windows
Thumbs.db
local-folder database (one per folder) holding previews and thumbnail icons for all multimedia files within the directory. - Apple macOS "dot-files", i.e. those sidecar files begninning with
.
or._
automatically generated for every file in every folder specifically transversed by the OS across any network drives or local volumes with non-Apple filesystems (i.e. filesystems different from HFS / HFS+ / APFS, or network shares not using the legacy AFP protocol). These sidecar-files usually hold GUI-related parameters about their twin file, that would be stored among the original file's own metadata on HFS+/APFS/AFP volumes (and macOS storing them in a hidden sidecar file otherwise). - Apple macOS automatically-generated
.DS_Store
files (one per folder) having the same functionality, for standard folders/directory, as the sidecar dot-files from the above bullet-point have for standard files. - Microsoft Windows disk recovery folders containing chunks of files partially recovered by
CHKDSK
and similar system utilities due to (usually "logical") filesystem errors. These objects may be "invisibily" generated, can occupy a sensible portion of the volume, and usable data can be seldom recovered out of them anyway. - A few additional special files and folders generated by the various Operating Systems across local volumes or network drives.
It reports errors without interrupting in case of write-permission or similar issues. Please also be aware that folders targeted by the script (like the trash-bin ones described above) are completely removed without analyzing their internal content whatsoever.
Reasons for running this tool usually include having a clean and "cleared" directory structure, conforming filenames to specific higher-level naming convention, removing unnecessary files (e.g. for Cloud/network file-sharing or long-term archival purposes) and –most notably– removing tiny files which automatic, or otherwise storage-I/O intensive applications may require long time for processing (and eventually failing to), as the sidecar files' extension and format deviates from the target.
WARNING!: The author may not be held responsible for accidental/unwanted deletion and/or corruption of filesystem objects, applications, procedures or whole systems as consequences of the use of this tool.