Перейти к содержанию

System Commands Reference

How to display all environment variables

printenv

Manual: printenv

How to stop/start the local PostgreSQL

sudo systemctl status postgresql
sudo systemctl stop postgresql
sudo systemctl start postgresql

Manual: systemctl

How to print all .py files in a project folder except some folders

find . -type d \( -path ./.tox -o -path ./venv_py39 -o -path ./venv_py310 \) -prune -o -name '*.py' -print

How to find all folders and files where the word "telegram" occurs

find / -iname "*telegram*" 2>/dev/null

How to display a tree of directories and files of a Python project

# Using
tree -a -I 'venv_py310|.idea|.git|.pytest_cache|.mypy_cache|.hypothesis|.coverage|__pycache__|docs|tests|src|*.sql|*.xml' --dirsfirst --sort=name -n -A

How to get detailed statistics on the size of folders and files

How to get detailed statistics on the size of folders and files with a depth of no more than 2 and a size of at least 10 GB and sort by size in descending order:

sudo du -h --max-depth=1 ./ | awk '$1 ~ /[0-9]+G/ && $1+0 >= 10 {print $0}' | sort -hr

How to display the operating system version

lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:    20.04
Codename:   focal

How to find the currently running shell

ls -l /proc/$$/exe

# /proc/19624/exe -> /usr/bin/bash

How to get information about the default shell

echo $SHELL

# /bin/bash

Manual: grep

kubectl explain pod --recursive | grep -A5 tolerations

How to find out the IP addresses of a host

ip address show
nmcli show
Manual: ip-address

How do I find out what is currently listening on which port

$ sudo netstat -tulpn

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      917/systemd-resolve
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      952/cupsd
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      1186/postgres
tcp        0      0 127.0.0.1:8000          0.0.0.0:*               LISTEN      25428/python
tcp6       0      0 127.0.0.1:63342         :::*                    LISTEN      8920/java
tcp6       0      0 ::1:631                 :::*                    LISTEN      952/cupsd
tcp6       0      0 127.0.0.1:6942          :::*                    LISTEN      8920/java
udp        0      0 0.0.0.0:57025           0.0.0.0:*                           948/avahi-daemon: r
udp        0      0 127.0.0.53:53           0.0.0.0:*                           917/systemd-resolve
udp        0      0 0.0.0.0:631             0.0.0.0:*                           1050/cups-browsed
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           948/avahi-daemon: r
udp6       0      0 :::41301                :::*                                8920/java
udp6       0      0 :::8976                 :::*                                8920/java
udp6       0      0 :::60237                :::*                                948/avahi-daemon: r
udp6       0      0 :::5353                 :::*                                948/avahi-daemon: r
Manual: netstat

How to create a string hash

echo -n 'Some text' | base64
# Output: U29tZSB0ZXh0

How to replace a file with content from another file?

cp -f [source_file] [destination_file]
Copies the original file and overwrites the target file (hence -f which stands for "force").

In case you are attempting to copy just the content of the file try:

cat /first/file/same_name > /second/file/same_name
This will overwrite all the content of the second file with the content from the first. However, your owner, group, and permissions of the second file will be unchanged.

How to see which services start when the system starts

systemctl list-unit-files --type=service --state=enabled

What's next?

  1. Found this article helpful? Share it and help spread the knowledge!
  2. Found a mistake or have ideas 💡 on what and how I can improve? Message me on Telegram.
  3. Want to know more about me? Read here.