How to remove certain files? [SOLVED]

Forum rules
Before you post please read this

How to remove certain files? [SOLVED]

Postby kgully on Thu Aug 11, 2011 9:43 am

Hey all,

I need help removing a bunch of old files from a directory, and don't have very good regular-expression foo so I thought I would see if anyone had a quick solution?

I have a directory with files that follow two different patterns:
new pattern: transmission-743.50-285.0-6.0-7.5
old pattern: transmission-743.50-285.0-6.5

As you can see, the old pattern, which I want to remove, has one less dash and one less number. There are thousands of each file type, so going into nautilus is not really a very good option for me. Any help would be much appreciated!
Last edited by kgully on Thu Aug 11, 2011 11:10 am, edited 1 time in total.
kgully
Level 2
Level 2
 
Posts: 55
Joined: Wed Sep 16, 2009 10:31 pm

Linux Mint is funded by ads and donations.
 

Re: How to remove certain files?

Postby xenopeek on Thu Aug 11, 2011 11:06 am

For the current directory, this command gives you all the files that match pattern with 3 dashes (transmission-1-2-3) and not with 4 dashes (transmission-1-2-3-4):
Code: Select all
ls | grep "^transmission-[^-]*-[^-]*-[^-]*$"

The following command will delete all the matching files:
Code: Select all
 ls | grep "^transmission-[^-]*-[^-]*-[^-]*$" | xargs rm
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14891
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: How to remove certain files?

Postby kgully on Thu Aug 11, 2011 11:10 am

Thanks Vincent!
kgully
Level 2
Level 2
 
Posts: 55
Joined: Wed Sep 16, 2009 10:31 pm


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 2 guests