How to make an “alias” for a long path?

前端 未结 10 1934
广开言路
广开言路 2020-12-22 17:58

I tried to make an \"alias\" for a path that I use often while shell scripting. I tried something, but it failed:

myFold=\"~/Files/Scripts/Main\"
cd myFold
         


        
10条回答
  •  -上瘾入骨i
    2020-12-22 18:15

    The preceding answers that I tried do not allow for automatic expansion (autocompletion) of subdirectories of the aliased directory.

    However, if you push the directory that you want to alias onto the dirs stack...

    $ pushd ~/my/aliased/dir
    

    ...you can then type dirs -v to see its numeric position in the stack:

     0  ~/my/aliased/dir
     1  ~/Downloads
     2  /media/usbdrive
    

    and refer to it using that number for most if not all commands that expect a directory parameter:

     $ mv foo.txt ~0  
    

    You can even use Tab to show the immediate subdirectories of the "aliased" directory:

     $ cd ~0/
     child_dir1    child_dir2
    

提交回复
热议问题