Reputation: 1215
I'm working with Ubuntu recently and I have been asked to remove files with numerals at the beginning.
How do I remove ordinary files from current directory that have numerals at the first three characters?
Upvotes: 0
Views: 1319
Reputation: 6543
How about something like
ls | egrep '^[0-9]{3}' | xargs rm
The ls
lists all the files, the egrep
filters the list so that it only contains filenames that start with three digits, and the xargs
applies rm
to each of the filenamess that egrep
lets through.
Upvotes: 0
Reputation: 3737
First of all: Be careful when trying out such delete commands! Try running in a directory with test files or files that are backed up well.
You could try something like this from shell:
find . -regex './[0-9]{3}.*' -exec 'rm {}' \;
For debugging, try running it without the rm
-command first, listing the files that will be deleted:
find . -regex './[0-9]{3}.*'
You may have to escape the curly braces - at least I had to in FreeBSD, using zsh-shell:
find . -regex './[0-9]\{3\}.*'
Upvotes: 3