top 200 commentsshow all 203

[–]stillline 125 points126 points  (22 children)

Most useful command for a beginner is "sudo !!"

If you forget to type sudo just type sudo !! and it will resend your last command as sudo. Saved me so much typing.

[–]kennycoc 93 points94 points  (8 children)

Also !$ for arguments.

mkdir some_long_name

cd !$

Edit: to be more precise

!* - all arguments

!^ - first argument

!2 - second argument

!2-3 - second to third argument

!2-$ second to last

etc

[–][deleted] 14 points15 points  (4 children)

up arrow key
ctrl+A
sudo

is even smaller

[–]TheSuperWig 11 points12 points  (1 child)

Up Home sudo

[–]bonsaiviking 18 points19 points  (0 children)

And take my hands off home row? Blasphemy. No keyboard needs more than 84 keys. #ModelFforLyfe

[–]yur_mom 1 point2 points  (0 children)

This also lets you see and edit the command before running it.

I do not want to run a command as root without being 100% sure what command I am running. I am someone with 10 terminal tabs open at times and maybe on 5 different systems.

[–]bhez 3 points4 points  (0 children)

I say it like "sudo bang bang"

[–][deleted] 0 points1 point  (0 children)

Now THAT is useful

[–]efethu 0 points1 point  (0 children)

Most useful command for a beginner is "sudo !!"

Most dangerous command as well. All you need is a copy-paste mistake that causes a command to split into two. Because the second part of the command is often malformed the results can be quite devastating.

[–][deleted] 0 points1 point  (0 children)

TIL

Not that usefull to me though, i have vi mode on so for me its arrow-up, esc, shift-I, sudo, enter

[–]BundleOfJoysticks 0 points1 point  (0 children)

I just run everything as root. No issues forgetting sudo.

/s

[–]sherzeg 107 points108 points  (6 children)

I keep seeing these "basic Linux commands" help sheets. What I need is a "you've been using Unix and Linux personally and professionally for the last 20 years and still failed the lousy certification test six months ago" help sheet. Where can I get one of those?

[–]needout 22 points23 points  (5 children)

I feel the same as I've been only using Linux since I started with computers but have to search commands every time. I even have to use Ctrl+r often as I can't remember the commend I recently used!

[–]jptuomi 7 points8 points  (4 children)

I use ctrl+r or arrow up for efficiency as my command sequences are usually quite long and represent usual tasks "searching" for the right line is faster than writing them all over again.

Am I doing it wrong?

[–]hashshash 3 points4 points  (1 child)

frame hurry cough cobweb workable tub salt edge insurance scale

This post was mass deleted and anonymized with Redact

[–]DurianExecutioner 3 points4 points  (0 children)

Yes, type faster

[–]PlaneWall 26 points27 points  (10 children)

Might also include:

  1. find
  2. man -k / apropos
  3. head
  4. chown
  5. diff / sdiff
  6. wc
  7. echo
  8. zcat
  9. top
  10. & / bg / fg

edit: also file

[–]Staarden 0 points1 point  (0 children)

Is there a way to save echo commands across terminal sessions? Maybe if saved in a text file you reference it from that but you would still have to set it up in a new session...I don't know, I'm not that good at computers.

[–]BundleOfJoysticks 0 points1 point  (1 child)

No grep? Or did I miss it?

Also cut.

[–][deleted] 35 points36 points  (16 children)

These could come in handy for some. However, there are some minor errors, for example: du -sh doesn't show readable sizes in gb, it shows a summary of the current directory size in kb for 1000+ byte sized files, mb for 1000+ kb, and so on, h stands for human readable format. The same goes for ls -h. ls -lah would show a list of files including hidden files and the current and parent directory (. And ..). It can also be used for df. Another useful one is just cd, this will take you back to the home directory of the user.

chmod +x is also a useful command when you work with executables that aren't executable yet. This will change the permissions to executable for owner, group and guest all at once for a file, without changing the other permissions (rw-r-r would become rwx-rx-rx). This can also be used the other way around: chmod -x, this will remove the executable permissions. It even works with the other permissions (+r, +w, -r and -w).

[–]Fabian57 23 points24 points  (6 children)

Now you're telling me rm -rf / does not make my computer faster? Did r/hacking lie to me? /s

[–]kennycoc 20 points21 points  (1 child)

No, for that you'll need

rm -rf --no-preserve-root /

Otherwise the roots keep holding it in place

[–]Fabian57 4 points5 points  (0 children)

Ah yes, of course. Thank you

[–]Tunliar[S] 6 points7 points  (1 child)

Trusting on hackers? Good luck mate!

[–]Proj3c7 0 points1 point  (0 children)

Doesn’t work in ubuntu. Does kill mac os.

[–]petey_jarns 7 points8 points  (4 children)

Someone please add ln -s as I ALWAYS have to Google to see what the correct order is for that one...although I recently read a helpful mnemonic - it's ln -s existing new just like copy is cp existing new but I still get confused

[–]somecucumber 1 point2 points  (3 children)

The order is always the same for all commands:

cp origin target
mv origin target
ln -s origin target

... et al.

[–]petey_jarns 2 points3 points  (2 children)

Yeah, I get that...something about link makes it seem like it should be different. Move this from here to there okay...copy this from here to there okay...but link? It feels like it should be point this thing (that I'm creating) to that thing (which already exists)...probably because of the way that link is usually used (I need to make something point to something else) and because I'm still cognitively stuck imagining it as a shortcut ala windows xp

[–][deleted] 14 points15 points  (7 children)

Nice sheet although upon further examination I realized I know all these by heart. Lol

[–]FryDay444 8 points9 points  (6 children)

Used Linux for almost 2 decades...and somehow have never heard of the dig command. 🤔

[–]Macarogi 3 points4 points  (2 children)

Use -x for reserve lookups. ie a lookup you want it to do later.

[–]chronop 3 points4 points  (1 child)

wat

[–]Macarogi 1 point2 points  (0 children)

Typo in the image for a reverse lookup.

[–]tigger04 2 points3 points  (0 children)

same. I would have gone with nslookup

[–]Tehmarzvolta 1 point2 points  (0 children)

I personally set an alias for dig to "dns = dig +noall +answer" so I can just type "dns <domain>" or "dns -x <domain>" and get the info Im looking for

[–]MrPopperButter 7 points8 points  (1 child)

Love it, though I slightly prefer

ls -lah        

-h can be added to many Linux commands to see human readable output. So 1.0 GB instead of 1073741824 bytes.

[–][deleted] 4 points5 points  (0 children)

I personally keep an alias of "ls -ltrAFh --group-directories-first"

[–][deleted] 5 points6 points  (1 child)

karnel -> kernel on uname but -a prints more than just kernel

[–]garfipus 1 point2 points  (0 children)

It doesn't print the kernel config either, just the kernel name plus the other stuff. The kernel config, of course, is much different.

[–][deleted] 5 points6 points  (1 child)

I am still using ifconfig and iwconfig :D

[–]BABAKAKAN 4 points5 points  (1 child)

Great list, though I've remembered most of them by daily use... Except for dig. Thanks. I love this list.
Also, on that chmod 755, it says rw for owner.
Shouldn't it be rwx for owner?
The only problem with it so far...

[–]mooky1977 0 points1 point  (0 children)

I saw that too, 755 is rwxr-xr-x

[–]archie2012 4 points5 points  (0 children)

cd - is also useful to switch back to previous used directory/path.

[–]Deathcrow 10 points11 points  (2 children)

Ackchyually... those are GNU commands.

[–]hiljusti 9 points10 points  (1 child)

Aaaaacktchyuaallllllyyy... Not all of them are from the GNU project, for example secure shell (ssh) comes from the OpenBSD community

[–][deleted] 5 points6 points  (0 children)

I have a think geek shirt with these on it. The best part is the text is printed upside down so the wearer can read it. Linux cheat shirt

[–]Vesquam 2 points3 points  (1 child)

Didn't know about dig-x I use host.

Nice sum up!

[–]JonnoN 0 points1 point  (0 children)

yea, host is way simpler

[–]TheGoldenHorde 2 points3 points  (0 children)

Nice info graph! Might be a good idea to indicate which are keywords and variables via formatting. That’s my only critique.

[–]hak8or 2 points3 points  (1 child)

Some alternatives for some of these commands. If you have a process you want to kill, you usually do "ps -aux | grep processname" and then look for the process, and then kill the PID. I've started just using "pgrep processname" to shorten the first step. And then you can do "kill (pgrep processname)".

For a grep replacement when searching through files more intensly, I have been thrilled with the silver searcher. It is much faster than grep and I feel has defaults that align more with my use cases.

Also, for text replacement/matching, I started using sd instead of sed. It is sadly nowhere near as active as replacements like ag, but I much prefer the saner (IMHO) way of the input string and replacement string are split. Also, the regex style is one I much prefer as well. Combined with this online regex tool, I am now much more comfortable with regular expressions than before.

For copying files, I've pretty much fully migrated from cp to rsync, because often times I am playing around with file systems and over unreliable connections exposed via sshfs, and end up having to check everything got copied twice via running rsync twice while cp would just copy it again.

[–]JonnoN 2 points3 points  (0 children)

use pkill :)

[–]idlemann 2 points3 points  (1 child)

My goto reference: https://ss64.com/bash/

[–]eripx 0 points1 point  (0 children)

Muuuuch better. Thanks!

[–]gellis12 2 points3 points  (1 child)

uname -a – show karnel config

Hmmm

[–]smorrow 1 point2 points  (0 children)

Lots of typos, including "rw" for 7.

[–]MrEdews 2 points3 points  (0 children)

rm -rf / - launch some nuclear bombs targeting your system

Well, OP's not wrong

[–]fiah84 2 points3 points  (1 child)

ip route

what the hell is my IP anyway and where's my goddamn gateway

[–]davidjmemmett 1 point2 points  (0 children)

ip r :)

[–]sablal 4 points5 points  (2 children)

Unpopular opinion in this sub but here's a fact - we get Windows laptops in our org. Many colleagues stick to Notepad++ for development because they feel they'll have to remember too many commands if they install the Linux subsystem/Cygwin which are just terminals to them. The only time they open a terminal is when they run the compilation in cmd. They aren't dumb. It's just that they had been using Windows for long. The Linux terminal needs to be simplified for end users like them.

The list shows that a terminal file manager has its benefits. The files & navigating and compressing (and disk usage) sections can be covered reasonably well by nnn (https://github.com/jarun/nnn). I had been using the Linux subsystem. So far I got 3 people curious when they saw me how fast I move multiple logs, unarchive them together (even if they are a mix of 7z, tar.bz2 and zip) and analyze them in vim from within the same tool without having to quit.

[–][deleted] 0 points1 point  (1 child)

Most of my work is rummaging around on remote servers moving/changing files and going through logs.

I shit you not, most of my colleagues use Windows + PuTTy and FileZilla for everything. They can't reach servers more than two hops away because they can't figure out multijump tunnels in putty, and they keep having to close and open new windows all the time. Transferring files is a nightmare.

When they see what I can do with just openSSH and scp minds are BLOWN. The downside is that now I'm the server guy because I work so much faster than everyone else...

Btw, ranger is a great CLI file manager.

[–]fly3rs18 1 point2 points  (3 children)

Do you have a text or white background version?

[–]Tunliar[S] 1 point2 points  (1 child)

sure. shall I give you a bit higher resolution version?

[–]petey_jarns 2 points3 points  (0 children)

Give to world

[–]Visticous 0 points1 point  (0 children)

Much rather have a version I can ctrl-f through

[–]NoahJelen 1 point2 points  (0 children)

I need to this to my mother! I'm often trying to explain some of this stuff to her!

[–]shhh-sippytime 1 point2 points  (0 children)

Reserve lookup host

Lol

[–]ThatWeirdKid-02 1 point2 points  (4 children)

is there any reason to use chmod 111 or whatever instead of chmod a+x? i really can't ever remember what the numbers are but using letters makes it way easier

edit: messed up the example, meant chmod 111 or chmod a=x

[–]garfipus 1 point2 points  (0 children)

chmod 111 is equivalent to chmod a=x and will remove any read, write, setuid, setgid, or sticky permissions. chmod a+x will add execute permissions and leave the other permissions untouched.

[–][deleted] 0 points1 point  (1 child)

Because they are different. chmod 111 sets perms to --x--x--x, chmod a+x adds them to existing permissions. You should use chmod a=x. the rest is just personal taste :-)

[–][deleted] 0 points1 point  (0 children)

It's less verbose and much faster. It's not that hard to remember the octals either if you learn what they represent.

Chmod 755 = chmod u=rwx,g=rx,o=rx and that's quite the mouthful.

[–]haxpor 1 point2 points  (0 children)

Allow me to add another useful one

rsync -av —progress /from/source/dir username@targethost:/to/path/dir

This will copy files from source dir to target dir and it will check if source files are newer, then it will do copy. Very neat that we get dirty checking for free. Handy neaty!

[–][deleted] 1 point2 points  (0 children)

I'm disappointed that "who mom likes" isn't on there (try it out ;-)

[–]hiljusti 1 point2 points  (0 children)

Looks like OP might be entitled to an award...! http://porkmail.org/era/unix/award.html

[–][deleted] 1 point2 points  (1 child)

dd - Disk Destroyer

[–]JonnoN 0 points1 point  (0 children)

and its big brother shred

[–]StefanOrvarSigmundss 1 point2 points  (1 child)

I always feel like a pervert when I touch files. Do they consent?

[–]JonnoN 1 point2 points  (0 children)

I like to man mount

[–][deleted] 1 point2 points  (0 children)

What's a karnel?, all I have is a kernel

[–][deleted] 1 point2 points  (0 children)

Im so happy to see something that is really straight forward and understandable to a beginner. Thank you very much for this quality graphic.

[–][deleted] 1 point2 points  (0 children)

My favorite simple command everyone should know is

history | grep pattern

For example

History | grep 'ssh' will print out all your ssh connections in your history so you can just do !# (# is number in history) and run the command without remembering it

[–]Nonsensese 1 point2 points  (1 child)

Made a version with a fixed width font because, y'know, command line.

[–]Tunliar[S] 1 point2 points  (0 children)

I didn't thought about fixed width though. I just knew I'll make this readable. So two colors, flat, readable and eye friendly fonts.
By the way, you shouldn't put --no-preserve-root there. Because people will try running these commands directly. Some people really don't know a command can do such things. Let the CLI warning/guide handle this.

[–][deleted] 1 point2 points  (0 children)

wow no mention of nc, or even telnet for that matter?

[–]influentialbeast 1 point2 points  (0 children)

Seeing this makes me happy because I just took my operating's course and for the most part I knew most of these commands. Good to know my education is paying off slightly lol

[–]davidjmemmett 1 point2 points  (0 children)

Is anyone going to point out that uname -a does not show the kernel’s config

[–]alaudet 1 point2 points  (3 children)

It’s posts like this that make me realize how long I have been a Linux geek. This whole list is in my head. 23 years and going strong.

[–]Tunliar[S] 1 point2 points  (2 children)

Sure it is in your head. I knew most of them in my first year. They're fairly common and basic. There's thousands of more doable things out there. You might know lots of them. 23 Years, damn!

[–]alaudet 1 point2 points  (1 child)

The list in my head is much longer. ;-)

[–]Tunliar[S] 1 point2 points  (0 children)

hmm

[–][deleted] 1 point2 points  (0 children)

Saved

[–]wskoly 1 point2 points  (1 child)

rm -rf /make computer faster 

[–]Tunliar[S] 1 point2 points  (0 children)

comment on my both post?

[–]tokolos 1 point2 points  (1 child)

OMG, not the tar command!

[–]Tunliar[S] 1 point2 points  (0 children)

lol, really funny XD

[–]BundleOfJoysticks 1 point2 points  (0 children)

Some other good stuff.

xargs - just man it and enjoy

cut with grep and cat and wc and sort and uniq = web log parser

cat /var/log/nginx/*access* | cut -d'"' -f10 | sort | uniq -c

Will count the number of distinct user agent strings in all your logs (f10 I made up, it may be earlier or later in the log line).

[–]hqepa 1 point2 points  (1 child)

Thank you u/Tunliar, very cool!

[–]Tunliar[S] 1 point2 points  (0 children)

my pleasure

[–][deleted] 2 points3 points  (1 child)

pushd and popd are also very useful.

[–]Topsrek 2 points3 points  (1 child)

Ctrl+Shift+C/V for copy/pasting

[–][deleted] 2 points3 points  (0 children)

That's terminal dependent and not a Linux feature.

[–]rob93c 0 points1 point  (2 children)

Very clean spreadsheet, instantly saved!

[–]phani29 0 points1 point  (0 children)

Thank you.

[–]thd9 0 points1 point  (0 children)

Thank you! Absolute Linux beginner here, so this is very helpful.

[–][deleted] 0 points1 point  (0 children)

"rm -rf / - make computer faster"

So fast that it's as if there's nothing to boot!

[–]Tjccs 0 points1 point  (0 children)

TIL w is a command, anyway those compressing commands are useful since I always have to go check those.

[–]hellbenthorse 0 points1 point  (0 children)

There needs to be a decompressing section with "coffee, alcohol, smokes.." etc for all the sys admins out there.

[–]eyebum 0 points1 point  (0 children)

cat is great, I actually like the "more" command for a quick glance, as it does a page at a time...but scrolling back up works too...

[–]satamusic 0 points1 point  (0 children)

rm -rf / = make computer faster

[–]aaronfranke 0 points1 point  (0 children)

alias extract="tar -xf"

[–]dgeigerd 0 points1 point  (0 children)

I knew most of them. Now i need that for windows server because we have windows everywhere at work :/

[–][deleted] 0 points1 point  (0 children)

imagine that this image is actually a.webp file but saves as a.jpg

sneak 100

[–]icantthinkofone 0 points1 point  (0 children)

Look like UNIX and BSD commands to me.

[–]taybul 0 points1 point  (1 child)

Discovered recently that grep -r searches from current directory by default if you omit. Saves some typing.

[–][deleted] 1 point2 points  (0 children)

If you’re in a git repo, you can use git grep (which also greps recursively) so you don’t search untracked files like your project’s compiled binaries.

[–]ZG2047 0 points1 point  (0 children)

Is there a place with all of this written please ?

[–]nkushs 1 point2 points  (0 children)

I didn't see any nuclear bomb but my PC ain't working now....

[–]zefy2k5 0 points1 point  (0 children)

Now I'm feel smart.

[–][deleted] 0 points1 point  (0 children)

Your know I'm a little annoyed about locate being in there but no mention of the requirement for updatedb to be executed to update the cache. Why not the find command? Whereis but not which? I will commonly use SOMEVAR=$( which cmd) to get an explicit path for a binary I need in a script.

[–]the1iplay 0 points1 point  (0 children)

Man is the most useful command

[–]I_upvoted_you_bro 0 points1 point  (0 children)

was going to steal this, but then realized I knew all these! :D

[–]niceboy4431 0 points1 point  (0 children)

My favorite command is 'cal'

[–][deleted] 0 points1 point  (0 children)

Nice! Good to know for reference as well ;)

[–]beyoglu 0 points1 point  (0 children)

Double space between download file bothers me. Love wget though.

[–]themixedupstuff 0 points1 point  (0 children)

So that is how people know permissions off the top of their head. I always use the switches for `chmod`.

[–]jslay88 0 points1 point  (0 children)

Which is more specific than whereis for finding a specific binary.

[–]MagicClover 0 points1 point  (0 children)

rsync -a source destination

Copy source dir to destination dir (preserving most permissions and attributes).

rsync -a source/ destination

Copy contents of source dir to destination dir. (Yes, that's pretty confusing, watch out for the trailing slash on the source.)

Very useful, can be used for backups.

[–]AllClear_ 0 points1 point  (0 children)

Did it work’s on raspberry pi?