Bash brace expansion. (to delete files)

In bash , it is common to have to do some action on a numéric serie of files , like deleting or renaming ,

Using brace expansion you will be able to générate a single line that will act on multiple targets ,

For our example , let’s think about a list of ten files

in the simple case where i want to delete the complete list of files, i just have to run de command,

The 10 files will be deleted, but , this is not practical if you want to keep the last file , and delete the other nine,

In that case we can use a usefull tool called brace expansion,

To delete the files 1 to 9 , i just have to run in my bash terminal!

This last one is extremely practical , I use it very often in a lot of different uses cases.

But in other cases , you may want to delete even on odd files , or one every three files,

This is also doable with braces expansions

Leave a Comment

Your email address will not be published. Required fields are marked *