0

I often need to create copy of files in varios locations(, and want to avoid excessive typing). (Then I will edit them)

Basically commands are like:

cp very/long/path/to/file/my-file_with-long.name very/long/path/to/file/my-file_with-long-another.name
vim very/long/path/to/file/my-file_with-long-another.name
cp even/longer/path/to/other/location/with_another-file_and-stupid.name even/longer/path/to/other/location/with_another-file_and-stupid-copy.name
vim even/longer/path/to/other/location/with_another-file_and-stupid-copy.name

I really want to avoid changing workdir with cd and typing the same path twice. Basically I can add command into bashrc like mydup, so it will create new file and return its name, so I cam use:

vim $(mydup very/long/path/to/file/my-file_with-long.name -another)
vim $(mydup even/longer/path/to/other/location/with_another-file_and-stupid.name -copy)

But maybe I invent bicycle and there is easier way to do the same?

2 Answers 2

1
cp /very/long/file/path{,.bak}

vim !$

or

cpvi() {
    name=$1
    cp "${name}" "${name}.bak"
    $EDITOR "${name}.bak"
}

cpvi /very/long/file/path
1
  • oh thank you - vim !$ is gamechanger :)
    – noonex
    Commented Sep 30, 2017 at 8:19
0

You can copy a file in-place, without changing directories. E.g.

cp very-long-file-name very-long-file-name.copy
vim very-long-file-name.copy

In this case, bash-completion and tab key is your friend. I do it all the time and I never write too much.

5
  • but I must use cd for that (and then cd back) and it is really not the best solution I consider at the moment, but thx anyway
    – noonex
    Commented Sep 28, 2017 at 11:19
  • I presume that the paths are pretty unique, so bash can automatically complete it with a single tab?
    – bayindirh
    Commented Sep 28, 2017 at 11:22
  • Also, if you access same paths over times, you can just create symbolic links to a so-called warp-directory, so /very/long/directory/name becomes /warp/first.
    – bayindirh
    Commented Sep 28, 2017 at 11:24
  • no: there are many nested paths and many files in each
    – noonex
    Commented Sep 28, 2017 at 15:36
  • Oh, alright then. It seems that your case is different than I imagined.
    – bayindirh
    Commented Sep 28, 2017 at 22:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .