[SOLVED] shortcut sought through directory thicket ....
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Currently, due to my adding a non-root user for myself yesterday, I have a pathway in my directories such as:
(the pathway in question extending from command line prompt at highest level ie: michael@tex:/home$)
/home/michael/Documents/journals/aujour/diary.txt
Question: I read an entire article on directory hierarchies last night, hoping to find a short cut from root of pathway to *any* node in a given pathway, but the only "shortcut" I found was:
$ ./<directory name of child directory> which is no shortcut at all, since cd <directory name> would do the same...
Seems I must have misunderstood something, as I feel sure that there must be a way of going from anywhere "up-stream" to anywhere "down-stream" *in the absolute pathway*, by a shortcut nominating the target "down-stream", without having to type all the intervening directory elements.
With a hierarchical filesystem, directory navigation at the command line can be a bit of a chore. But you can often avoid having to type the entire directory string by using an asterisk in each directory name at an unambiguous prefix.
For example, if I am in my home directory and I want to navigate to ~/docs/photography/Beseler/45A_head/Beseler 45A manual, I could type the full path on the change directory command or I could specify the smallest unambiguous prefix at each directory level, which in my case would be "cd do*/pho*/Be*/4*/B*".
This:
cd do*/pho*/Be*/4*/B*
is a lot faster to type than this:
cd docs/photography/Beseler/45A_head/Beseler\ 45A\ manual
With a hierarchical filesystem, directory navigation at the command line can be a bit of a chore. But you can often avoid having to type the entire directory string by using an asterisk in each directory name at an unambiguous prefix.
For example, if I am in my home directory and I want to navigate to ~/docs/photography/Beseler/45A_head/Beseler 45A manual, I could type the full path on the change directory command or I could specify the smallest unambiguous prefix at each directory level, which in my case would be "cd do*/pho*/Be*/4*/B*".
This:
cd do*/pho*/Be*/4*/B*
is a lot faster to type than this:
cd docs/photography/Beseler/45A_head/Beseler\ 45A\ manual
okay, but since making this post, I have discovered by trial and error that, when logged in as root, one can use:
~./ <target_directory_name>
in order to jump from root, skipping multiple steps, to a targetted directory in a path.
Is that strictly a feature of root's privileges, non-extendable to the non-root trees?
Can you give a concrete example of what you are referring to?
Here are some useful shortcuts.
cd . (change to current directory, not especially useful)
cd .. (change to parent directory of the current directory)
cd (with no argument, change to your home directory)
cd / (change to the root directory)
cd - (change to the last directory you were in)
If you are at the /usr directory and you type cd ./src, it will go to /usr/src. But you could just as well type cd src. The ./ that you show in your example is implied in the cd command argument (i.e., current working directory), so you don't have to specify it.
Can you give a concrete example of what you are referring to?
Here are some useful shortcuts.
cd . (change to current directory, not especially useful)
cd .. (change to parent directory of the current directory)
cd (with no argument, change to your home directory)
cd / (change to the root directory)
cd - (change to the last directory you were in)
If you are at the /usr directory and you type cd ./src, it will go to /usr/src. But you could just as well type cd src. The ./ that you show in your example is implied in the cd command argument (i.e., current working directory), so you don't have to specify it.
Thanks Z, this clarifies the matter: in other words: use threshold redundancy principle when navigating at CLI.
(I must have been sleep deprived when I wrote the above concerning use of cd ~./, since just then, I went and typed:
In the context of bash (& other shells), '~' is a synonym for your home dir eg /home/you (as specc'ed in your entry in /etc/passd).
The shell var $HOME means the same thing.
In the context of bash (& other shells), '~' is a synonym for your home dir eg /home/you (as specc'ed in your entry in /etc/passd).
The shell var $HOME means the same thing.
Take a look at the CDPATH variable too. You can set it to a colon-separated list of directories that bash will look into when you use the cd command.
If your CDPATH contains "/home/michael/Documents/journals", for example, then "cd aujour" will take you directly to "/home/michael/Documents/journals/aujour".
There's also the cdable_vars shell option that, when enabled, will allow you to store directory paths in variables and cd into them using that variable name as the argument.
Next, you can always create an alias or shell function that you can call to jump directly to a set location.
Finally, I know I've seen several scripts/commands in the past that people have written for quick directory navigation, such as jumping up n levels at once. Try a web search or two.
PS: Just for accuracy, "." and ".." are not shell shortcuts of some kind, but actual directory names. *NIX filesystems automatically create them as hard links to the current and parent directories, respectively.
Last edited by David the H.; 05-17-2013 at 02:40 PM.
Reason: Some additions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.