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!

  • tvcvt@lemmy.ml
    link
    fedilink
    arrow-up
    70
    ·
    10 months 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.
    • Father_Redbeard@lemmy.mlOP
      link
      fedilink
      arrow-up
      12
      ·
      10 months 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
        link
        fedilink
        arrow-up
        7
        ·
        10 months 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.

        • BastingChemina@slrpnk.net
          link
          fedilink
          arrow-up
          2
          ·
          10 months ago

          It does not work on all terminal but you can also your the beginning of a command then the up key. It will show you only the previous command that start the same way.

      • einsteinx2@programming.dev
        link
        fedilink
        arrow-up
        5
        ·
        10 months ago

        I use Termius on iOS and double tapping the screen sends a tab (I may have enabled it in settings but I don’t think so). I think you can also put a button for it above the keyboard. In any case it does work for tab completion. I know I’m on iOS and not Android but I’d be really surprised if the Android version had no way to send a tab…

        • Father_Redbeard@lemmy.mlOP
          link
          fedilink
          arrow-up
          2
          ·
          10 months ago

          You are correct, I just tried it. I have a keyboard on my Galaxy Tab S7+ and it will recognize the Tab key in normal text entry fields but doesn’t seem to work in Termius. The double tap is pretty clutch!

      • ReversalHatchery@beehaw.org
        link
        fedilink
        arrow-up
        3
        ·
        10 months ago

        Oh and then there’s ncdu too with which your can navigate your fs, but that won’t allow you to open files, it is for finding what takes a lot of space.
        The vim text editor can also let you browse directories and open files in them, when you pass a folder’s path to it. But that may be an extension now that I think about it… maybe tpope’s plugin loader does it? But maybe it isn’t so it’s easiest to just try it out

    • SnachBarr@lemm.ee
      link
      fedilink
      arrow-up
      8
      ·
      10 months ago

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

      • teawrecks@sopuli.xyz
        link
        fedilink
        arrow-up
        11
        arrow-down
        1
        ·
        10 months 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"
        
        • z3bra@lemmy.sdf.org
          link
          fedilink
          arrow-up
          3
          ·
          10 months ago

          You mean

          cd a
          pushd b
          pushed c
          popd
          popd
          

          Right ?

          Depending on your shell, pushd/popd might not be an option. For a similar functionality, I like to use a subshell which is portable across all shells:

          cd a
          $SHELL
          cd b
          cd c
          # do work here
          ^D
          # you're back in "a"
          
      • kool_newt@lemm.ee
        link
        fedilink
        English
        arrow-up
        2
        ·
        10 months ago

        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.

  • inspxtr@lemmy.world
    link
    fedilink
    arrow-up
    21
    ·
    10 months 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.

  • lemmyvore@feddit.nl
    link
    fedilink
    English
    arrow-up
    19
    ·
    edit-2
    10 months 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
      link
      fedilink
      English
      arrow-up
      7
      ·
      10 months 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.mlOP
      link
      fedilink
      arrow-up
      5
      ·
      10 months 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!

    • Undearius@lemmy.ca
      link
      fedilink
      arrow-up
      3
      ·
      10 months ago

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

      Create ~/.inputrc and add these lines:

      $include /etc/inputrc
      
      ## arrow up
      "\e[A":history-search-backward
      ## arrow down
      "\e[B":history-search-forward```
      
  • orizuru@lemmy.sdf.org
    link
    fedilink
    arrow-up
    18
    ·
    10 months 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.

  • bdonvr@thelemmy.club
    link
    fedilink
    arrow-up
    16
    ·
    10 months 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)

  • DrOps@feddit.de
    link
    fedilink
    arrow-up
    16
    ·
    10 months 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.

    • Dandroid@sh.itjust.works
      link
      fedilink
      arrow-up
      4
      ·
      edit-2
      10 months ago

      Instead of aliases, I use variables that I set in my .bashrc.

      For example, on WSL I have export WINDOWS_HOME=/mnt/c/Users/username. Then I can just cd $WINDOWS_HOME. Or cp $WINDOWS_HOME/Downloads/some_file .

    • Ricaz@lemmy.ml
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      10 months ago

      Instead of aliases, I just have lots of symlinks in my homedir.

      I do have .. and ... aliases though.

      Mostly if I’m gonna work with files I just use ranger, or FZF from my shell to find stuff.

      • Father_Redbeard@lemmy.mlOP
        link
        fedilink
        arrow-up
        1
        ·
        10 months ago

        Ranger looks like how my brain wants to work. I’ll have to check that out. I like the idea of symlinks too.

  • Coelacanthus@lemmy.kde.social
    link
    fedilink
    arrow-up
    11
    ·
    10 months 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.

  • 257m@lemmy.ml
    link
    fedilink
    arrow-up
    11
    ·
    10 months 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

    • furikuri@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      10 months ago

      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 and exa but they can easily be swapped out for find and ls 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)"'
      
  • cizra@lemm.ee
    link
    fedilink
    arrow-up
    11
    ·
    10 months ago

    In Linux, the locate command is crazy fast. I am amazed at how slow search is in Windows, compared to this.

      • wolfshadowheart@kbin.social
        link
        fedilink
        arrow-up
        12
        ·
        10 months ago

        But after the 2.5 years it takes to build the Windows index wouldn’t it be the same - just searching through a built index?

        • whodatdair@lemm.ee
          link
          fedilink
          arrow-up
          3
          ·
          10 months ago

          lol i remember hunting and systematically ripping out the file indexer in like vista? I think? It was terrible lol

          • wolfshadowheart@kbin.social
            link
            fedilink
            arrow-up
            5
            ·
            10 months ago

            It was honestly hilarious how bad it was and how much it could slow the system down in some situations. I’d be curious to see just how much of it was a byproduct of HDD’s - that is to say, just how slow is it even in solid state drives!

        • deong@lemmy.world
          link
          fedilink
          arrow-up
          3
          ·
          10 months ago

          It’s been a while since I’ve had a Windows machine, but doesn’t Windows index the content of files as well as their names? If so, that would have fairly profound differences from slocate.

        • m_r_butts@kbin.social
          link
          fedilink
          arrow-up
          3
          ·
          10 months ago

          I forgot that. I have never used the built-in Windows search. I hated it in XP and would just drop to a command prompt to find shit, then eventually started using Agent Ransack instead.

      • cizra@lemm.ee
        link
        fedilink
        arrow-up
        4
        ·
        10 months ago

        Windows has a pre-built index as well (or at least it has a search indexer service that enjoys as warm a CPU as possible). That doesn’t appear to improve the speed of search, though.

        • vort3@lemmy.ml
          link
          fedilink
          arrow-up
          2
          ·
          10 months ago

          Unless you use everything (that’s what the software is called) to search.

          It’s so fast I’m amazed why microsoft can’t have something similar out of the box.

  • exylos@jlai.lu
    link
    fedilink
    arrow-up
    10
    ·
    10 months 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.