What's your most-used terminal trick nobody taught you?

Some of the best command-line habits aren’t from tutorials or docs. They’re weird little things you stumbled into or accidentally discovered while trying not to break something in production.

Whether it’s a clever alias, a one-liner you’ve used a hundred times, or a keybind that changed your life, drop your go-to terminal trick below.


Oh nice, this is your own post so you want to kick off the replies. Here’s a first-person reply you can drop in:


For me, it’s ctrl+r for reverse search in bash. I used to just hit the up arrow like 50 times trying to find that one command I ran earlier. :smile: Once I discovered reverse search I couldn’t believe I’d gone so long without it. Just hit ctrl+r and start typing any part of the command and it pulls it right up.

Close second would be !! to repeat the last command. Mostly because of sudo !! when you forget to run something as root.

5 Likes

If you just created a directory or moved a file and now want to interact with that same file/path, don’t type it out again. Use Alt +

  1. mkdir /var/www/html/my_new_project
  2. Type cd and then hit Alt +
1 Like

Been using the screen utility for years until tmux started to be included in distros instead.

With some use and research found the best way to make the session ‘reentrant’ to survive disconnections was to write a little script, viz.:

[…]
#!/usr/bin/bash

tmux start-server

#create a session with four windows
tmux new-session -d -AD -s 0 -n BTop btop
tmux new-window -t 0:1 -n “Midnight Commander” mc
tmux new-window -t 0:2 -n “Default Shell”
tmux new-window -t 0:3 -n “Shell” ‘duf; bash’
#tmux new-window -t 0:4 -n …

tmux attach -t0
[…]

So, each time I reconnect ssh it pickups up current session or creates new with prepopulated windows ready to go.

;-}
P

2 Likes

Hey @nobillgates

That’s a solid approach! I made a similar switch from screen to tmux a while back and never looked back. The ability to script your session layout like that is hard to beat.

Do you have it wired up to run automatically on SSH login?

I did consider full automation from login but decided against for the sake of flexibility.

I fire up a lot of test VMs for assorted distros and this is one of the scripts I always include in the setup. Always a good start.

:face_with_monocle::+1:t4:

1 Like