r/LinuxTeck • • 18d ago

What's One Linux Command You Use Almost Every Day That Beginners Often Overlook?

Everyone knows ls, cd, grep and top. But there are plenty of lesser-known commands that can save time in everyday Linux work.

Commands like jq, lsof, diff, cut, paste and sort | uniq can be surprisingly useful.

Fellow Linux users, what's that one command or command combination you use regularly and wouldn't want to work without?

Share your favourite one-liners too!

62 Upvotes

119 comments sorted by

12

u/StupidIsIfYouDontAsk 17d ago

sudo !! runs your previous command again with sudo

2

u/Hatta00 17d ago

and !$ repeats the final argument to the previous command

ls [Gg]l*b
rm !$

No worries about retyping a complicated glob.

1

u/zaufi444 14d ago

`Alt+.` in bash gives u the last arg :)

2

u/Dragenby 17d ago

What does each bang mean, individually?

6

u/StupidIsIfYouDontAsk 17d ago

The first ! is to say you want to get a command from history and the second ! says use the last command.

when you run history you will get a numbered list of the commands you ran.

So you can also do !29 which will execute the 29th command in your history

1

u/Dragenby 17d ago

Woah, that's great to know! Thank you!

1

u/studiocrash 16d ago

But will the numbers have shifted by one because history is itself another command?

3

u/DaSchmitzi 16d ago

As far as I found out, history also prints itself (as the most recent command). 

And the commands are numbered ascendingly from most far back to most recent (most far back has number 1) so there isn't any shifting of the command numbers anytime.

1

u/studiocrash 16d ago

I wasn’t very serious about that comment. I’m sure over the decades if it did something inconvenient like that, they would have fixed it. lol.

1

u/Top_Performance_732 13d ago

alias fuck='sudo !!'

11

u/blobCabbage 17d ago

bat which is like cat, but with syntax highlighting.

8

u/radialis99 17d ago

man. The man command lists the manual pages for most linux commands.
apropos. Apropos lets you search the manual pages.

1

u/Top_Performance_732 13d ago

in that vein, tealdear

7

u/bannedfromdevnull 18d ago

alias.

2

u/mrdaihard 16d ago

That and "declare -f" for me since I have just as many functions defined as aliases on my systems.

6

u/sqeeezy 18d ago

I am irrationally tickled by this one for sending my clipboard from this mac to that mac pbpaste | ssh user@thatmac "cat | pbcopy" I know it's basic but so am I

5

u/Lonely-Scarcity-3387 17d ago edited 17d ago

CTRL+R in the terminal to see your command history.

2

u/dcheesi 17d ago

It took me an embarrassingly long time (mostly spent pressing the Up arrow over and over) to discover this one

1

u/Lonely-Scarcity-3387 17d ago

Same! Several months, for me. Also CTRL+L is a nice QoL feature.

1

u/dcheesi 17d ago

...TIL, thanks (and I've only been doing this since the '90s lol)

1

u/CardOk755 17d ago

Emacs. Oddly nobody ever uses "set -o vi".

2

u/mrdaihard 16d ago

I have "set -o vi" in my ~/.bashrc. Am I supposed to replace it with "bind -m vi"?

1

u/CardOk755 16d ago

Ok, ok, only the appropriately named u/mrdaihard has "set -o vi" in his .bashrc

1

u/nv1t 15d ago

even better. mcfly or similar with Ctrl+r. that is command history on steroids. and I like this: <command> #doesthis

you can easily find it in command history :)

1

u/Lonely-Scarcity-3387 15d ago

I had not heard of this before, but yeah this looks cool.

https://github.com/cantino/mcfly

1

u/audunru 11d ago

I’ve used this a couple of times when screensharing and there’s always someone going “wait what?!?”

3

u/Background-Train-104 18d ago

wall "Anyone using this machine now?"

3

u/diegotbn 17d ago

xargs, head, tail, touch, cat, sed

find is incredibly useful, probably the most useful on a daily basis out of any of these here

And of course there's all the basic file and directory operations- cp, mv, mkdir, rm

The obvious sudo and su and of course chmod

Also alias, gzip, tar, lsblk, ipaddress, fdisk and gdisk

I don't use it every day, but dd is beautifully simple and dangerous but if you're careful you don't need any other tool for cloning and wiping drives/partitions

3

u/opensourcedev 14d ago

cal and cal -y

2

u/recursion_is_love 17d ago

ls/find pipe to xargs

1

u/anders_hansson 17d ago

pretty much anything pipe to xargs

I often use git grep --name-only or similar to find relevant files that should get some treatment via xargs (e.g. sed or clang-format).

2

u/tuxsmouf 17d ago

It's not a builtin command : fping -qa -g xxx.xxx.xxx.xxx/xx

1

u/MrWoland74 17d ago

i learned about fping recently and it so good! Excellent for scripts

2

u/leobult 17d ago

Learn to use the bash shell quickly with keyboard shortcuts like alt w and alt f Dont learn ctrw w, sometimes the shell is in a browsertab....

2

u/Sad_Listen6607 17d ago

not so much a command I use every day... but what I put in my rc file...

aliases.

alias whereami='pwd'
alias dir='ls -la'
alias c='ssh'
alias p='ping'
alias reloadz='exec bash'
alias readz='cat .bashrc'
alias configz='nano ~/.bashrc'
alias tr='traceroute'
alias p8='ping 8.8.8.8'
alias p254='ping 192.168.1.254'
alias addssh='nano ~/.ssh/config'
alias addhost='sudo nano /etc/hosts'
alias smtr='sudo mtr'
alias home='cd ~'
alias q='cd ..'
alias mk='mkdir'
alias edit='pico'
alias serial='screen /dev/tty.usbserial-140'
alias fixterm='echo -e \\033c'
alias argo='scrcpy --new-display=1920x1080/160'
alias argom='scrcpy --new-display=1920x1080/160 -M'
alias z='ssh -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa -o KexAlgorithms=+diffie-hellman-group14-sha1 '

Along with alias's to all the devices I ssh to.

7

u/CourageousCreature 17d ago

neat list, but whereami hurts. Why make a longer alias to a short command?

3

u/Empty__Jay 17d ago

the only thing going for it is that it matches 'whoami'. Now we need a command 'whyamihere'.

2

u/Sad_Listen6607 17d ago

carry over when I was a noob... for some reason my brain malfunctions when I need to remember that command. If someone asks me how to see where they are? I can give the correct answer... randomly when I need to see where I am? I fricken forget!

The mind is a terrible thing.

2

u/DubiousLogik 17d ago

ha. for me pwd is my old abbrev for password. bzzznt. wires cross. short circuit. least intuitive cmd for me

2

u/hacksawsa 16d ago

Two faves: ll='ls -l', ltr='ls -ltr' #later!

I use pushd, dies, and popd a lot.

1

u/magicmulder 17d ago

Is “exec bash” better than “source ~/.bashrc”?

3

u/DubiousLogik 17d ago

exec bash has no special chars to type. i love that. typing ~/. is a pia to me

1

u/Sad_Listen6607 17d ago

neither is better, per se.

Source, i think, keeps some things, where exec does not. I cant recall the last time that mattered to me... and I am sure it was academic or minor.

2

u/R2-Scotia 16d ago

source pulls commands into the current shell, exec replaces it with a new process

1

u/SpudgunDaveHedgehog 17d ago

“alias home” is useless. Just do “cd”.

1

u/MysteriousPause82 17d ago

I find it amusing you have alias whereami to pwd.

Isn’t pwd much faster to type in?

1

u/Sad_Listen6607 16d ago

"A mind is a terrible ting."

1

u/tedecristal 16d ago

why "c" for ssh?

1

u/Sad_Listen6607 15d ago

c for connect, which i think originated with something on a vax I used back in 1996.

1

u/Odd-Change9844 15d ago

Yup .. love aliase

2

u/Only-Stable3973 17d ago

Probably when using cd then using the back command...etc. cd .., cd -, and cd ~

2

u/Fun_Tune5669 17d ago

df -h is something I use occasionally that is kind of useful. I have bunch of other written down somewhere but this one comes to my mind. Also htop is much nicer than regular top...

1

u/MrWoland74 17d ago

wl-copy

1

u/leobult 17d ago

Curl ip.me

1

u/ftranschel 17d ago

emerge 🫠

1

u/Pitiful_Noise_1127 17d ago

History

1

u/MisterJasonMan 16d ago

This but I usually define an alias called "ghist" which is

alias ghist='history | grep -i'

and you can do a search in your command history like for example

$ ghist jpg

will give you every command you ran containing the term "jpg"

