Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 569  / 2 Years ago, sat, july 2, 2022, 5:17:12

I am looking for something that I can type to shorten a long path. This path happens to point to a separate hard drive, and I'm hoping that will help.


Background



  1. Our company has provided us with Ubuntu machines containing a system drive and a larger, faster work drive.

  2. Company policy says that all software development (meaning compiling of executable code, but not all work) must be done in a specific folder. Our anti-virus software has been configured not to block or quarantine changing executable files within a particular directory structure. Unfortunately (and I'm not sure I follow the details of this part) in order to prevent malware from infecting these whitelisted directories, they are multiple levels deep. In other words, all development work must be done at the end of an arbitrarily long path.

  3. I have successfully mounted the large hard drive at the path specified by the policy. In other words, the long and arbitrary path points to what (in DOS) I would call the root of the drive.


What I want



  • To be able to type cd foo and have the OS perform cd /my/company/arbitrary/path

  • To be able to use other Linux commands for copying / accessing files and get a similar substitution.

  • Ideally, though this is not essential, I would like the command prompt to display the shortened form of the path.


My question



  • If I use a "symbolic link" or "soft link" to get the OS to perform this substitution automatically, will this meet my needs, or does it have limitations that might affect my workflow down the line? (Reminder: not all my work will be done on this drive.)

  • Is there a smarter way of doing this? Can I take advantage of the fact that the path actually "points to" the mount point (or "root") of the physical device?

  • Are there additional tricks I can perform to shorten the command prompt to show the user-friendly shorter version of the current working directory when I'm within the work area?


More From » disk

 Answers
2

The usual ways of dealing with this are:



  1. Make a symlink in your local directory


     ln -s /very/long/path/to/some/folder/hidden/deep/in/the/file/system ~/foo

    You can now do cd foo from your local directory and that will take you to /very/long/path/to/some/folder/hidden/deep/in/the/file/system. Depending on how your system is set up, you may have to use cd -P foo for your setup to recognize that you are in /very/long/path/to/some/folder/hidden/deep.in/the/file/system and not in ~/foo. To illustrate:


     $ ls -l foo
    lrwxrwxrwx 1 terdon terdon 61 Jan 7 14:46 foo -> /very/long/path/to/some/folder/hidden/deep/in/the/file/system
    $ cd foo
    $ pwd
    /home/terdon/foo

    Now, do the same thing but with cd -P:


    $ cd -P foo
    $ pwd
    /very/long/path/to/some/folder/hidden/deep/in/the/file/system


  2. Make an alias for the command. Open your shell's config file (use ~/.bashrc if you are using bash) and add this line:


     alias cdfoo='cd /very/long/path/to/some/folder/hidden/deep.in/the/file/system'

    Then, save the file, open a new terminal, and run cdfoo. That will take you straight to /very/long/path/to/some/folder/hidden/deep.in/the/file/system.



  3. Store the name in a variable. Open your ~/.profile file (or ~/.bash_profile if that file already exists and you are using bash) and add this line:


    foo="/very/long/path/to/some/folder/hidden/deep/in/the/file/system"

    Now, either log out and log back in or run . ~/.profile to read the new variable definition. From now on, you will be able to do cd $foo and move to the target directory. Note that, if your path contains spaces or any other whitespace or globbing characters, you should quote the variable: cd "$foo".




Of the three choices above, the first (symlink) and the third (variable) let you do everything you want. With a symlink, you can cd foo and cp bar/file foo/ and everything else. What will be displayed in your prompt when you cd into it will depend on how your prompt is set up.


[#2122] Sunday, July 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
fittecanap

Total Points: 322
Total Questions: 100
Total Answers: 105

Location: Israel
Member since Tue, Nov 17, 2020
4 Years ago
;