DEV Community

Cover image for Linux Commands Cheat Sheet

Linux Commands Cheat Sheet

Serverspace.us on December 13, 2023

It happens that some Linux terminal commands are hard to recall, and keeping them on your computer or paper as a cheat sheet is a good practice. Th...
Collapse
 
joolsmcfly profile image
Julien Dephix • Edited

Hi.

A had a quick glance at the list I have the following suggestions for you:

Id – Detailed information about a user (uid, gid, and group).

It should be id.

cd - Navigate to the home directory (using the $HOME variable).

You probably meant cd ~.

ls -al – Displays files and directories in the current folder.

Add h to have human readable sizes! (ls -lah)

There's a command I find myself using from time to time:
du --max-depth=1 -h which lists sizes of files and folders with, you guessed it, max depth of 1. Useful when you want to find out which folder takes most disk space.

Collapse
 
danlee1996 profile image
Daniel Lee

the cd command without any arguments work exactly like cd ~.

Collapse
 
joolsmcfly profile image
Julien Dephix

TIL. Thanks!

cd - is also very helpful to go back and forth between two folders.

Collapse
 
olexy profile image
Scarlet Olexy

Didn't know that, thanks

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

I don't understand why people still use chmod like that. It's fine if you want to put it in a script, or even in a manual type thing. But for everyday stuff, it's just way easier to do for example chmod o+rx.

Collapse
 
teamradhq profile image
teamradhq

Because 3 octals are easier to understand.

chmod 777 is equal to `ugo+rwx

chmod 750 is equal to chmod u+rwx,g+rx,o-rwx

One of them seems much simpler to me…

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

When you want to set the exact permissions of a file, maybe, but most of the time people just want to do "let me execute this" or don't let others even read this", and you just cannot tell me that the average user finds it easier to just assemble the exact numeric code of the current permissions with that change applied on the fly as they type the command.

Thread Thread
 
teamradhq profile image
teamradhq • Edited

Each to their own I suppose.

I don’t think you can quantify that most of the time ppl just want to execute something they do so in a way that adheres to your personal preferences.

Personally, if I want to let others read something, I’ll chmod 640 or 644 for that. For me, three octals are much easier to type and remember than the dozens of characters required to achieve the same result.

Also, it’s not a numeric code. It’s a set of 3 octals that assign rwx permissions to owner, group and all. An octal is not a number, it’s a set of three bits 7 = 111, 6 = 110, 5 = 101, etc. The digit just represents the order of bits.

This is just base 2, which is pretty fundamental to computing. It’s really not hard to count from 0 to 7 in binary. My seven year old figured it out in about five minutes, so I’d suggest the average terminal user could do the same. Certainly much quicker than determining the exact collection and combination of letters and symbols required to provide 754 permissions.

Perhaps you should do some reading on the topic to shore up the clear gaps in your understanding. :)

Thread Thread
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

I don't see where that condescending conclusion comes from, but I think you're conflating what is a good way of teaching chmod and how you and everyone else should be using it.

I'm in your exact shoes with colours in hexadecimal; They're easiest to type if you've spent way too much time using them and can just write and interpret them as any other notation, but I would never put it as the default in any tutorial.

Most users of a tool won't be using it often enough to memorise these things, and a more mnemonic notation like g+w to say "add write to group" will be quicker to learn and easier to remember when you need it.

This post was supposed to be a cheat-sheet, after all.

Collapse
 
kaamkiya profile image
Kaamkiya

This is awesome! I personally use tldr, because it's easy to access from the terminal. This is a fantastic sheet, though. Also, ls -al displays the verbose output for files (date, author, update, etc), while ls just displays the files.

Collapse
 
greenteaisgreat profile image
Nathan G Bornstein

Holy heck, thanks for the lead to tldr; I never knew I needed that in my life until now

Collapse
 
teyim profile image
Teyim Asobo

nice

Collapse
 
semo profile image
semo

Cool. I use each command. Good to know I left the early admin stages.

Collapse
 
mellen profile image
Matt Ellen-Tsivintzeli

Very good list.

A command I use almost daily is grep -rnI "thing I want to find" to search though a directory recursively but Ignoring binary files and giving me line numbers. I also add --exclude-dir=.svn because searching through the SVN stuff is pointless.

Collapse
 
moopet profile image
Ben Sinclair

Some of these are problematic, e.g.:

cd - Navigate to the home directory (using the $HOME variable)

This is correct, but the way you say it makes it look like cd - which acts to toggle you between the current and previous directories.

You mix adduser with userdel and usermod when there's a useradd command but don't explain why.

You should explain what you mean by "forecefully".

touch newfile – Creates an empty file named 'newfile'.

This is incorrect. touch newfile updates one of the timestamps on a file called newfile. If newfile doesn't exist, it is created as a side effect, but that's not what the command does.

find /etc/ -name "searchargument" – Finds files with names starting with searchargument in the /etc directory.

This finds files and directories with the exact name "searchargument".

Collapse
 
cappe987 profile image
Casper

ifconfig is deprecated and ip command should be used instead.

Collapse
 
tontonastro profile image
tontonastro

Tonton Astro Ria for live episodes of Malay dramas and Malaysian telefilms 2024.
Explore Drama Melayu free online 2023 and enjoy free series online dfm2u hd today.

Tonton Astro Ria

Collapse
 
abhixsh profile image
Abishek Haththakage

Really important

Collapse
 
alexteendev profile image
alex

Oh, nice!
Now I, as professional Linux user, can calmly remove project server

Collapse
 
abhixsh profile image
Abishek Haththakage

you made my day!

Collapse
 
christosc77 profile image
christosc77

@ Directory navigation:
pushd /var - put current directory on stack and jump to /var
popd - jump back to directory on stack

Collapse
 
levifrance profile image
Levi France

Awesome share, thanks