I have a list of files
-rw-rw-r-- 1 t t 24813 Oct 23 2002 fig8_21.gif
-rw-rw-r-- 1 t t 2259 Oct 23 2002 fig8_21t.gif
-rw-rw-r-- 1 t t 35331 Oct 23 2002 fig8_23.gif
-rw-rw-r-- 1 t t 2610 Oct 23 2002 fig8_23t.gif
-rw-rw-r-- 1 t t 19970 Oct 23 2002 fig8_24.gif
-rw-rw-r-- 1 t t 2019 Oct 23 2002 fig8_24t.gif
-rw-rw-r-- 1 t t 54623 Oct 23 2002 fig8_3.gif
-rw-rw-r-- 1 t t 3657 Oct 23 2002 fig8_3t.gif
-rw-rw-r-- 1 t t 35861 Oct 23 2002 fig8_4.gif
-rw-rw-r-- 1 t t 2344 Oct 23 2002 fig8_4t.gif
I want to overwrite <...>t.gif
with <...>.gif
e.g. copy fig8_4.gif
to overwrite fig8_4t.gif
.
I first find those <...>t.gif
files by find . -regex ".*t\.gif"
. Then I want to use basename
to strip the filenames, but why do I have the following warnings?
$ find . -regex ".*t\.gif" -execdir basename {} \;
find: The relative path `~/program_files/internet/SSH_tunneling/' is included in the PATH environment variable, which is insecure in combination with the -execdir action of find. Please remove that entry from $PATH
$ find . -regex ".*t\.gif" | xargs basename
basename: extra operand ‘./f10_1t.gif’
How shall I continue to finish my task?
Is it possible not using find
?
Best Answer
Yes, it's possible. One way to do it might look like this:
The
${var%%pattern}
thing is standard/POSIXsh
syntax for removing the longest string that matches pattern from the end of$var
.