Skip to content

Instantly share code, notes, and snippets.

@psulek
Last active January 5, 2022 15:02
Show Gist options
  • Save psulek/45f821095594df8822669aa129d3b63f to your computer and use it in GitHub Desktop.
Save psulek/45f821095594df8822669aa129d3b63f to your computer and use it in GitHub Desktop.
Linux Commands

Services management

Start/Stop/Restart/Status

sudo service service_name [status|stop|start|restart]

alternative 1:

sudo systemctl [status|stop|start|restart] service_name

alternative 2:

sudo service --status-all | grep service_name

List of all services

service --status-all

Users

Name of currently logged user

who

How to see which groups specific user account belongs to

groups user_name

Add user to specific group

sudo adduser user_name group_name
usermod -aG sudo user_name

Show all users processes tree

ps faux

File system

Get current path

pwd

Remove folder (non-empty)

sudo rm -rf folder

Get free disk space

df -h

Display file content with automatic refresh

watch -n 1 tail filename

Create tar.gz archive file

tar -czvf filename.tar.gz /path/to/dir1

Move all files and folder into diff directory

mv -v ~/Downloads/* ~/Videos/

Clear content of file

sudo truncate -s 0 filename

Operating System

Reboot

sudo reboot

Rename host name (computer name):

gksu gedit /etc/hostname
gksu gedit /etc/hosts
sudo service hostname restart

alternative:

hostnamectl set-hostname new-hostname

Get a parent PID

ps -o ppid=PID
ps -f PID
pstree -s -p PID

Find process by name

ps aux | grep -i process_name

Kill process with specific port listening:

kill $(sudo lsof -t -i:port)

Get os name and version:

lsb_release -a

alternative:

uname -r

Get public IP from shell

curl ipinfo.io/ip

Sync Time

dpkg-reconfigure tzdata

Which process use specific port:

lsof -i :port

Get detailed information about a given PID?

ps -Flww -p PID

Misc

Install Certbot-auto

https://certbot.eff.org/docs/install.html#certbot-auto

wget https://dl.eff.org/certbot-auto
sudo mv certbot-auto /usr/local/bin/certbot-auto
sudo chown root /usr/local/bin/certbot-auto
sudo chmod 0755 /usr/local/bin/certbot-auto
/usr/local/bin/certbot-auto --help

Add firewall rule

iptables -A REDIS -s 192.168.10.1 -j ACCEPT
iptables -A REDIS -s 192.168.10.2 -j ACCEPT
iptables -A REDIS -j LOG --log-prefix "unauth-redis-access"
iptables -A REDIS -j REJECT --reject-with icmp-port-unreachable
iptables -I INPUT -p tcp --dport 6379 -j REDIS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment