Delete files in a folder with a specific ending


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete files in a folder with a specific ending
# 1  
Old 12-17-2009
Delete files in a folder with a specific ending

Hi I have files that end with .txt.txt that i want to delete. But I also have files that end with .txt that I want to leave intact. How do I specifically delete files that end with .txt.txt in a folder.

thanks
# 2  
Old 12-17-2009
why not this:
Code:
rm *.txt.txt

# 3  
Old 12-17-2009
I would use the find command first, and use it to print out the results and then delete them after you verify you want to delete them....example:

Code:
/usr/bin/find ‑x ‑E /path/to/folder ‑regex '.*\.(txt)' ‑print

Disclaimer is I am not in front of a *nix box right now so I am just doing this from memory and google, should work in bash though. Where it says path to folder, set the path to the folder you want it to search.

Last edited by tlarkin; 12-17-2009 at 11:03 PM..
# 4  
Old 12-17-2009
I would sooner use ls or another program that uses globs/wildcards to make sure the results will be the same.
# 5  
Old 12-18-2009
Quote:
Originally Posted by CRGreathouse
I would sooner use ls or another program that uses globs/wildcards to make sure the results will be the same.
Quote:
Originally Posted by tlarkin
I would use the find command first, and use it to print out the results and then delete them after you verify you want to delete them....example:

Code:
/usr/bin/find ‑x ‑E /path/to/folder ‑regex '.*\.(txt)' ‑print

Disclaimer is I am not in front of a *nix box right now so I am just doing this from memory and google, should work in bash though. Where it says path to folder, set the path to the folder you want it to search.
I may use both these commands in a shell script and achieve the same. Smilie
# 6  
Old 12-18-2009
In my limited experience the find command does have some over head, and I have had it totally eat up tons of space in log files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

3. UNIX for Dummies Questions & Answers

Script to delete files in different folder

Hi Experts, i need a little help. i have different folder that contain files that need to be deleted. but those folder contains huge amoung of same with 3 different extention. what i used to do is to delete them using the rm commande rm *.ext *.ext1 *.ext3 what i want to do is to have... (1 Reply)
Discussion started by: yprudent
1 Replies

4. Shell Programming and Scripting

rsync delete specific files - from different target folder

Hi, I need to use rsync to delete multiple files(only specified files not all) using --delete option, these files are located in different target folders. Instead of running rsync command multiple times for each file, can we achieve this with one time execution? your help is much... (0 Replies)
Discussion started by: MVEERA
0 Replies

5. Shell Programming and Scripting

need to navigate into specified folder and delete the files

Hi all, I need to write a script to naviagate into the list of specified folder and delete the files in it. I have mentioned the list of folders in a external file so it can be reusable. The issue is am facing now is that, i am not understating on how to navigate into the folder locations... (6 Replies)
Discussion started by: Nithz
6 Replies

6. Shell Programming and Scripting

transfering files with a specific name to a folder

Hi I want to transfer all files in a folder to another folder. So the files have a ending of .lop.txt thanks (4 Replies)
Discussion started by: gisele_l
4 Replies

7. Shell Programming and Scripting

delete all the files in folder a which exist in folder b

Hi , I need a script which basically deltes all files in folder a which are alreasy present in folder b say folder a has files abc.txt pqr .txt and b has abc.txt pqr.txt rmr.txt then file abc.txt and pqr.txt from a should be deleted (6 Replies)
Discussion started by: viv1
6 Replies

8. Shell Programming and Scripting

Batch delete specific folder from user home directories

Hi! Need your help. How can I delete the cache folder of multiple user home directories via automatically executed shell script on a Mac OS X Server? Example: The userdata are stored on a Xsan Volume like this: /Volumes/Xsan/userdata/mike /Volumes/Xsan/userdata/peter... (2 Replies)
Discussion started by: nipodrom
2 Replies

9. UNIX for Dummies Questions & Answers

How can i delete files in folder by date?

Hi, I have some files on a folder and i want to delete all the files that were created on July. Thanks, Kobi. (9 Replies)
Discussion started by: kobibn
9 Replies

10. Shell Programming and Scripting

delete all folders/files and keep only the last 10 in a folder

Hi, I want to write a script that deletes all folders and keep the last 10 recent folders. I know the following: ls -ltr will sort the folders from old to recent. ls -ltr | awk '{print $9}' will list the folder names (with a blank line at the beginning) I want to get the 10th folder from... (3 Replies)
Discussion started by: melanie_pfefer
3 Replies
Login or Register to Ask a Question