this post was submitted on 28 Aug 2023
9 points (90.9% liked)

Linux

48090 readers
773 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
 

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
[–] [email protected] 5 points 1 year ago (3 children)

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.
[–] [email protected] 1 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.

[–] [email protected] 1 points 1 year ago (3 children)

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)
[–] [email protected] 1 points 1 year ago (1 children)

!$ means the last argument. So if you ls ~/Downloads and then decide you want to go there, you can cd !$.

Nice, I usually do !!:n. This is a lot better.

[–] [email protected] 0 points 1 year ago

Nothing like extremely cryptic shell scripts

[–] [email protected] 3 points 1 year ago

I'm surprised I didn't see fasd fasd (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

[–] [email protected] 1 points 1 year ago (1 children)

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)

[–] [email protected] 1 points 1 year ago

Damn, that is incredibly useful. Thanks!

[–] [email protected] 1 points 1 year ago (1 children)

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

[–] [email protected] 0 points 1 year ago

A meaty tome! That looks super handy to have around though.

[–] [email protected] 1 points 1 year ago (1 children)
[–] [email protected] 1 points 1 year ago (2 children)

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

load more comments (2 replies)
[–] [email protected] 1 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.

[–] [email protected] 1 points 1 year ago (1 children)

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.

[–] [email protected] 1 points 1 year ago* (last edited 1 year 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 .

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (2 children)

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.

[–] [email protected] 1 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).

[–] [email protected] 1 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!

[–] [email protected] 1 points 1 year ago (1 children)

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

[–] [email protected] 1 points 1 year ago

Reminder that mc has the ability to make directory bookmarks (Ctrl + /).

[–] [email protected] 1 points 1 year ago (1 children)

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

[–] [email protected] 1 points 1 year ago (1 children)

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.

[–] [email protected] 1 points 1 year ago

Wait until you try "oh-my-zsh".. 😅 That's autocompletion on steroids lol.

[–] [email protected] 1 points 1 year ago (2 children)

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

[–] [email protected] 1 points 1 year ago (2 children)

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

[–] [email protected] 1 points 1 year ago

I will definitely look into this, thank you

[–] [email protected] 1 points 1 year ago

I'm using both of them:) zoxide comes with a zi command which lets you search through your recent directories

[–] [email protected] 1 points 1 year 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)"'
[–] [email protected] 1 points 1 year ago

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

[–] [email protected] 0 points 1 year ago* (last edited 1 year ago) (1 children)

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.

[–] [email protected] 0 points 1 year ago (1 children)

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

[–] [email protected] 0 points 1 year ago (1 children)

You kid, but I just ripped a bunch of old data CDs and decided to also scan their covers and stick them in the tar.gz file along with the images. Some of them were pretty creative.

[–] [email protected] 0 points 1 year ago (1 children)

Back when I started my dream was go have folders of DVDs of all things I would need. Luckily for me cheat fast HDDs became a thing. Still should burn atleast my favourite contents.

[–] [email protected] 1 points 1 year ago

Yeah. I recently bought a tape drive to do just that. Turns out fiber channel hbas are harder to get working than I thought. First one didn't fit, like physically the card was too long and hit the CPU fan power connector. Second one fit, but the computer wouldn't boot. Third I get a driver error, and since it's enterprise stuff the threads I find on it basically say 'contact your vendor'. At least they're really cheap. Should have spent the extra money for a SAS compatible one.

[–] [email protected] 0 points 1 year ago (1 children)

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.

[–] [email protected] 0 points 1 year ago (1 children)

Not sure if limited to certain emulators, alt+l should do that for you

[–] [email protected] 0 points 1 year ago* (last edited 1 year ago) (3 children)

I think pressing TAB sends Alt+I to the terminal so yeah.

load more comments (3 replies)
load more comments
view more: next ›