189
submitted 1 year ago* (last edited 1 year ago) by Father_Redbeard@lemmy.ml to c/linux@lemmy.ml

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!

top 50 comments
sorted by: hot top controversial new old
[-] tvcvt@lemmy.ml 71 points 1 year ago

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 you ls ~/Downloads and then decide you want to go there, you can cd !$.
  • :h removes the last piece of a path. So I can do vim /etc/network/interfaces and then cd !$:h will take me to /etc/network.
[-] Bugamn@lemm.ee 13 points 1 year ago

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.

[-] Father_Redbeard@lemmy.ml 5 points 1 year ago

I've used the cd - several times, it is very handy. the others are new to me so I'll check it out.

load more comments (3 replies)
load more comments (8 replies)
[-] veroxii@aussie.zone 55 points 1 year ago

You're pressing the tab key for auto completion right?

[-] Father_Redbeard@lemmy.ml 12 points 1 year ago

Um...no. I'll admit I didn't know that was an option. Weirdly I do it all the time in PowerShell. Though I am using Termius right now and at least on Android it doesn't support tab auto complete. That said, it does auto suggest as you type to get you in the ballpark. I'll have to try it again from my PC once I get my office put back together.

[-] ReversalHatchery@beehaw.org 7 points 1 year ago

Also make use of the up arrow on your keyboard, with which you can quickly reuse commands you have ran recently.
For example you search for a directory with ls -alh in multiple steps, and when you have found the one you actually want to work in, then you once again press up, and either edit the command from ls to cd to switch to it, or just edit it to your favorite text editors command and put the file name at the end of the path. Tab helps with that too.
Tab completion is done by the shell, not by the command you want to use, though worth mentioning that some tools install tab completion helpers your shell makes use of automatically.

load more comments (2 replies)
load more comments (6 replies)
[-] kool_newt@lemm.ee 26 points 1 year ago
[-] SnachBarr@lemm.ee 8 points 1 year ago

Why use a separate command when “cd -“ works just fine to take you to the previous directory

[-] teawrecks@sopuli.xyz 10 points 1 year ago
cd a
cd b
cd c
popd
popd
// you're now in "a"
cd a
cd b
cd c
cd -
cd -
// you're now in "c" and need to manually cd to "a"
load more comments (3 replies)
load more comments (1 replies)
[-] inspxtr@lemmy.world 21 points 1 year ago

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 and zoxide + fzf regularly on CLI to navigate.

Some here also mention ranger, which is another terminal file manager. In my limited experience with ranger, I feel like the start up time is much slower than nnn; but I haven’t tried much. Tho with ranger + graphic-accelerated terminals like kitty, I believe you can preview images and files, which seems to be a great feature. So it depends on your need.

[-] nightwatch_admin@feddit.nl 21 points 1 year ago

I am old and I like ‘mc’ (Midnight Commander) a lot when doing many/complex file operations

load more comments (2 replies)
[-] lemmyvore@feddit.nl 19 points 1 year ago* (last edited 1 year ago)

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.

[-] CoderKat@lemm.ee 7 points 1 year ago

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

[-] Father_Redbeard@lemmy.ml 5 points 1 year ago

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!

load more comments (1 replies)
[-] orizuru 18 points 1 year ago
  • ls / cd for basic stuff

  • fzf if I want to find my way through the history

  • broot if I want to search for a file

  • ripgrep if I want to find a file with specific contents.

I know that the last 3 are not available by default, but they are good pieces of software, so I'm just going to install them.

load more comments (1 replies)
[-] sounddrill@lemmy.antemeridiem.xyz 17 points 1 year ago

I simply use ls and spam cd xyz cd .. etc

[-] bdonvr@thelemmy.club 16 points 1 year ago

Not strictly file browsing advice, but you can quickly search for previously issued commands by hitting ctrl-r and starting to type. (and you can press it again to search further back)

load more comments (4 replies)
[-] DrOps@feddit.de 16 points 1 year ago

I did 4 things, that helped me a lot:

  1. Make aliases for the most visited directories

alias cem=’cd /home/drops/.config/emacs’

  1. Make aliases for moving up the tree tree:

alias. .=’cd. . && ls’

Three points for two levels up, etc...

  1. Name all directories lowercase, 3-5 letters long, and try to avoid directories with the same starting letter as siblings That way you can use tab completion with just a single letter

  2. Use the option to jump to subdirectories of /home/user from everywhere.

load more comments (3 replies)
[-] snekerpimp@lemmy.dbzer0.com 14 points 1 year ago

The Linux Command Line is a book I still go back and look stuff up in.

load more comments (1 replies)
[-] Coelacanthus@lemmy.kde.social 11 points 1 year ago

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.

load more comments (1 replies)
[-] 257m@lemmy.ml 11 points 1 year ago

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

[-] skimm 5 points 1 year ago

I've got to agree. It's replaced z for me and its just a great multipurpose tool

load more comments (2 replies)
load more comments (1 replies)
[-] karet@sh.itjust.works 10 points 1 year ago

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

load more comments (1 replies)
[-] exylos@jlai.lu 10 points 1 year ago

To navigate quickly between directories in ssh, I recommend you using zoxide as cd replacement.

Zoxide remembers the directories you visited, then you can jump to them very quickly.

[-] trompete@hexbear.net 10 points 1 year ago* (last edited 1 year ago)

What file structure? I just put everything in /home and then try to vaguely remember part of the filename and glob *part-of-filename*.

Ok, actually, every couple of years, I move all my files into a new directory, /home/old. I think I'm up to /home/old/old/old/old/old right now. I recommend using find to look for files in there.

[-] nestEggParrot 6 points 1 year ago

You should be putting them onto CDs. Lets you have cool covers to recognise them how old it is.

load more comments (3 replies)
[-] slembcke@lemmy.ml 10 points 1 year ago* (last edited 1 year ago)

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
[-] Rescuer6394@feddit.nl 9 points 1 year ago

i have broot, an interactive tree

[-] Presi300@lemmy.world 9 points 1 year ago

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

load more comments (1 replies)
[-] witx 9 points 1 year ago* (last edited 1 year ago)

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

load more comments (1 replies)
[-] ErnieBernie10@lemmy.world 8 points 1 year ago

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.

[-] SomeBoyo@feddit.de 8 points 1 year ago

Try a TUI like mc (midnight commander)

[-] buckykat@hexbear.net 7 points 1 year ago

cd, ls, and the tab key are the basic tools of terminal filesystem navigation

[-] jernej@lemmy.ml 7 points 1 year ago

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

load more comments (5 replies)
[-] shotgun_crab@lemmy.world 6 points 1 year ago

pushd and popd may be useful

[-] craigevil@lemmy.ml 6 points 1 year ago
load more comments (2 replies)
[-] Magister@lemmy.world 5 points 1 year ago

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

load more comments (4 replies)
[-] underisk@lemmy.ml 5 points 1 year ago

Look into your shell’s tab completion abilities, the find command, and fzf. There’s also stuff like midnight commander but I find that to be a little overkill for my tastes.

[-] Euphoma@lemmy.ml 5 points 1 year ago

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.

load more comments (8 replies)
[-] indigomirage@lemmy.ca 5 points 1 year ago

Old school, but I really like midnight commander or mc. Fast and easy.

Another good one is ranger - more concise, but great.

load more comments (2 replies)
load more comments
view more: next ›
this post was submitted on 28 Aug 2023
189 points (97.5% liked)

Linux

48375 readers
1165 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS