I have been asked to post a command or script by a newbie user on how he can delete all files with 0K or zero filesize recursively.
This is a quick entry on how to delete files with 0K (zero) filesize and optionally do it recursively.
A precaution. First, deleting files recursively in linux is dangerous unless you know what you are doing. Here's one way on how to delete files with zero file size recursively.
Assuming our target directory is /tmp and we wish to delete all zero-sized regular files inside that /tmp folder
First, search files with sero-sized filesize that needs to be deleted
# find /tmp -size 0c
This can confirm if the search results produced by the above command are correct. The above command lists out results including special files, special blocks, devices and lock files that has zero file size. This is the chance to verify if the above command would include any important files that you might have from the search directory folder.
Let us add more searcg filters to the search query by filtering out to show regular files with zero file size only.
Searching with regular file filter using find
# find /tmp -size 0c -type f
If we are satisfied with the results produced by the above command, we can now proceed on deleting those search results returned by the above command. This can be done by appending the file delete command with the find command like so
Search and delete recursively
# find /tmp -size 0c -type f -exec rm -rf {} \;
The above commands totally deletes all files with zero filesize (0K) without any prompts. Be careful with this command as you don't want to delete special device, files and lock files from your linux box.
Enjoy.
Subscription
Categories
- HowTos (612)
- Linux Devices (40)
- Linux Diggs (620)
- Linux News (1541)
- Linux Videos (24)
Recent Posts
Blog Archive
-
▼
2008
(2301)
-
▼
January
(49)
- HowTo: Brasero
- HowTo: ISOs Management for Fedora
- HowTo: Install Nmap with GUI FrontEnd
- HowTo: Create and Manage Genealogy Family Tree via...
- HowTo: Install KFTPGrabber FTP Client
- HowTo: Install FileZilla 3 on Fedora 8
- HowTo: Be Alerted via Popups When Monitoring Log F...
- HowTo: Mount Windows Drive From Linux GUI
- HowTo: Delete Files With 0K Filesize Recursively
- HowTo: Changing Interface's MTU Size
- HowTo: Create Vanishing Virtual Drive
- HowTo: Install Identity.pub Into Remote Machines
- HowTo: Check and Mark Bad Block Of Hard Disk
- HowTo: Install Linux Hardware Browser
- HowTo: Basic RPM Package Queries And Usage
- HowTo: Rebuild Locked Out RPM Database
- HowTo: Display RPM Packages Installed Last Month
- HowTo: Display and List Out All Package Files Rece...
- HowTo: Identify Source Package Name Of A File or F...
- HowTo: Delete Extra Spaces Between Words From Files
- HowTo: Find Hidden Directory Folders Recursively
- HowTo: Create Hidden Directory Folder
- HowTo: Print Only Lines of Text File with N charac...
- HowTo: Sort Files by FileSize and What Else?
- HowTo: Squeezed Out Multiple Lines From Text File
- HowTo: Prevent Binary Execution From Mounted Device
- HowTo: Determine Domain's Expiration Date From Lin...
- HowTo: Create and Overwrite Existing Alias
- HowTo: Get MAC Address of PCs Around
- HowTo: List Out Hidden Files and Hidden Directory ...
- HowTo: Identify Valid Login Shells
- HowTo: Deny User from Logging Into Your System
- HowTo: Remove Tabs From Text Files Completely
- HowTo: Convert Tabs In Each File To Spaces
- HowTo: Install and Say Cheese
- HowTo: Install HomeBank and Manage Personal & ...
- HowTo: Install Mind-Mapping LabyRinth Tool
- HowTo: Install VMWare Server on Fedora 8
- HowTo: Install VMWare Workstation on Fedora 8
- HowTo: Virtual PCLinux 2007 via VirtualBox over Fe...
- HowTo: Enable PortMap on Fedora 8
- HowTo: Linux Hardware Lister Tool - LsHw
- HowTo: Install Bandwidth Shaper - Trickle on Fedora
- HowTo: VnStat Long-Term Traffic Monitoring via CLI
- HowTo: Install NetSpeed Traffic Monitoring Applet
- HowTo: Install IPTraff LAN Monitoring Tool
- HowTo: Install Ibmonitor Interface Bandwidth Monitor
- HowTo: Install IfTop Bandwidth Monitoring Tool
- HowTo: Fedora WordPress Installation
-
▼
January
(49)
Monday, January 28, 2008
HowTo: Delete Files With 0K Filesize Recursively
Subscribe to:
Post Comments (Atom)
ILoveTux - howtos and news | About | Contact | TOS | Policy
0 comments:
Post a Comment