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 ( @tvcvt@lemmy.ml ) 49•2 years agoI 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 youls ~/Downloads
and then decide you want to go there, you cancd !$
.:h
removes the last piece of a path. So I can dovim /etc/network/interfaces
and thencd !$:h
will take me to/etc/network
.
Bugamn ( @Bugamn@lemm.ee ) 9•2 years agoBesides using
!$
,alt+.
on bash copies the last argument into the line you are typing, which might be better if you want to edit it.I’ve used the
cd -
several times, it is very handy. the others are new to me so I’ll check it out. vort3 ( @vort3@lemmy.ml ) 2•2 years agoI might be wrong here, but “cd” without any arguments works as “cd -” for me.
puttputt ( @puttputt@beehaw.org ) 6•2 years agocd
without arguments takes you to$HOME
, so it’s the same ascd ~
ExLisper ( @ExLisper@linux.community ) English2•2 years ago!$ 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.
datavoid ( @datavoid@lemmy.ml ) English1•2 years agoNothing like extremely cryptic shell scripts
ExLisper ( @ExLisper@linux.community ) English2•2 years agoI don’t use it in scripts, only when typing.
datavoid ( @datavoid@lemmy.ml ) English1•2 years agoFair enough… i’ll have to test it out
zikk_transport2 ( @zikk_transport2@lemmy.dbzer0.com ) 1•2 years agoA couple things that I use
Don’t you use something like
cd ../..
orcd ../networks
? 😅 WorseDoughnut 🍩 ( @worsedoughnut@lemdro.id ) English1•2 years agoNot sure if you just misread the commands or not, but that’s a pretty different usecase than what they’re describing.
veroxii ( @veroxii@aussie.zone ) 45•2 years agoYou’re pressing the tab key for auto completion right?
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 ( @ReversalHatchery@beehaw.org ) 7•2 years agoAlso 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 withls -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 fromls
tocd
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 ( @BastingChemina@slrpnk.net ) 2•2 years agoIt 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.
I have been doing that, useful on Windows as well and I do that mess for my job now.
einsteinx2 ( @einsteinx2@programming.dev ) 5•2 years agoI 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…
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!
einsteinx2 ( @einsteinx2@programming.dev ) 2•2 years agoWeird the keyboard didn’t work but glad the double tap did! It’s definitely clutch
ReversalHatchery ( @ReversalHatchery@beehaw.org ) 3•2 years agoOh 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 zikk_transport2 ( @zikk_transport2@lemmy.dbzer0.com ) 2•2 years agoWait until you try “oh-my-zsh”… 😅 That’s autocompletion on steroids lol.
Nightwatch Admin ( @nightwatch_admin@feddit.nl ) 17•2 years agoI am old and I like ‘mc’ (Midnight Commander) a lot when doing many/complex file operations
lemmyvore ( @lemmyvore@feddit.nl ) English4•2 years agoReminder that mc has the ability to make directory bookmarks (Ctrl + /).
lemmyvore ( @lemmyvore@feddit.nl ) English15•2 years agoSomething 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 ( @CoderKat@lemm.ee ) English5•2 years agoAlso, 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 ) 3•2 years agoYou 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```
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!
orizuru ( @orizuru@lemmy.sdf.org ) 14•2 years 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.
-
sounddrill ( @sounddrill@lemmy.antemeridiem.xyz ) English12•2 years agoI simply use ls and spam cd xyz cd … etc
DrOps ( @DrOps@feddit.de ) 11•2 years agoI did 4 things, that helped me a lot:
- Make aliases for the most visited directories
alias cem=’cd /home/drops/.config/emacs’
- Make aliases for moving up the tree tree:
alias. .=’cd. . && ls’
Three points for two levels up, etc…
-
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
-
Use the option to jump to subdirectories of /home/user from everywhere.
Ricaz ( @Ricaz@lemmy.ml ) 3•2 years agoInstead 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.Ranger looks like how my brain wants to work. I’ll have to check that out. I like the idea of symlinks too.
- bdonvr ( @bdonvr@thelemmy.club ) 11•2 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)
Damn, that is incredibly useful. Thanks!
Gryzor ( @Gryzor@lemmyfly.org ) English5•2 years agoAlso check https://github.com/junegunn/fzf and https://github.com/ajeetdsouza/zoxide
Two great utilities that will reduce the number of file jumping and searching you need to do. :)
More useful tools: https://zaiste.net/posts/shell-commands-rust/
257m ( @257m@lemmy.ml ) 10•2 years agoFor 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 ( @skimm@lemmy.sdf.org ) 5•2 years agoI’ve got to agree. It’s replaced z for me and its just a great multipurpose tool
maor ( @maor@lemmy.org.il ) 3•2 years agoI’m using both of them:) zoxide comes with a
zi
command which lets you search through your recent directoriesI will definitely look into this, thank you
furikuri ( @furikuri@programming.dev ) 1•2 years agoAgreed, 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
andexa
but they can easily be swapped out forfind
andls
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)"'
Coelacanthus ( @Coelacanthus@lemmy.kde.social ) 9•2 years agoI just use
ls
,cd
,tree
and tab completion. Sometimes I will userg
to find files which contains specified string, and uselocate
to find files which I known name but path. smileyhead ( @smileyhead@discuss.tchncs.de ) 4•2 years agoJust learned about
rg
, thanks.
exylos ( @exylos@jlai.lu ) 9•2 years agoTo 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.
snekerpimp ( @snekerpimp@lemmy.dbzer0.com ) 8•2 years agoThe Linux Command Line is a book I still go back and look stuff up in.
A meaty tome! That looks super handy to have around though.
witx ( @witx@lemmy.sdf.org ) 8•2 years agoNot necessarily navigation, but
ncdu
will give the total size of your directories. It’s a simple but very useful toolOh 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.
Rescuer6394 ( @Rescuer6394@feddit.nl ) 8•2 years agoi have broot, an interactive tree
slembcke ( @slembcke@lemmy.ml ) 7•2 years agoThere 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