Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Linux Command Line Cheat Sheet

A collection of Linux commands and concepts I tend to forget

A. System

sudo reboot

B. File System


Current directory: pwd
Show file contents: cat File

List file sizes: ls -lah

Log file viewing: tail error_log -n 50

List size of all directories in current directory: find . -maxdepth 1 -type d | xargs du -m -s

Find files

find . -name '*{part_of_word}*' -print

What is taking up space?

cd /
du -ch -d 1 | sort -hr

...or ncdu


Free disc space: df -h
Directory size: du -sh /var

Removing old kernel images etc.

sudo apt-get autoremove

Creating Archives

zip -r dir_path

Extracting Archives

unzip .zip-file-name -d /path/to/extract

C. Permissions

There are three permissions you can set, and there are three classes that can receive those permissions.

read, write, execute
user, group, others

Symbolic Notation	Octal Notation	English
----------	0000	no permissions
---x--x--x	0111	execute
--w--w--w-	0222	write
--wx-wx-wx	0333	write & execute
-r--r--r--	0444	read
-r-xr-xr-x	0555	read & execute
-rw-rw-rw-	0666	read & write
-rwxrwxrwx	0777	read, write, & execute

#list users
cat /etc/passwd

#list groups
cat /etc/group

Each user usually has at least one corresponding group, which has the same name as the user.

Directories are just special files, and they have the same owner and permission rules as ordinary files.

D. User handling

Change password


Create user

sudo adduser MYUSER

Allow user to login over SSH

  • Edit SSH configuration: sudo vim /etc/ssh/sshd_config
  • Add AllowUsers MYUSER to the bottom of the file to only allow ssh login with MYUSER
  • Reload SSH with sudo reload ssh

E. System Activity and Resources

Find process

ps -ef | grep php



displays memory usage: Shift + f, then press n


free - shows available memory


free -m

To see how much ram is free to use for your applications, run free -m and look at the row that says "-/+ buffers/cache" in the column that says "free". That is your answer in megabytes:

see also

Network monitoring

sudo iftop
sudo nethogs eth0


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment