|
||||||||
Linux / Unix: Find and Delete All Empty Directories & Files
Время создания: 23.01.2018 10:58
Автор: Vivek Gite
Текстовые метки: linux find delete directory dir file
Раздел: Linux
Запись: Velonski/mytetra-database/master/base/151668712258j6te31qv/text.html на raw.githubusercontent.com
|
||||||||
|
||||||||
How do I find out all empty files and directories on a Linux / Apple OS X / BSD / Unix-like operating systems and delete them in a single pass? WARNING! These examples may crash your computer if executed. Some background process (daemons) may use empty files as a lock files or as default location to lock (chroot) down daemons. Do not delete those files. Usually, located in /var/, /lib/ and other important locations. Method # 1: Find and delete everything with find command only The syntax is as follows to find and delete all empty directories using BSD or GNU find command:
Find and delete all empty files:
Delete empty directories In this example, delete empty directories from ~/Downloads/
Delete empty files In this example, delete empty files from ~/Downloads/
Sample session: How to count all empty files or directories? The syntax is as follows:
Where,
This is useful when you need to clean up empty directories and files in a single command. Method # 2: Find and delete everything using xargs and rm/rmdir command The syntax is as follows to find and delete all empty directories using xargs command:
OR ## secure but may be slow due to -exec ## find /path/to/dir -type d -empty -print0 -exec rmdir -v "{}" \; The syntax is as follows to delete all empty files:
OR
See man pages – find(1),rmdir(1),xargs(1) |
||||||||
Так же в этом разделе:
|
||||||||
|
||||||||
|