Friday, July 18, 2014

check or remove multiple backup files filter by number

Assume on the backup directory has files like this
backup-2011-01-01-data.tar.gz
backup-2011-02-01-data.tar.gz
backup-2011-03-01-data.tar.gz
. . .
backup-2012-01-01-data.tar.gz
backup-2012-02-01-data.tar.gz
backup-2012-03-01-data.tar.gz
. . .
backup-2013-01-01-data.tar.gz
backup-2013-02-01-data.tar.gz
backup-2013-03-01-data.tar.gz
. . .

If I want to check or remove all files from year 2011 to 2012 by command line, how to do that. Do one by one? just 24 times. but if more?

You can check on file by command line by :

$du -ch backup-2012-01-01-data.tar.gz
3.4M backup-2012-01-01-data.tar.gz
3.4M total

For more files and filter by number can use this command

$du -ch backup-{2011,2012}*
3.4M backup-2011-01-01-data.tar.gz
3.4M backup-2011-02-01-data.tar.gz
3.4M backup-2011-03-01-data.tar.gz
. . .
3.4M backup-2012-12-01-data.tar.gz
81.6M total

And you can remove files

rm backup-{2011,2012}*

Read More