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!
How to remove certain files? [SOLVED]
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
How to remove certain files? [SOLVED]
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: How to remove certain files?
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):
The following command will delete all the matching files:
Code: Select all
ls | grep "^transmission-[^-]*-[^-]*-[^-]*$"
Code: Select all
ls | grep "^transmission-[^-]*-[^-]*-[^-]*$" | xargs rm