Best practices for navigating file structure via terminal?

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!

wuphysics87,

I’m surprised I didn’t see fasdfasd (pronounced ‘fast’) uses ‘frecency’ (frequency + recently) in order to jump to or open your most frecent documents or directories. A dumber version is z which works as a supliment to cd

phoenixz,

Take some bash tutorials on the internet there are loads of them

Learn rsync, it’s the best!

I’ve been a 20 year Linux desktop and server user. I spent my time either in an IDE for development, on a browser, or in shells. Last time I touched a graphical file manager has been years ago, if not decades. Cli shells are so so so so so much more efficient in getting shit done than GUI programs it’s not even funny.

Welcome to the dark side, we have cookies!

If you use Linux desktop (you should, it rocks, use KDE!) then install yakuake! It’s the friggin best awesome thing ever! F12 and 25 shells drop down on my screen. F12 and I got my browser back.

Father_Redbeard,
@Father_Redbeard@lemmy.ml avatar

I just finished buttoning up my new PC build and installed Linux on it, actually. Pop!_OS though because I like the layout and it’s very un-Windows-like which is what I was after. I’m excited to learn more!

phoenixz,

Still, get yakuake. It’s probably my favorite apo

Father_Redbeard,
@Father_Redbeard@lemmy.ml avatar

I will! Looks slick. Thanks for the input.

Nalivai,

I find that zsh with plugins makes my life very easy. And if I need to quickly find something, fzf works wonders

Zucca,

cd, find, pushd, popd and last but not least https://github.com/jarun/nnn.

lloram239,

cd - is an easier alternative to pushd/popd.

Zucca,

Yes. It’s (cd -) in most cases much more convenient.

WhyIsItReal,

if i’m not really sure what the contents of a given folder are, and i want to look into files as i go, i’ll often just open vim in file explorer mode

Father_Redbeard,
@Father_Redbeard@lemmy.ml avatar

Pardon the ignorant question, but can you do that with a headless server as your target? I’ve not used Vim at all.

Shinji_Ikari,
@Shinji_Ikari@hexbear.net avatar

Yes, vim is a command line program.

If you look up “Cli file manager”, there’s a bunch that you can check out and try.

