I have a directory with automatically generated files that all end with the .sample extension. I would like to have a way to remove the .sample extension from them all in one terminal command.
I tried this:
mv ./{$1}*.sample ./$1
But it doesn't work because I'm definitely placing the {$1} in the wrong place or way. Can anyone point to the right direction?
Thanks in advance.
Edit: Also see
${parameter#word}
, which deletesword
from the front ofparameter
:I remember which of these I need from the positions of the
#
and%
keys on my (UK) keyboard:#
is left of%
so matches on the left. Before I noticed that I had to check the man page every time :~)These expansions also support shell wildcards:
The
#
and%
forms match the shortest expansion ofword
. You can use##
or%%
for the longest match. E.g.:It's worth getting to grips with these expansions. There's several more, including (somewhat cranky) regex support, substrings and ways to set defaults or get variable lengths. Man bash, of course.
The
rename
command accepts Perl expressions:Example:
On my Ubuntu system,
rename
is symlinked to theprename
script from theperl
package.On Fedora, the
rename
command is included in the util-linux-ng package.One of the many way to do that: