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
    522 years 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
      link
      fedilink
      112 years 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.

    • @SnachBarr@lemm.ee
      link
      fedilink
      62 years ago

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

      • @teawrecks@sopuli.xyz
        link
        fedilink
        82 years 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"
        
      • Kool_Newt
        link
        fedilink
        English
        22 years 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
    152 years 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.

  • DrOps
    link
    fedilink
    132 years 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.

    • @Ricaz@lemmy.ml
      link
      fedilink
      3
      edit-2
      2 years 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.

    • Dandroid
      link
      fedilink
      2
      edit-2
      2 years 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 .

  • @bdonvr@thelemmy.club
    link
    fedilink
    112 years 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)

  • @cizra@lemm.ee
    link
    fedilink
    82 years ago

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

      • wolfshadowheart
        link
        fedilink
        82 years 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?

        • @deong@lemmy.world
          link
          fedilink
          22 years 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.

        • @whodatdair@lemm.ee
          link
          fedilink
          22 years ago

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

          • wolfshadowheart
            link
            fedilink
            42 years 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!

      • @cizra@lemm.ee
        link
        fedilink
        32 years 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
          22 years 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.

    • humanplayer2
      link
      fedilink
      12 years ago

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

  • @slembcke@lemmy.ml
    link
    fedilink
    7
    edit-2
    2 years 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
  • @ErnieBernie10@lemmy.world
    link
    fedilink
    72 years 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.

  • @257m@lemmy.ml
    link
    fedilink
    62 years 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

    • bayaz
      link
      fedilink
      22 years ago

      I love ranger. Mostly I just use the basic shell, but when I’m doing a lot of random file transfer, seeing what I’m doing with ranger is nice.

      It’s super fast and intuitive if you’re already into vim and vim-style keybindings.

  • @jernej@lemmy.ml
    link
    fedilink
    52 years 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

    • @nathris@lemmy.ca
      link
      fedilink
      42 years ago

      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@lemm.ee
        link
        fedilink
        3
        edit-2
        2 years ago

        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@lemmy.ml
        link
        fedilink
        22 years ago

        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

    • palordrolap
      link
      fedilink
      12 years ago

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