In a Bash interaction session, you can edit the command line with Emacs and vi key bindings, so I tend to do the following before using my brain.
Type the following first, then
$cp very-long-file-name.txt
This is how it works.
cp
).old
)This is especially useful when dealing with troublesome file names, such as mixed Japanese.
I think there are many ways to do it, but I often do it in the following two patterns.
First of all, it's common to enter so far.The cursor position should be on the far right.
$cp very-long-file-name.txt
Pattern 1:
Pattern 2:
and so on.For your information.
bash interactive sessions can complement the file name with the [tab] key.
It's easy to type in cp, mv, and other existing file names while complementing them appropriately.
In this example, since it is the end supplement, enter the same file name as complementary twice and
Finally, turn off the space in [backspace] and bring the cursor right after .txt.old.
If you're used to Emacs (including Oira), yaegashi's Emacs-bind is more fun, but
From the perspective of people around Oira, it seems that even people who are not used to it can supplement [tab] without any discomfort.
GNU cp only, but
$cp-bf-S.old file file
$ ls
file file.old
You can omit .old
by setting the environment variable SIMPLE_BACKUP_SUFFIX
to .old
.
$exportSIMPLE_BACKUP_SUFFIX=.old
$ cp-bf file file
$ ls
file file.old
Personally, I think it's better to number it to avoid overwriting backups than to add .old
.
$cp--backup=t-file file←first time
$ cp--backup=t-file file←second time
Or
$exportSIMPLE_BACKUP_SUFFIX=numbered
$ cp-bf file file ← 1st time
$ cp-bf file file ← 2nd time
The result is
$ls
file.~1~file.~2~
You can also use the same option for mv
ln
install
patch
.
For some reason, no one mentioned the history development function of bash
, so I will write it down.You can use the history expansion (enabled by default in the interaction shell) specification to do exactly the same thing as a questionnaire.In other words,
Example
cp very-long-filename.txt very-long-filename.txt.old
cp very-log-filename.txt!#:1.old
You can write !#:1
is the specification of the history deployment.The meaning is !
(=History Deployment) #
(=Current Command Line) :
(='s) 1
(='s) 1
( )'s first word).When you run the above, the command contents are expanded to cp very-long-filename.txt very-long-filename.txt.old
and then executed.
For more information on how to specify a history deployment, you should visit manbash
.Historical deployment is easy to make mistakes, so it is recommended that you do not run it directly while you are not used to it, but deploy it once using the command M-^
(history-expand-line).Specify a history deployment !~
at the command line, and then press M-^
to replace the contents of the command line with the contents after the history deployment.
You can also use the for statement.
for fin very-long-filename.txt;docp$f$f.old; done
© 2024 OneMinuteCode. All rights reserved.