Changing directory CLI shortcuts

I’ve been doing this for a few decades, but I figured some of you aren’t aware of this, I thought I’d post this simple tip. If your in a terminal and want to say, switch to your git directory off your Downloads directory, and your in your home directory, (in this example) you can simply do a “cd Dow*/git” (minus the quotes). This can apply to any path. 3rd edit is a charm I hope. lol

3 Likes

I do not quite understand. Obviously this will work only for non ambiguous paths, like not for “Do*/git” which could mean Downloads as well as Documents, right?
So, lets imagine you are typing “cd Dow” and at this point you have a choice, either to type Shift + 8 to get an asterisk or a single key - Tab - to autocomplete “Downloads”. And then proceed with “/git” in both cases. What would be the advantage of typing asterisk?

First of all I have to say, this is the kind of thing I love about communities in general. Here is a topic and at this point has two replies that some people might look at and think “Well of course, why would you take the time to type that all out it is so basic and well known”. On the other hand you have people (present company included and implied) who have used Linux for years (12) and have never come across either of these things. I have probably heard them mentioned on podcasts but have never taken the time to try. I have a couple situations where neither answer is the perfect solution but combined they will change my life if I take the time to develop the muscle memory. Thank you so much.

2 Likes

I tend to use tab completion rather than this approach but I concur that these kinds of tips are gold and exactly why I love community forums. Thanks for posting this.

1 Like

I mostly agree with you, but there could be cases where this solution is better.

For example, you can make this into an alias to enter the Firefox profile dir (assuming only a single profile exists):
alias cdmoz='cd $HOME/.moz*/f*/.default/’
The "moz
" and “f*” are just for show and have no practical purpose, but the *.default is an easy way to enter the profile dir by simply typing “cdmoz”.

Another reason to use globs could be if the directory is on a remote media, that you are not currently connected to, so you cannot list the subdirs or you would need to resume the connection first, making the listing very slow.
ssh servername ‘ls -al $HOME/.mozilla/firefox/*.default’
This method would allow you to write out the entire command in one go and only have the delay after you press enter, in which case you could be doing something else instead of waiting before you can complete the command.

4 Likes