Ger*_*rry 6 shell cd-command rename
有没有办法将文件从一个目录移动到另一个目录,然后在一个命令中 cd 进入后者?类似mv /a/file /another/dir && cd _
但没有第二次输入目录路径的东西。
有一些函数可以移动和复制文件并将它们跟踪到源自Arch Linux 板上线程的目标目录:
# Follow copied and moved files to destination directory
cpf() { cp "$@" && goto "$_"; }
mvf() { mv "$@" && goto "$_"; }
goto() { [ -d "$1" ] && cd "$1" || cd "$(dirname "$1")"; }
Run Code Online (Sandbox Code Playgroud)
然后,您可以通过发出以下命令来 {move,copy} 并跟踪文件:
mvf file /dest/dir/
Run Code Online (Sandbox Code Playgroud)
在您的.bashrc
:
cpcd() { cp "$1" "$2" && cd "$2"; }
Run Code Online (Sandbox Code Playgroud)
那就是我会怎么做
然后你会cpcd
像你一样使用cp
cpcd blah dir/
Run Code Online (Sandbox Code Playgroud)
它会将 blah 复制到 dir,如果成功,它会将目录更改为 dir/