我经常需要在varios位置创build文件的副本(并且希望避免过多的input)。 (然后我会编辑它们)
基本上命令是这样的:
cp very/long/path/to/file/my-file_with-long.name very/long/path/to/file/my-file_with-long-another.name vim very/long/path/to/file/my-file_with-long-another.name cp even/longer/path/to/other/location/with_another-file_and-stupid.name even/longer/path/to/other/location/with_another-file_and-stupid-copy.name vim even/longer/path/to/other/location/with_another-file_and-stupid-copy.name
我真的想避免用cd更改workdir并input相同的path两次。 基本上我可以将命令添加到像mydup这样的bashrc ,所以它会创build新文件并返回它的名字,所以我使用:
vim $(mydup very/long/path/to/file/my-file_with-long.name -another) vim $(mydup even/longer/path/to/other/location/with_another-file_and-stupid.name -copy)
但也许我发明了自行车,还有更简单的方法来做同样的事情吗?
cp /very/long/file/path{,.bak} vim !$
要么
cpvi() { name=$1 cp "${name}" "${name}.bak" $EDITOR "${name}.bak" } cpvi /very/long/file/path
您可以在原地复制文件,而无需更改目录。 例如
cp very-long-file-name very-long-file-name.copy vim very-long-file-name.copy
在这种情况下,bash完成和tab键是你的朋友。 我一直这样做,我从不写太多。