On Sat, Jul 1, 2023, at 09:03, Bernhard Voelker wrote:
> On 7/1/23 14:12, Sergey Ponomarev wrote:
>  > To rename a file a user need to use mv command and specify the DEST dir:
>  >
>  >      mv /some/very/long/path/file /some/very/long/path/
>  >
>  > This makes it not so easy to use when typing a command but also makes a
>  > script line longer.
>
> Assuming you meant
>
>    $ mv /some/very/long/path/file /some/very/long/path/file2
>
> as in the other example - this could be done with:
>
>    $ cd /some/very/long/path && mv file file2
>
> or (with GNU coreutils' env):
>
>    $ env -C /some/very/long/path mv file file2
>
> Have a nice day,
> Berny

If you use bash and if your long paths are consistent (i.e. often referring
to the same source or destination each time) then another approach is to just
enable the bash 'direxpand' option, define some short envars in your
.bash_profile or .bashrc, and use those to facilitate commandline (and
script) operations, e.g.

  export p1=/long/path/to/some/frequently/accessed/directory
  export p2=/another/long/path/to/a/frequently/accessed/directory

Then, for cmdline ops, just typing 

  $ mv $a/<tab>

immediately expands $a (inline on the commandline) to 

  $ mv /long/path/to/some/frequently/accessed/directory/ 

and you can then tack on "$b" (or any other destination).

The 'direxpand' option provides nice immediate feedback that the envar you
selected is the correct one (among, presumably, several 1-letter envars
you've defined like this for various long paths of interest.)

I use this approach frequently in my own workflow when dealing with
annoyingly long but consistent paths.

Glenn


Reply via email to