r/linuxquestions • u/BareFuzzee • Oct 29 '26
What’s one Linux command you wish someone had explained to you sooner?
[removed]
353
Upvotes
r/linuxquestions • u/BareFuzzee • Oct 29 '26
[removed]
67
u/Fazaman Oct 29 '26 •
sshfs
You can mount a remote machine's filesystem (or parts of it) to yours simply over ssh.
Have two remote machines that can't reach each other for various reasons, but you need to copy something from one to another? Well, you could copy from one to local and then from local to the other, or you could sshfs them both to your machine and then just rsync from one directly to the other. Sure, you're still the middle-man, network-wise, but you don't need that two-step process!
I've known about it for a long time, but never really started using it until a couple years ago.
82
u/jondaley Oct 29 '26
I was going to say "rm -rf /", but when I learned about clusterssh, that was a great day, since I administer lots of systems.
I once had a customer who was trying to learn DOS, so bought a DOS for Dummies book and tried out all the commands alphabetically. I got a call to fix the system after he had run fdisk *and* format. The fdisk command succeeded but it was cached so didn't kill off the system until he ran the format.
I said, "so when it said, 'this command will erase all content on your system, do you want to continue?', you chose 'yes'?" He said, yup, that's what the book said it would do...
49
u/Munalo5 Test Oct 29 '26
Not a command but putting a single space before the command to keep it off the bash history log. Keeps the log from getting clogged with junk.
20
u/WetMogwai Oct 29 '26
I found find to be intimidating for over 25 years. Now I use it constantly. It would have made so many things so much easier if I had bothered to learn it earlier.
19
u/ricperry1 Oct 29 '26
`git`. I know it’s not technically a “Linux command”, but I still struggle to understand what’s what. And I need to use it often.
33
u/Joker-Smurf Oct 29 '26
I have been using fish shell for a few months now, but still learning little shortcuts.
Like Alt+s (which prepends sudo to the current line, or if the line is empty, adds sudo to the previous command just like `sudo !!` In bash)
And `cd -` which is the fish equivalent of `cd ~-`
66
u/Ori_553 Oct 29 '26
Those are all elementary, but they made me like Linux years ago:
history | grep "any substring i can remember from that one-liner i used a week ago"(searches historical commands)Tab key -> autocomplete (folder names, files, binaries, etc)
bb(bonus, if you know, you know)14
u/0dev0100 Oct 29 '26
htop
Tells me what's using which resources
57
u/TomDuhamel Oct 29 '26
manSomeone should really have told you about to this one, so you shouldn't be intimidated by commands you don't know.
13
u/MasterGeekMX Mexican Linux nerd trying to be helpful Oct 29 '26
For me it was something more meta: that commands are in fact programs you have installed, not a set of orders the terminal knows.
12
u/ResponsibilityBig343 Oct 29 '26
Not commands but this one senior taught me how to reverse search using ctrl+r
9
u/neckyo Oct 29 '26
Awk
It took me a couple of years and seeing someone else using it ti start processing logs and command output with 9ne liners
9
u/Schaex Oct 29 '26
I am a very big advocate for
tldr, which is a very useful tool that gives you examples of how to use a specific command. I often use it because I just cannot remember where to put the file/directory name when callinggreporfindfor example.Just enter
tldr grepand it will pull the examples and display them :DOther than that,
sedandxargsare incredibly useful, but not used enough imo :D8
u/bbbourq Oct 29 '26
For me it was the `rsync` command with ssh vs. `scp`:
rsync -avPzhe ssh /path/to/local_dir username@remote_server:/path/to/remote_dir/
8
u/vilari-mickopf Oct 29 '26
`parallel` for spawning multiple processes, `nohup` if you are not using tmux and want to detach processes from current session (allowing procceses to continue to run after for example ssh session is closed). Also `rg` instead of `grep -R`, it's waaaaay faster.
7
u/absnotkinkyreggae Oct 29 '26
i hope i dont start a debate but:
systemctl edit <service name>will open your text editor with the default service file all commented out and you can create your own override file, which then is inserted within /etc/systemd/system/<service name>.d/override.conf
pretty handy.
7
u/frankensteinsKITTEN Oct 29 '26
xargs. It's one of those commands that I just couldn't get my head around until I started proper shell scripting and learnt about the difference between piping to stdin and processing arguments. It's a very simple tool, but often comes in handy.
6
u/MyNameIsRichardCS54 Oct 29 '26
Not a command, but I wish someone had told me about LVM much sooner than I learnt about it. It's not as scary as I thought.
6
u/GimmieTheRoot Oct 29 '26
cat instead of dd
You can properly cat iso files to usb sticks faster than DD can write them. Blew my mind.
5
u/elijuicyjones Oct 29 '26
GREP is what made my work easy back in the 90s when everyone else was using GUI tools that were woefully inadequate.
5
u/pa5hk1n Oct 29 '26
strace. When a program fails with some useless error message, it can show exactly which files it tried to open and what went wrong. Saved me from a lot of guesswork.
strace -f -e trace=%file ./your_program5
u/Soakitincider Oct 29 '26
I like sudo !!
If you do a command and it doesn’t work, you can type sudo !! and it will run the command again but as sudo.
4
u/asrma7 Oct 29 '26
Definitely awk. Filtering, extracting columns, pulling useful information from huge log files, you name it.
4
u/funny_perovskite Oct 29 '26
awk. other than printing a field
4
u/das_menschy Oct 29 '26
CTRL + R to search in your shell history.
3
u/OldAgeGeek62 Oct 29 '26
tldr for any command you can't remember the syntax.
3
u/drivefastgt4 Oct 29 '26
Xargs
3
u/revengeof1987 Oct 29 '26
Ctrl+L
3
u/daaaaave_k Oct 29 '26
tmux
3
u/MouseJiggler Oct 29 '26
A command is never on its own, it is always a part of a system. Don't think in terms of a single command - think how a particular tool fits in a workflow. That is the thing I wish I understood early on.
3
u/doodlehip Oct 29 '26
There are so many things, but one nifty little trick I tend to use a lot is Ctrl+T Which swaps the character under the cursor with the one to the left.
3
u/ATF_OFFlClAL Oct 29 '26
Use "old somefile.xyz" to rename it to "somefile.xyz.old"
3
u/Dr_CLI Oct 30 '26
This may start a heated discussion about editors but I say to take time to learn vi. The reason I say this is because vi is on every Unix based system. Nano may be available on most Linux districts but not all (it may be available but not installed). If you ever have to troubleshooting a system that won't boot and only has vi available you will be glade you took the time.
I'm not going to sugar coat it for you, vi has a very steep learning curve and not at all friendly or forgiving for new users. It is very different from most any other editor you have ever used. Start simple with just the i command. Then learn a, ... Keep adding commands to your knowledge. The more you learn it the more you will not want to use other editors. There are plenty of online tutorials and other reference materials.
2
u/_Lost-In-The-Weeds_ Oct 29 '26
TLDR / TealDeer
Example based "man pages"
2
u/Jan1north Oct 29 '26
vi - baptism by fire!
2
u/zed_patrol Oct 29 '26
sl
2
u/Orlha Oct 29 '26
fzf
2
u/Vk2djt Oct 29 '26
sed. Still yet to deal with that beast.
2
u/john_flutemaker Oct 29 '26
Sed in detail.
2
u/infinitUndo Oct 29 '26
awk
2
u/mglepd Oct 29 '26
tldr for people like me who are too lazy for man. Seriously useful for beginners
2
u/grantrules Oct 29 '26
Screen or tmux
2
u/time-always-passes Oct 29 '26
You can go a really long way with just five:
xargs
find
echo
cut
grep
Learn everything you can about how those can work with piping.
And then add in
ssh
nc
With these last two you can do all sorts of network magic, as well as remote execution.
2
u/mattPez Oct 29 '26
fish
2
u/MartinUK_Mendip Oct 29 '26
Putting a hash in front of any lengthy command line I'm constructing so hitting 'enter' doesn't run it.
Asides from that 'find' and realising you can run another -exec after the first -exec
2
u/other-brother-darryl Nov 03 '26
fc
If you type a massively long command (like a docker run sequence) and realize you made a typo after hitting enter, you don't need to pull it back up and use the arrow keys to slowly go back to fix it.
Just type fc and hit Enter. It opens your previous command in your default text editor. Once you fix the typo, save and exit, the corrected command will execute automatically.
I use it the most when I know I'm going to write a long command. I type fc, erase whatever is in nano and type out my command; this gives me much more space and I can move around more freely as I "craft" my command, then save, exit and off it goes.
spong would be a close second for me. It's basically a smarter replacement for '>' because it "soaks up" all the input entirely before opening the output file.
This: sort data.txt > data.txt will erase data.txt
While this: sort data.txt | sponge data.txt will do what you actually wanted.
2
u/TapEarlyTapOften Oct 29 '26
When people refer to things like this, they're often interpreting "learn Linux" as "learn bash." To thst end I would recommend you read the bash users guide. After that, I would recommend reading the GNU C library reference.
2
u/forestbeasts Oct 29 '26
...are you a bot again, OP?
Again, sorry if not, but... smells fishy.
(Different OP this time though. If you're wondering what I'm on about with the 'again', I just ran across another question that just had... the too-perfect sheen of slop all over it.)
2
u/GruesomeJeans Oct 29 '26
The command of unplug it and plug it back in.. my Logitech keyboard has white LEDs in it and for some reason on occasion when I reboot Zorin my lights are off by default and the keyboard FN buttons don't turn them on. At first I was using a mix of some commands to get them back one when I discovered I can just unplug the USB and plug it back in and they turn back on fine...
1
u/skyfishgoo Oct 29 '26
tee
1
u/OutrageousCrab9224 Oct 29 '26
tee
Cuz i rewrote it, then found it
1
u/Gokudomatic Oct 29 '26
chmod
1
u/schnarfler Oct 29 '26
stow for dotfiles / config files (with a git repo)
1
u/cad_nova Oct 29 '26
That's a good question 'man'
1
u/this_is_life_now Oct 29 '26
sudo !
1
u/jatawis Oct 29 '26
sl
1
u/ctesibius Oct 29 '26
Not as useful as it was, but
telnet. It was very useful for debugging servers with text-based prototols (http, imap, smtp etc.). So you could do something liketelnet 80 example.comand interact with the server as though you were the client, seeing all the responses and error messages.I'm putting that in the past tense as there's not much use of unencrypted servers now and you would use things like openssl and curl these days.
1
u/Steerable-Octopus Oct 29 '26
strace, it's glazed like it's the best thing since sliced bread but I think it's too noisy to be useful.
1
u/rukiann Oct 29 '26
mv
1
u/him4her4ever Oct 29 '26
Alias
1
u/I_am_Pauly Oct 29 '26
Sl
1
u/vinzz73 Oct 29 '26
1
u/ianwilloughby Oct 29 '26
Either watch or 2>&1 | tee fubar. I ran a lot of Apache spark using scala. The Java output is maddeningly voluminous
1
u/das_menschy Oct 29 '26
To search for a file named "somefile.txt": find . -type f -name somefile.txt 2>/dev/null
To search for a file containing the text "sometext": grep -rnw "sometext" . 2>/dev/null
1
u/muffinChicken Oct 29 '26
I have my system setup so I can write Arabic directly into the terminal thus giving me the feeling of aladin
1
u/Few_Research3589 Oct 29 '26
It is -- at least for me -- more a question of the main ideas and commands clustered around each of them:: ssh, rclone, timeshift, borg, cron, vim, rofi, tint2, diff, ffmpeg, etc.; and of course, python has a special place among them
I am not an IT spcialist, I am just ready to put quite a lot of time and effort into saving some time and effort :-) just because I can.
You can (and I did) pursue similar approach in windows, as far as I can remember, but it was much harder and less satisfying than in linux
1
u/VpowerZ Oct 29 '26
fzf
1
u/LokiAstaris Oct 29 '26
jq
The ability to search large JSON objects and strip out the parts I want.
1
u/roywill2 Oct 29 '26
Not a command but connector the pipe | symbol. Just magic "cat file | sort | uniq "
1
u/abyssea Oct 29 '26
Chmod calculations
1
u/vanderaj Oct 29 '26
It’s comm for me. It helps find things that are the same or different in two or three files. I exceptionally handy and stops you writing a quick and dirty script for the same thing.
1
u/zuccster Oct 29 '26
Cowsay
1
u/rndrboi Oct 29 '26
I feel like awk, sed and grep really improved my Linux experience. Not on the daily but every now and then you have to something that I'm grateful I took time to learn those commands well
1
u/Appropriate-Idea5281 Oct 29 '26
Screen
1
u/Pretty-Driver9444 Oct 29 '26
Ik vraag het meestal aan chatGPT of een andere AI. Die hebben het ook wel eens mis maar vaak heb ik er wat aan.
1
u/Jew-zilla Oct 29 '26
All of them. Just started using it a few years ago. Now I have a Kali box as a daily driver, a machine from 2011 with Armbian running Tailscale and Pi-Hole, and a third running Mint. The last one was a fun project. It was a Windows 8 early ultrabook, but the display went weird when the adhesive behind the screen leaked. I put Mint on it and removed the display. I always wanted a Commodore64, now I have my own custom slabtop.
1
u/OkYogurtcloset4980 Oct 29 '26
grep with -B (before) and -A (after). Just gives you the block of lines around its find
1
u/mnlg Oct 29 '26
Not really a programme/command that made me click with linux, just one I was surprised to find: strings. It looks for printable strings within binaries.
1
u/skantrall1433 Oct 29 '26
What made me want to try Linux was tab completion in bash. DOS didn't have it then.
As for commands, egrep / grep -E is something I use daily, also awk is amazing.
But I still don't know how to use tee.
1
u/Jean_Luc_Lesmouches Mint/Cinnamon Oct 30 '26
openopens a file with the associated program as it you double clicked on it. With a URL it opens the web browser.open .opens your gui file manager in the current dir. It works with sudo to open as root.1
u/swstlk Oct 30 '26
e2image and losetup -- I use them for recovery/backups..
1
u/tuxsmouf Oct 30 '26
man -k
1
u/theNbomr Oct 30 '26
Not so much a command as a concept: the concept of standard IO, and the related concept of 'everything is a file'. This gains the best advantage when you understand the basic semantics of file access: open, read, write, seek, close.
With these concepts understood, the whole benefit of IO redirection and the elegance of treating everything as a file, and how it makes many separate small tools work together so easily.
1
u/kj1352 Oct 30 '26
Using tabs for auto complete.
1
u/Only_Candidate_3993 Oct 30 '26
"shutdown"
1
u/h0dgep0dge Oct 30 '26
pv, socat, nmap/nping, tcpdump
1
u/2eanimation Oct 30 '26 edited Oct 30 '26
!!
Expands to the last command you typed.
E.g. if your command needs root permission and you forgot sudo, type in sudo !!
Edit: there’s a whole can to open with the exclamation mark! !n expands to the nth command in history(so !1 would be the first). Works with negative indices, !-2 expands to the second to last command. !pattern if you don’t know the number. !grep expands to the last grep command you typed. !$ expands to the last file-path. Let’s say you used less ./some-path/text.txt and now want to edit it, type vim !$. !*, same spiel for arguments.
1
u/stianhoiland Oct 30 '26
`sh` is air, `sed` is water, `fzy` is honey.
1
u/DadsVacation Oct 30 '26
Piping less into a large terminal output to easily read and search contents
Alias for combining mkdir and cd together
sudo dd if=/path/to/linux.iso of=/dev/sdX bs=4M status=progress conv=fsync
Instead of using image writers to write os images to usbs
1
u/verdigris2014 Oct 30 '26
systemctrl
1
u/Levgils Oct 30 '26
|
1
u/HoodoftheMountain Oct 30 '26
recently `parallel`, instead of inputting a file each time the command is run or running a shell script, just batch it all together if the names are similar enough. Useful for when I have to re-encode a list of things in ffmpeg.
1
u/SigmaxAlpha Oct 30 '26
No se. llegue a Linux ya sabiendo programar, asi que si tengo una tarea repetitiva, simplemente abro mi IDE y escribo un programa que la haga, asi que no toco mucho la terminal mas alla de para usar apt o iniciar los graficos.
1
u/Champboyriley Oct 30 '26
Lots of good suggestions ...
I find locate and updatedb (commands must work in a pair) to be very usefull when looking for files but are not sure where they might be. Locate is like a find command but is almost instant even on fairly large systems.
1
u/VeryPogi Oct 30 '26
sed and awk are important Linux commands because they allow you to automatically search, filter, extract, and manipulate text from files and command output. They are especially useful for system administration, log analysis, configuration management, and shell scripting.
1
u/maartenyh Oct 30 '26
》apt update
Error: no root permissions
》sudo !!
Updating...
1
u/Mister_Magister Oct 30 '26
I'm too deep to think of any at this point but i'd like to understand lsof
also people need to have explained what is dd and why they're using it wrong
1
u/Sad-Cod-9584 Oct 30 '26
lots of good stuff in here already, but I just want to add that vim accepts stdin, so you can do for example sudo dmesg | vim -
1
u/Dr_CLI Oct 30 '26
A lot of good command references here. If you are going to really use the command line then you need to spend time to really learn Bash (or whatever shell you use). Learning the shell will provide a great base for interactive command line use as well as shell script writing.
After you have a good understanding of Linux and are using pipes to write complex command strings, then study up on the
xargscommand. A fairly obscure command with power for dealing with huge amounts of arguments. Can breakup long lists in into workable units.1
u/m1L35dY50N Oct 30 '26
!! in Bash.
Ever typed a long-ass command, hit Enter, and realized you forgot sudo ?
Instead of typing the whole thing again, just use sudo !! and Bash will rerun your previous command with sudo front of it.
Such a tiny feature, but it's saved me an embarrassing amount of typing over the years.
Just don't blindly use it if you're not sure what your last command was.
In that case check with history.
Also pushd and popd were massive eye-openers. Being able to jump between directories and return to where you were without constantly typing out paths is ridiculously convenient.
1
u/Relevant-Educator587 Oct 31 '26
CTRL+R has increased my work speed of 10000%
1
u/Forward-Scar-7050 Oct 31 '26
Q2aa
1
u/frasnian Oct 31 '26
If you have to use
telneta lot for management interfaces,rlwrapis fantastic.1
u/Ok_Enthusiasm8135 Oct 31 '26
Screen or tmux
1
u/neopaf Oct 31 '26
tac (reverse cat)
1
u/neopaf Oct 31 '26
alt+. (add last command last argument here)
esc+. (Ditto)
1
u/FlatusTheRoman Oct 31 '26
Tab
1
u/Unable_Fun_1074 Oct 31 '26
fg, sin duda.
1
u/daninlakewood Oct 31 '26
I was going to say grep and then I thought, I wish someone would explain grep to me now.
1
u/ecce_mono Oct 31 '26
I noticed a lot of 'cut' commands in my predecessor's scripts at an old job. Still one of my go-tos for quick n dirty one-liners. Also second place goes to the combo of sort & uniq
1
u/Whyte_Wolf Oct 31 '26
../../ when using cd
1
u/vphan13_nope Oct 31 '26
cd - to go back to the last PWD, ctrl-r to search previous commands
1
u/tekchip Nov 02 '26
history and !xxx
Lets you see all your prior command and you can re-run a command by typing ! followed by it's number.
As someone else points out you can combine history with grep to narrow down which command you're looking for.
1
u/plugs3501 Nov 02 '26
sudo !! Has saved me more times
1
u/coldbeers Nov 02 '26
!!
1
u/UseTheTerminal Nov 03 '26
poweroff
Alternative to
shutdown, literally just turns off your computer. but not all distros have it.1
u/Dev-in-the-Bm Nov 03 '26
opencode
1
u/LawElectrical2434 23d ago
Well... That you can reap zombies of other processes with waitpid. I learned that today. Also, turns out, it was a redditor full of shit, you cannot do that if they don't belong to your process... But still, something I learned today, just something that wasn't true.
1
u/wehaveYummiTummies 20d ago
Not a command, but the thing that I find myself constantly referencing over the >10 years I've been using linux is the shell parameter expansions page of the bash manual (idk about compatibility with other shells).
${var##something*else}will remove the longest substring matching the patternsomething*elsestarting from the left (see shell pattern matching for info about the patterns). Useful for extensions:var=filename.ext; echo ${var##*.}will returnext.${var#something*else}removes the shortest substring, from the left. IF you havefilename.ext1.ext2and want to getext1.ext2, use this one, becausefilename.is the shortest pattern that matches*..${var%%something*else}will remove the longest substring from the right. So instead of*., you would use.*:var=filename.ext; echo ${var%%.*};would give youfilenameinstead ofext.${var%something*else}matches the shortest pattern from the right.Those are the ones I use the most. There's more that are also helpful, like find/replace, and some that deal with arrays.
1
u/Sahkopi4 15d ago
What is a pipe and how to use grep
1
u/mdins1980 Oct 29 '26
One for me was SSH. I had been using Linux for years before I even knew SSH existed, but once I discovered it, I couldn't imagine living without it. Another was tab completion. For the longest time, I had no idea I could just press Tab to autocomplete commands.
1
u/ReasonableTreeStump Oct 29 '26 edited Oct 29 '26
Sudo lol. Sudo everything. Break sudo? Repair or revert and sudo properly. If it is your personal machine, don’t be afraid to break it and reload.
That brings me to rsync. Not exactly linux but one of the best part about linux
Edit: oh also chmod -x or +x
Edit 2: i just realized that I have been using Linux straight for over a year now, without dualbooting windows. I have a macbook air for travel/work etc. But yeah, it took me a bit to actually understand what was going on.
Before I started using linux full-time, I would use command prompt on windows but only if I was following a guide.
Now I feel a little more confident just trying and seeing what happens, knowing just enough to know I can explain it to some LLM (claude or chatgpt) and they can point out the idiotic thing I did, and I can go DOH and fix it. Also, I feel like I have somewhat of a grasp to know when an LLM is being stupid and giving me a dumb linux or software related answer.
And I don’t work in tech anything. Legal/policy. So, honestly, anyone wondering about linux. It might seem intimidating, but it is not difficult.
I use Ubuntu. it works for me.