I’ve just started my Linux journey earlier this year. As a goal to learn how to self-host applications and services that will allow me to take back some control of my data. Immich instead of Google Photos, for example.
I have a local server running Unraid and 22 docker containers now. And then a VPS (Ubuntu 20.04 LTS) running two apps. I’ve learned a ton but one thing I can’t seem to wrap my brain around is navigation through the file structure using only terminal. My crutch has been to open a SFTP session in Cyberduck to the same device I’m SSH’d to and try to figure things out that way. I know enough to change directories, make directories, using Tree to show the file structure at different levels of depth. But I feel like I’m missing some efficient way to find my way to files and folders I need to get to. Or are y’all just memorizing it and know where everything is by now?
I come from a Windows background and even then I sometimes catch myself checking via explorer where a directory is instead of using CMD or PowerShell to find it.
I’d love to hear any tips or tricks!
EDIT: I’ve been using Termius because they have a great Android client, but I wasn’t about to pay $5/mo for sync. Especially to sync to someone else’s cloud. Which led me to Tabby, which I understand has quite a large footprint resource-wise. But I guess I either don’t know enough yet to be mad about it or it hasn’t impacted any of my systems negatively yet. No Android client though, but you can bring your own sync solution and it has a handy little shortcut to SFTP to the current directory you’re in. Between that and stuff like ranger, it’s made it so much easier to learn my way around!
I think it’s just a matter of getting used to it. I had the same issue at first and the more I used the command line, the more I started to prefer it to GUI apps for certain tasks.
A couple things that I use all the time:
- tab completion is incredible
cd -goes back to the last directory you were in (useful for bouncing back and forth between locations)!$means the last argument. So if youls ~/Downloadsand then decide you want to go there, you cancd !$.:hremoves the last piece of a path. So I can dovim /etc/network/interfacesand thencd !$:hwill take me to/etc/network.
Besides using
!$,alt+.on bash copies the last argument into the line you are typing, which might be better if you want to edit it.I’ve used the
cd -several times, it is very handy. the others are new to me so I’ll check it out.I might be wrong here, but “cd” without any arguments works as “cd -” for me.
cdwithout arguments takes you to$HOME, so it’s the same ascd ~
deleted by creator
Why use a separate command when “cd -“ works just fine to take you to the previous directory
deleted by creator
Others have mentioned using interactive tools like
zoxideto easily get to frequently visited directories.In addition, I also use
nnn(https://github.com/jarun/nnn), which is a terminal file manager that you can navigate through. You can create shortcuts, snippets and bookmarks with this. I use this andzoxide+fzfregularly on CLI to navigate.Some here also mention
ranger, which is another terminal file manager. In my limited experience withranger, I feel like the start up time is much slower thannnn; but I haven’t tried much. Tho withranger+ graphic-accelerated terminals likekitty, I believe you can preview images and files, which seems to be a great feature. So it depends on your need.Use the fish shell… No, seriously it’s autocomplete and tab functionality makes browsing directories through the terminal so much easier
lol, their website is delightfully retro. Only thing missing is a random GIF that has no context, just there to grab attention. https://fishshell.com/
Check out ranger fm, helps navigate through files very quickly, also has a ton of features
lf sounds interesting, too. Haven’t tried it yet. The link is a guide on migrating from ranger.
Useful one I find is the z program you can install it with package manager and it’s also included with zsh shell. It’s basically like a smart cd command. Instead of having to type the entire path for cd, when using z you can just type the destination folder and if it’s in your history it will resolve the path by itself.
I use ls and ranger, to find files i use
find -nameand remember that * is used as a wildcard so you can use it when searching for stuff with in incomplete filename or when copying or moving files/directories. You could also use colorls to add some flare to your ls, and oh-my-zsh for syntax highlighting and tab autocompleteI know there is probably a historical reason but I hate how find parses its arguments.
Any other app would be fine --name or find -n.
Every time I use it I have to spend a few minutes checking the results to make sure that it’s actually doing what I want it to do.
That’s one of the reasons why the more modern
fdis a nice alternative: it accepts command line args as you’d expect.deleted by creator
In Linux, the
locatecommand is crazy fast. I am amazed at how slow search is in Windows, compared to this.For navigating files quickly fzf is pretty much crucial to my workflow. Being able to get my home directory to the directory of the project I want to work on in two seconds flat is such a nice feeling after manually typing the path in for months. https://github.com/junegunn/fzf
Agreed, fzf (and similar fuzzy finders) have been a game-changer with regards to the way in which I navigate the shell. Add in a couple of one-liners and I’m never more than a second away from any nested directory
Here are some of the most used aliases in my configs if anyone would like to try it out
Note that they use
fdandexabut they can easily be swapped out forfindandlsif those aren’t available on your system (which would allow for shorter aliases since they’re the fzf defaults IIRC)alias update-cdd='fd -Ha -td -d1 -E "\.config" -E "\.local" "^\." ~ > ~/.cddignore' alias cdd='cd "$(fd -H -td --ignore-file ~/.cddignore . ~ | fzf --preview "exa -lF --no-permissions {}" --tiebreak=length,end,begin --preview-window=up,20%)"' alias cdf='cd "$(fd -H -tf --ignore-file ~/.cddignore . ~ | fzf --preview "bat --style=header-filename,header-filesize -r 40: --color=always {}" --tiebreak=length,end,begin --preview-window=up,20% | xargs dirname)"'
There are a few directory structures I have memorized, like my programming projects for instance. For everything else, I use the GUI. That’s what it’s there for. Mixing and match to get the best of both worlds. Some handy tips:
xdg-openwill act like clicking on a file in the GUI, and is an easy way to open folders from the terminal when you want to browse them.- Use sshfs or even just whatever is built into your desktop environment to connect to remote servers and browse them
- Most terminals let you drag files or folders into them to paste their paths
deleted by creator
pushd and popd may be useful
Just using “cd -” to go back where you were is useful.
history command and ! and the number in history, like
!123
For instance, it’s useful
you can also put !! for the most recent history entry, useful if you forget to put sudo
pushdandpopdare good for keeping a history and going back to different directories.
I tend to use walk or midnight commander. zoxide is nice as well. It also helps to have bash aliases. https://github.com/antonmedv/walk
https://github.com/ajeetdsouza/zoxide https://midnight-commander.org/ https://www.hostinger.com/tutorials/linux-commands
mcis killer. All the features of a desktop file manager but in your terminal!
Vifm is ridiculously customizable but also assumes that you’re competent with the modal paradigm of Vim.
If you’re in a WM, you can use a terminal emulator with SIXEL support (Alacritty is no longer maintained but Wezterm is great) and you can get image previews as well.
Even on a headless server, I love being able to predefine bookmarks.
A simple workflow would be,
'egoes to ‘/etc/’. HJKL to whatever directory I want, ZZ, then there I am.There’s so much more that can be done, though.
Edit: It looks like alacritty is alive! No idea why I had thought that it had been abandoned. Apologies for the accidental gaslighting.