Tree, grep, and find are usually my three go-tos. Tree to get a general view of a ton of nested files/folders, then if I know a name I’ll use find . -name “filename”, if I know a bit of contents, i’ll use `grep -re “content string” to find files containing that.

I recommend reading the man pages because you can often chain together these in fairly powerful ways.

Father_Redbeard,
@Father_Redbeard@lemmy.ml avatar

Awesome! You’ve given me some reading material. Thanks.

Coelacanthus,
@Coelacanthus@lemmy.kde.social avatar

I just use ls, cd, tree and tab completion. Sometimes I will use rg to find files which contains specified string, and use locate to find files which I known name but path.

smileyhead,

Just learned about rg, thanks.

TheFriendlyArtificer, (edited )

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.

skimm,

When did alacritty die? I thought it was still actively maintained. Maybe I missed an important commit somewhere but it looks active as of now?

TheFriendlyArtificer,

Maybe I was wrong? Gonna check again. Alacritty was my fave. Hopefully I misread something.

skimm,

Perhaps when it was under jwilms original repo and now its under the alacritty org. Looks like it’s going strong and moving from yaml to toml config, which makes me happy.

jernej,

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 autocomplete

nathris,

I 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.

bellsDoSing,

That’s one of the reasons why the more modern fd is a nice alternative: it accepts command line args as you’d expect.

BaumGeist,

Also every other search program has the needle as a positional argument and either reserves a named parameter to specify haystack, or has the haystack come after.

Apparently the find devs thought users would spend more time using it as an alternative to ls -a than finding specific files

brokenix,
@brokenix@emacs.ch avatar

@BaumGeist @nathris try zsh plugins/ widgets in term, that helped me

palordrolap,

Depending on system, something like locate/mlocate might be installed, and is almost certainly available if the following seems like a good idea.

Tools/daemons like them are quicker for finding files - basically because they index all files except those in specified places. (Or potentially only those in specified places depending on tool/configuration.)

That way, rather than find -name 'some_wildcard_string', it's instead locate 'partial_filename_match or locate --regex 'some_regex_string'.

As for speed: locate / | wc -c returned 565035, the count of files currently indexed by mlocate on my computer, in 0.3 seconds. Quite a bit quicker than find! (locate / literally returns any file with a / in the full pathname, which basically means every single file in its DB).

craigevil,
@craigevil@lemmy.ml avatar

I tend to use walk or midnight commander. zoxide is nice as well. It also helps to have bash aliases. github.com/antonmedv/walk

github.com/ajeetdsouza/zoxidemidnight-commander.orgwww.hostinger.com/tutorials/linux-commands

nik282000,

mc is killer. All the features of a desktop file manager but in your terminal!

sentinel1980,

@craigevil @Father_Redbeard

Hi I use Ranger in BASH terminal a lot, let me weigh in on how very useful it is and how easy to customize to my needs it has been. There is a similar app written in C++ But I couldn't script it as easy. Until I found Ranger I also used MC as my workhorse.

pedroapero,

You can quickly display the filesystem hierarchy using the tree command.

Father_Redbeard,
@Father_Redbeard@lemmy.ml avatar

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.

witx,

Not necessarily navigation, but ncdu will give the total size of your directories. It’s a simple but very useful tool

Father_Redbeard,
@Father_Redbeard@lemmy.ml avatar

Oh that is handy. I’ve been trying to figure out wtf is taking up so much room on my VPS that’s only running Miniflux and Wallabag.

karet,

Check out ranger fm, helps navigate through files very quickly, also has a ton of features

humanplayer2,
@humanplayer2@lemmy.ml avatar

lf sounds interesting, too. Haven’t tried it yet. The link is a guide on migrating from ranger.

Presi300,
@Presi300@lemmy.world avatar

Use the fish shell… No, seriously it’s autocomplete and tab functionality makes browsing directories through the terminal so much easier

Father_Redbeard,
@Father_Redbeard@lemmy.ml avatar

lol, their website is delightfully retro. Only thing missing is a random GIF that has no context, just there to grab attention. fishshell.com

lemmyvore,

Something I haven’t seen mentioned here is Ctrl + R on the command line to quick-search history. You start typing/backspacing and it shows the most recent matching history entry. Press Ctrl + R or Ctrl + Shift + R to navigate up and down through matching entries. Press Enter to pick an entry, Ctrl + C to cancel.

Father_Redbeard,
@Father_Redbeard@lemmy.ml avatar

I saw that mentioned in another comment and I’ve been testing it out while I try to get Cryptpad installed on my VPS and its very nice!

CoderKat,

Also, if OP is new, they may not yet be aware of aliases and functions. Generally you’d out those in a ~/.bashrc file that gets automatically executed when a terminal starts. They’ll allow you to save a more complex command as a really simple one. And particularly can be useful when things you want to run are in unusual directories. Eg, maybe you have a git repo somewhere that contains some project you spend most of your time on, so you could have an alias that just cd’s you to it’s directory. Git also has its own way of doing aliases and that’s really nifty for the more complicated git commands (or the more commonly used, like st for status).

Undearius,
@Undearius@lemmy.ca avatar

You can also make this the default behaviour as you start typing a command.

Create ~/.inputrc and add these lines:


<span style="color:#323232;">$include /etc/inputrc
</span><span style="color:#323232;">
</span><span style="color:#323232;">## arrow up
</span><span style="color:#323232;">"e[A":history-search-backward
</span><span style="color:#323232;">## arrow down
</span><span style="color:#323232;">"e[B":history-search-forward```
</span>
slembcke,

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-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
  • All
  • Subscribed
  • Moderated
  • Favorites
  • linux@lemmy.ml
  • cubers
  • DreamBathrooms
  • ethstaker
  • magazineikmin
  • thenastyranch
  • ngwrru68w68
  • Youngstown
  • slotface
  • modclub
  • love
  • kavyap
  • everett
  • InstantRegret
  • mdbf
  • megavids
  • khanakhh
  • tacticalgear
  • osvaldo12
  • rosin
  • tester
  • GTA5RPClips
  • cisconetworking
  • Durango
  • Leos
  • normalnudes
  • anitta
  • provamag3
  • JUstTest
  • All magazines