Linux command cheatsheet

Finding files

# finding a file
# 1. find hello.txt in /src
find /src -name hello.txt

# Find large files in linux
$ sudo du -a /dir/ | sort -n -r | head -n 20

Add a new user

adduser <username> --shell /bin/bash --home <home directory>

Add a user to an existing to group

usermod -aG <group name> <username>

# eg1: add user to sudo group
usermod -aG sudo <username>

Remove user from a group

gpasswd -d <user name> <group name>

# show the group of the user
groups <user name>

Creating symbolic link

ln -s <source folder> <new shortcut>

Show current memory usage

> free -h

              total        used        free      shared  buff/cache   available
Mem:           875M        141M        155M         80M        579M        592M
Swap:           99M          0B         99M

or

> free -m

              total        used        free      shared  buff/cache   available
Mem:            875         141         155          80         579         592
Swap:            99           0          99

Remove password requirement

sudo vim /etc/pam.d/common-password

remove obscure to disable complexity check

add minlen=3 to add min password length

Service control

# Start a service
sudo service nginx start

# check the status of a service
sudo service nginx statua

# stop a service
sudo service nginx stop

# list all service
service --status-all
service --status-all | more
service --status-all | grep ntpd
service --status-all | less

Posted in notesTagged