≡ Menu

UNIX / Linux: Deleting Multiple Files In Bulk

How do delete multiple files in bulk (say all *.bak file stored in /netapp/ and its subdirectory) under Linux / UNIX operating systems?

You can use the find command as follows to find and delete file in bulk:

find /path/to/delete -type f -iname "fileType" -delete


find /path/to/delete -type f -iname "fileType" -exec rm -f {} \;

To delete all *.bak files in bulk from /netapp/ and its subdirectory, enter:
# find /netapp/ -type f -iname "*.bak" -delete
# find /netapp/ -type f -iname "*.bak" -exec rm -f {} \;

Shell Scripting Example

In this example, you’ve a file called delete.txt (with 5000 entries, each per line) and you need to delete all those files:


Create a shell script as follows to read a text file using while loop one line at a time:

[ ! -f "$_input" ] && { echo "File ${_input} not found."; exit 1; }
while IFS= read -r line
	[ -f "$line" ] && rm -f "$line"
done < "${_line}"

The while statement is used to executes rm commands repeatedly on each file.

Share this tutorial on:

Like this? Follow us on Twitter OR support us by using Patreon

{ 0 comments… add one }
Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , ,