我的文件路径很长,例如:
/opt/very/long/path/file1
我要复制此目录中的文件:
cp /opt/very/long/path/file1 /opt/very/long/path/file2
我不想重复这条漫长的路。我可以转到目标文件夹并复制:
cd /opt/very/long/path/
cp file1 file2
但是我不想更改目录。原因之一是:如果我有很多长路径,则每次都必须转到目录。
cd /opt/very/long/path/
cp file1 file2
cd /opt/other/very/very/long/path/
cp fileA fileB
另一个原因是:我想保留上下文并清除历史记录(每个命令都说明复制的内容和位置)。
因此,最好不要更改目录:
cp /opt/very/long/path/file1 /opt/very/long/path/file2
cp /opt/other/very/very/long/path/fileA /opt/other/very/very/long/path/fileB
但是我必须重复一遍。
有这样的捷径吗?
cp /opt/very/long/path/file1 ./file2
cp /opt/other/very/very/long/path/fileA ./fileB
但是点.
表示“当前目录”。是否有任何字符表示“目标目录”或“源目录”?
cp /opt/very/long/path/file1 <destination>/file2
cp /opt/other/very/very/long/path/fileA <destination>/fileB
括号扩展对此非常有用:
cp /opt/other/very/very/long/path/{fileA,fileB}
...将扩展为:
cp /opt/other/very/very/long/path/fileA /opt/other/very/very/long/path/fileB
当它实际执行时。
该命令将在您键入时显示在您的历史记录中,并保留路径:
$ history
# ...
508 cp /opt/other/very/very/long/path/{fileA,fileB}
509 history
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句