Is it possible to remove rather than adding substring to a filename using bash brace expansion?
Considering the following scenario, one can add a suffix to a filename by using the below technique:
mv offlineimap.conf{,.minimal}
What it does is renaming offlineimap.conf
to offlineimap.conf.minimal
which is very handy esp. for making backup files (eg. swith .bak
extension).
But is it also possible to subtract substrings from given filenames, like so:
mv offlineimap.conf.minimal{,-minimal}
Here I use -
as a hypothetical special character to substract the substring.
I expect the second technique to result in offlineimap.conf
removing the .minimal
suffix from the name of an existing file.
Best Answer
To use a brace command to remove a suffix, such as
.minimal
from the fileofflineimap.conf.minimal
, use:More on brace expansion
The idea here is that brace expansion creates a series of strings using the comma-separated list of strings between the braces:
In your first use, the first of the two strings is empty:
In the desired solution, we switch it so that the second of the two strings is empty:
Or: