Skip to content

Instantly share code, notes, and snippets.

@anselmdk
Last active July 29, 2020 14:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save anselmdk/f64cc982ca823ecb2800 to your computer and use it in GitHub Desktop.
Save anselmdk/f64cc982ca823ecb2800 to your computer and use it in GitHub Desktop.
Linux Command Line Cheat Sheet

A collection of Linux commands and concepts I tend to forget

A. System

#reboot
sudo reboot

B. File System

Info

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

more

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

Removing old kernel images etc.

sudo apt-get autoremove

Creating Archives

zip -r foo.zip 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

passwd

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

Top

top

displays memory usage: Shift + f, then press n

Free

free - shows available memory

http://stackoverflow.com/questions/3784974/want-to-know-whether-enough-memory-is-free-on-a-linux-machine-to-deploy-a-new-ap/4417121#4417121

Explaination: http://www.linuxatemyram.com/

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 http://www.cyberciti.biz/faq/linux-check-memory-usage/

Network monitoring

sudo iftop
sudo nethogs eth0

Articles

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