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 ~/Downloads
and then decide you want to go there, you cancd !$
.:h
removes the last piece of a path. So I can dovim /etc/network/interfaces
and thencd !$:h
will 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.
deleted by creator
The Linux Command Line is a book I still go back and look stuff up in.
A meaty tome! That looks super handy to have around though.
Others have mentioned using interactive tools like
zoxide
to 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
+fzf
regularly 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.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.
Learn to use
pushd
andpopd
Why use a separate command when “cd -“ works just fine to take you to the previous directory
Right, but what if the dir you want to return to was not the last one?
For example, you are working in two dirs and go into your home dir for something, now you can pop yourself back into your long ass hard to type working path.
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.
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/
In Linux, the
locate
command is crazy fast. I am amazed at how slow search is in Windows, compared to this.I use ls and ranger, to find files i use
find -name
and 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 autocompleteThere 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-open
will 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
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
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
mc
is killer. All the features of a desktop file manager but in your terminal!
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
pushd
andpopd
are good for keeping a history and going back to different directories.
pushd and popd may be useful
You can quickly display the filesystem hierarchy using the
tree
command.Yeah I’ve been messing with that. I like that you can limit how deep you want to go, like if you just want to see folders but not the files within, for example.