我正在尝试重命名文件,例如使用this SO question中的方法screen-0001.tif
到0001.tif
:
for file in *.tif
do
echo mv "$file" "${screen-/file}"
done
无法改变任何事情。感谢我出错的想法。
答案 0 :(得分:2)
更容易,恕我直言,这样做的方法是使用Perl的--dry-run
脚本。在这里,我将它与--dry-run
一起使用,因此它只是告诉你它会做什么,而不是实际做任何事情。如果/当您对命令感到满意时,您只需删除rename --dry-run 's/screen-//' *tif
'screen-001.tif' would be renamed to '001.tif'
'screen-002.tif' would be renamed to '002.tif'
'screen-003.tif' would be renamed to '003.tif'
'screen-004.tif' would be renamed to '004.tif'
:
screen-001.tif
0screen-01.tif
它具有额外的好处,它不会覆盖碰巧出现在同一名称的任何文件。所以,如果你有文件:
rename 's/screen-//' *tif
'screen-001.tif' not renamed: '001.tif' already exists
你这样做了,你会得到:
rename
brew install rename
可以使用Homebrew轻松安装,使用:
create table receivers(
country varchar(10) not null,
date datetime not null,
quantity integer not null
);
insert into receivers values ("china", "2000-01-01", 100);
insert into receivers values ("japan", "2000-01-01", 900);
insert into receivers values ("usa", "2000-01-01", 345);
insert into receivers values ("usa", "2000-01-01", 234);
insert into receivers values ("usa", "2000-01-01", 56);
insert into receivers values ("usa", "2000-01-01", 12);
insert into receivers values ("china", "2000-01-01", 300);
insert into receivers values ("china", "2000-01-01", 10);
insert into receivers values ("china", "2000-01-01", 1000);
答案 1 :(得分:1)
两件事:
${file#screen-}
。${file/screen/}
环境变量的名称始终是第一位的。然后是模式类型,然后是模式
以下是我将如何做到这一点:
$ for file in *.tif
> do
> echo "mv '$file' '${file#screen-}'"
> done | tee mymove.sh # Build a shell script
$ vi mymove.sh # Examine the shell script and make sure everything is correct
$ bash mymove.sh # If all is good, execute the shell script.