Unix command for removing specific list of files from a directory

To remove a specific list of files (like .txt, .log, etc.,) from a directory, we can proceed with two ways.

1. Using rm command directly to remove .txt or .log or any kind of specific files using file extension

rm *.txt

2. Using find command to locate the files first and then using rm command to remove the files recursively

find . -type f -name "*.txt" -exec rm -f {} \;

The above command will search for .txt files in the current directory and execute remove command parallely.

Performance wise, find and remove command will be the best. rm command will exhaust more time when compared with find and remove command.

Share This Post

Related Articles

Leave a Reply

© 2018 Techy Diary. All rights reserved.
Powered by Charvi Groups