制作文件副本的最小命令

use*_*107 19 command-line bash cp

我经常发现自己复制粘贴长路径以创建文件的副本

cp /path/to/file/file1 /path/to/file/file1.bkp
Run Code Online (Sandbox Code Playgroud)

是否有替代实用程序不需要我两次键入路径/到/文件?就像是 -

nameOfExecutible /path/to/file/file1 'bkp'
Run Code Online (Sandbox Code Playgroud)

注意:我不想做一个cdtofile1的父目录。

dai*_*isy 34

是的,

cp /path/to/file/file1{,.kbp}

这将自动扩展为 cp /path/to/file/file1 /path/to/file/file1.kbp

  • bash shell 在执行 cp 之前扩展花括号中的表达式。你可以在 bash 手册中找到它,或者谷歌搜索“bash 大括号扩展” (7认同)