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!
deleted by creator
Why use a separate command when “cd -“ works just fine to take you to the previous directory
deleted by creator
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.
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.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.
cd
without arguments takes you to$HOME
, so it’s the same ascd ~
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/
That’s a good question 💯 In my case too, it took me some time (read years 😂) to figure out what I’m comfortable w/.
I can think of 3 major ways that you can navigate the filesystem while being able to drop to a shell when you need it:
- If you’re familiar w/ Emacs, you can either:
- Use
dired
andtramp
on your machine to access/navigate the target machine. - Install Emacs (
emacs-nox
) on the target machine, SSH and then runemacs-nox
and voila! No need fortramp
in this scenario.
- Use
- Use Midnight Commander (
mc
) which offers a TUI pretty much like Norton Commander (nc
) from the days of yore. - Get used to the semi-standard structure of the file system and just use plain Bash (
cd
,pushd
&popd
) to move around. That is- Understand what usually goes into common directories (like
/usr/share
or/opt
) and try to follow the same pattern when rolling your own software installations. - Learn how to use your distro’s package manager to query packages and find out where things, like configurations and docs, are stored. Something as simple as
rpm -q --list
is what you usually need.
- Understand what usually goes into common directories (like
HTH
- If you’re familiar w/ Emacs, you can either:
I felt the same. Simple tasks I do in terminal, but when I have to deal with too many files and folders I use filebrowser. Its amazing docker container with simple GUI
In Linux, the
locate
command is crazy fast. I am amazed at how slow search is in Windows, compared to this.I just type ls everytime I cd into something. It’s not that efficient honestly but I usually remember where I want to go after going there a couple times. Also if you hit tab twice after typing cd and a space, it shows all of the files in the directory.
That’s where I’m at now. And it does work. But I knew there had to be something out in the wild that folks use to traverse or at least understand where they are better. I do like Tree for a more in depth
ls
though. I don’t recall the options you can throw at the end of tree off the top of my head but you can specify how many layers you want to go down to see a visual of the file structure.
https://github.com/agkozak/zsh-z
Any directory in the filesystem is less than 5 key presses away
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
fd
andexa
but they can easily be swapped out forfind
andls
if 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)"'
Not to be “that guy”, but you can use a gui file manager to access your files the same way you do so in windows. Most of them support ssh keys as well. If you’d like to check out the cli stuff, nnn or ranger can be useful. Something like midnight as abckup is good too. Definitely install fzf on both your vps and local machine. You can also go over board and run xorg over ssh and run a small window manager, maybe awesomewm or even xfce (not that small but works fine).
I was speaking more towards my VPS , which of course has no OS GUI. In Unraid I do use the very nice GUI regularly though.
Midnight commander is a pretty nice alternative!
There are tools like sshfs that let you mount remote directories as if they’re local. Most of the time I tend to use nnn with some of the little extra bits you can find in the docs like cd to last directory on quit and multi-colored tabs etc.
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,
'e
goes 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.
I find that zsh with plugins makes my life very easy. And if I need to quickly find something, fzf works wonders
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.