1

u/williamt31 17d ago

I have a couple cd aliases but I use pushd to get there that way I can popd back to where I was.

I created this function to find the size of all dirs from a point, I got tired of typing it all out.

duh ()
{
  if [[ -z $1 ]]; then
    du -h --max-depth=1 "$PWD" | sort -k2;
  else
    du -h --max-depth=1 "$1" | sort -k2;
  fi
}

lately practicing my commands so I've been running 'man whatever | grep -a3 switch' because I get tired of going into and out of man and just want a quick reminder of the switch I need.

1

u/Sigfrodi 17d ago

Pushd and popd

Awk

1

u/lyidaValkris 17d ago

cat - though really well known, beginners might open everything in nano or a GUI text editor instead of a simple output in the terminal. cat can also be used to quickly create and paste text into a file in one step. bat is even better, allowing a more formatted output for ease of reading.

1

u/Optimal-Savings-4505 17d ago

Multiplexing your terminal with r/tmux and similar solutions. It offers a subset of emacs functionality that is very useful for daily tasks. There are many other solutions, so this is a conceptual thing, really.

1

u/hexdump74 17d ago

sed

Allows to replace portions of strings (and a lot more) : 

  $ echo "aaa:6" ‌| sed -r  's/(a+):([0-9])/\2 > \1/' 

  6 > aaa

1

u/FLMKane 17d ago

sudo sv restart sddm

1

u/CardOk755 17d ago

Strace (and more rarely ltrace) to find out what a program is really doing, rather than what you think it's doing.

"sort | uniq -c | sort -n" is a great one.

1

u/ahusby 17d ago

topgrade: One command to upgrade everything.

1

u/Dev-in-the-Bm 17d ago

opencode

Alias is oc

1

u/camachorod 17d ago

realpath, pwd, du -sh

1

u/SoggyWalrus7893 17d ago

!su or anything "!" when a bit of up arrow on the mouse doesn't find it

cal

1

u/knuthf 17d ago

Whois TLD

1

u/Corn_Flake_76 17d ago

whoami - especially after a night of hard drinking.

1

u/n3vim 17d ago

"fuck" but it does not come preinstalled

1

u/lwj15 17d ago

I work with input files for some calculation jobs. Currently I need to edit 10-30 files at the same time to optimize multiple jobs. For that I use a combination of sed and find. 

sed -i s/"string currently in file"/"string I want to replace it with"/ $(find -name *of.inp)

It works with multiple lines. Just include the \n. And if one of the strings uses / or () then you put the whose s/.../.../ in ' ' qutation marks and change to |.

sed -i 's|example/text|replacement(new)|' ...

I don't see much use of this command other than the stuff I use it for. But if you have other uses. Tell me. I am interested.

1

u/BarkingSpider5 16d ago

ncdu
In this day of vibe coding, and agents leaving build artefacts everywhere, this command is awesome to find out where stuff is.

1

u/-CloudCook- 16d ago

Usually, I log on server because some service doesn't work, so one of first commands I hit is: netstat - tulpn | grep LISTEN

1

u/aviftw 16d ago

Screen -S session_name, screen -r -d session_name

1

u/Leolo_ 16d ago

Two things to make you powerful on the CLI: mastering xargs and redirection to multiple pipes.

1

u/michaelpaoli 16d ago

sed

Most never take sed beyond, e.g.:

$ sed s/foo/bar/

It's a Turing complete programming language.

E.g. I even implemented Tic-Tac-Toe in sed.

2

u/nv1t 15d ago

same goes for awk :)

1

u/michaelpaoli 15d ago

True, ... but also fair bit more challenging to write such a program in sed. awk, though specialized, is significantly closer to a general purpose programming language than sed. E.g. awk has general purpose variable, flow control, arithmetic, lots of test conditions, etc. sed, for flow control has relatively little. There's an unconditional branch, and a quite limited conditional branch, and some limited manipulation of pattern and hold space, and can read/append next input line. Though with embedded newlines, the pattern and hold space can be manipulated like a pair of stacks. Anyway, wrote that tick-tack-toe program in sed - as I figured that'd be far more challenging. :-)

1

u/wkavinsky 16d ago

ps -aux | grep xxx
kill 1232141

1

u/PossibilityOrganic 16d ago

watch -n "whatever" run it over and over and show it
jq if you have to do anything in bash with json

