2009-03-25

regex - pattern matching with numbers in sequence

Arghhh... Disk space is full. First thing to do? Of cause, is to free some disk space first. Next question, what to delete? Log files are the first on the list. But log files are normally named after running number in sequence. To delete them, it has to be either a "one by one" command"s" or in script. Oops, there is another way. Look forward :

e.g.
To remove files with numbers in sequence :
rm some-files-000[1-9]



Is bonus time !!!

There are other Bash utilities supports regex. Below are some examples :
To list some files with numbers in sequence :
ls some-files-000[0-5]


rsync, too, support regex
e.g.
rsync -av --progress some-files-0001[0-5] some-files-0002[0-5] destination-directory

Hasta la Vista !!!

No comments: