[Terminal] Delete All Duplicate Files, Delete Empty Folders
Delete All Duplicate Files: parenthesis example
In terminal type: “cd” including a follow space.
In finder: drag/drop the top level folder you want to search on the terminal window. This will show the folder path
In terminal: hit enter
(optional) In terminal type: “ls” to view all folders and files.
In terminal type: find . -type f -name “*(*)*” -print. This will print a list of all the matching files found, that include any character (notated by the first *) that proceeds an open parenthesis “(”, followed by any character(s) (notated by the second * symbol), followed by a closing parenthesis “)”, followed by any character (notated by the last * symbol). -print is a common safe way to test returned results, before executing a permanent command like -delete.
Delete All Empty Folders:
In terminal type: “cd” including a follow space.
In finder: drag/drop the top level folder you want to search on the terminal window. This will show the folder path
In terminal: hit enter
(optional) In terminal type: “ls” to view all folders and files.
In terminal type: find . -type d -empty -print. This will print a list of all the matching folders (directories) that are empty within the specified folder (directory) being searched. -print is a common, safe way to test returned results, before executing a permanent command like -delete.
Command definition for completeness:
cd = change directory
ls = list contents of specified directory
find . = dot represents the current directory. (Some versions of find require that you provide a path argument)
-type = find files of type
f = f is shorthand for file
d = d is shorthand for directory
-name = searching file names
“*whatever_you_are_looking_for*” = * allows a match to any character proceeding or following the match character(s) within the regex
-empty = finds folders (directories) that are empty / contain no files
-print = will print a list of files returned from the search
-delete = replace -print with -delete to remove all found files