1

u/CorporateDirtbag 15d ago

claude --dangerously-skip-permissions

1

u/HowCanIChangeMyName1 15d ago

What do you need "sort | uniq" for that "sort -u" doesn't do?

1

u/clawsoon 15d ago

awk for anything structured like a log file, config file, or simple CSV. It's too flexible to give a single one-liner, but I'll make some things up and hopefully you'll get the idea:

awk '$1 == "Oct" && $2 == "25" {print $5}' /var/log/messages

Or for a CSV, set the field separator to a comma:

awk -F, '$3 == "Sell" {x=x+$4} END {print x}' transactions.csv

Let's extract the "default" section from an inf-style config file:

awk '/^\[/ {defaultsection=0} /^\[defaults\]/ {defaultsection=1} defaultsection==1 {print $0}' /etc/mke2fs.conf

It's a full-fledged programming language which was a big inspiration for Perl, Python, and Javascript, so you can do a lot more with it than what I'm doing here. The biggest thing it lacks compared to those languages is locally-scoped variables, which is why it's mostly best for one-liners.

1

u/Wisdom_Wizard_Waldo 15d ago

I don't?...

If i'm using a command every day, chances are i'll just stick it in a daemon so it does it automatically

1

u/ofnuts 15d ago

Perl rename (which is plain rename in my distro).

And outside of the command line, kdiff3 and filelight are very useful.

1

u/natnit555 15d ago

1.Practical way to share file/directory with peers (not secure)

python -m http.server

Then your peer can access the files/dirs from http://<ip addr>:8000

2. Saves your output to file for later inspection while at the same time you can watch it as well.

<arbitrary commands> | tee output.log

3. Script/record/document your steps/work - not one liner actually

screen

https://devhints.io/screen

1

u/ivovis 14d ago

I don't no if I'd call it overlooked, but I use journalctl -r to see how long I slept.

1

u/ChillingChasuble 14d ago

lsusb to show USB devices that are connected to

1

u/Bamseg 14d ago

My most used command is "just" (a command runner - https://github.com/casey/just ) it deeply integrated in my nixos workflow -> herdr, fishshell, starship

It save to me tons of time and nervous.

1

u/SewNgP2206 14d ago

alias k=kubectl

1

u/Bamseg 14d ago edited 14d ago

My most used command is just. It allow create justfile (per project or global) with complex recipe's and run these recipes as >just recipe_name There is snip-off my nixos maintenance justfile:

~/.../homelab/.justfile

host := "homelab"

default:
  @just --list

update:
  nix flake update

# Try configuration
try:
  nh os test .#{{host}}

# Switch to new configuration
switch:
  nh os switch .#{{host}}

clean:
  nh clean all --keep 3

# Optimize/deduplicate the Nix store
optimize:
  sudo nix store optimise

Then i run in my config folder root where .justfile is: $> just update and it call my update recipe to update my flake inputs. Then $> just switch and my new system generation become active. The recipe can be bash or wherever you want (python, etc.. use shebang in recipe)

1

u/solslost 13d ago

History

1

u/modsiw_agnarr 13d ago edited 13d ago

sponge

Almost every use is due to a bad habit / anti-pattern, but old habits die hard.

1

u/jimirs 12d ago

CTRL+E to go the end of the terminal "strings"; CTRL+A beginning; CTRL+D deletes word backward; ALT+D deletes the word forward;

history | grep "something"

find . -type f -name "something*" (-type d for dirs)

nc -zv 192.168.1.X 22 (check connectivity with some host, specific port)

ss -tulpn (check ports listening to something)

cat > file.txt <<'EOF'

write stuff here, or paste

EOF

2

u/tzopper 12d ago

`ag` > `grep`.

1

u/Fantastic-Mister_Fox 12d ago

find . -type f -iname as well if you don't remember casing

1

u/AlmosNotquite 11d ago

'grep' is the answer to everything. It is like the 42 of Linux.

1

u/StrawberryFederal709 11d ago

shutdown -h now

1

u/Due-Celebration-5435 11d ago

sudo apt update

1

u/jmakov 11d ago

byobu restore tiles

1

u/roywill2 11d ago

pushd so you can flip between directories

1

u/randygeneric 16d ago

history | grep -i <> | grep -iv <>
ps
killall

, )

1

u/[deleted] 14d ago

[removed] — view removed comment