[問題] 誤改檔名後如何快速改回來

看板Linux作者 (一步一腳印)時間12年前 (2011/09/20 15:31), 編輯推噓7(704)
留言11則, 5人參與, 最新討論串1/1
有時候手殘會發生這種事 原本想要打這樣: user@local_host:~$ scp a_file_with_long_filename user@remote_host:path_to_put_the_file 卻不小心打成這樣, 誤改了檔名: user@local_host:~$ mv a_file_with_long_filename user@remote_host:path_to_put_the_file 於是只好先把檔名改回來再scp: user@local_host:~$ mv user@remote_host:path_to_put_the_file a_file_with_long_filename user@local_host:~$ scp a_file_with_long_filename user@remote_host:path_to_put_the_file 像這種情況就算有tab completion的幫忙也是略嫌麻煩 以上情境只是舉例 也有其他情況也是不小心改了檔名 想請問的是像這種情況有沒有辦法: 1. 用更短的指令把檔名改回來 or 2. 把"改檔名"和"重作動作"兩個動作變成一個動作, 而且指令不會太長? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.31.149

09/20 16:24, , 1F
我第一個想到的是把mv alias 成 mv -i 可以解決大部分的問題
09/20 16:24, 1F
我的.bashrc有alias mv='mv -i' 然而mv -i 是覆寫前提出警告 跟我問的問題的關係是...?

09/20 16:25, , 2F
但是剛剛試了一下\mv -i 似乎不會 interactive? Ubuntu 11.04
09/20 16:25, 2F
喔我懂你的意思了 你是說每次mv都跳出prompt對吧 不過mv -i只有覆寫才有prompt 然後我也不希望每次mv都prompt...XD

09/20 16:26, , 3F
-i似乎是在複寫的時候才會interactive?
09/20 16:26, 3F

09/20 16:34, , 4F
ya, 我腦補interactive了
09/20 16:34, 4F

09/20 21:59, , 5F
mv !:2 !:^
09/20 21:59, 5F

09/20 22:20, , 6F
在X下嗎?? 用滑鼠選取後按中鍵再搭ctrl-w ctrl-a
09/20 22:20, 6F
說到滑鼠中鍵選取 我超希望用鍵盤就可以操作primary selection或clipboard 比如(幻想)按ESC後接^w就可以把cursor右方的word複製到primary selection 可惜bash好像沒有這種功能 = =

09/20 23:27, , 7F
try: mv a b => mv !:2 !:^
09/20 23:27, 7F
恩恩!剛剛還在研究XD 這應該是本文最佳解法了

09/21 00:53, , 8F
mv (alt+.) !:^ 也可以(alt+.是上個指令最後一個arg)
09/21 00:53, 8F
多謝!

09/21 00:57, , 9F
set -o vi 可以把commandline設為vim 你說的功能大概就有
09/21 00:57, 9F

09/21 00:57, , 10F
不過我想應該不多人用這種模式就是了
09/21 00:57, 10F
喔喔...我本來以為set -o vi只是改key binding而已 原來有那些功能? 來研究看看...

09/21 01:50, , 11F
有vim裡面的y複製d剪下功能
09/21 01:50, 11F
恩恩 ※ 編輯: Holocaust123 來自: 140.112.31.155 (09/21 02:25)
文章代碼(AID): #1EU45ajr (Linux)