You can use the rename
tool like this
rename 's/\ \[\!\]//' *.zip
I recommend that you first add the -n
switch, which causes rename
to just show what it will do, but not rename any files.
rename -n 's/\ \[\!\]//' *.zip
Note that this will only remove the first occurence of [!]
in the filename, only if it is preceded by a space, and regardless of whether it is at the end of the filename or not.
basic syntax of rename
:
rename 's/from/to/' filenames
will replace from
with to
in all filenames.
here is a detailed explanation: https://www.computerhope.com/unix/rename.htm
note there are two rename
commands: one from the util-linux package and one from the perl package. the command i refer to above is the perl variant. the perl variant is much more popular and useful. usually when people talk about rename
they mean the perl variant.
in debian (and therefore ubuntu) rename
is the perl variant by default. https://stackoverflow.com/questions/22577767/get-the-perl-rename-utility-instead-of-the-built-in-rename
in arch linux rename
is the util-linux variant while perl-rename
is the perl variant. https://bbs.archlinux.org/viewtopic.php?id=85128
here is how you can see what version you are using:
$ rename --version
rename from util-linux 2.30.1
$ perl-rename --version
perl-rename 1.9
Best Answer
A simple bash script should do it.
To help with a line-by-line explanation:
ls
(sorted alphabetically by default).file#.ext
. The "#" is the current number in "count" and the stuff past the "." is a quick way to get the current file extension (so this could work in a folder of various file extensions).loop, loop, loop
Note:
This executes in whatever directory you are executing it from. So as a script, you'd want to add a command line argument. Instead I would open a terminal, navigate to the directory to do this on, and execute the following (exactly):
This is assuming that you only have file names such as "file.txt" not "this.is.a.file.txt"