linux

file and directory commands

ls -al                  # List all files in a long listing (detailed) format
pwd                     # Display the present working directory
mkdir directory         # Create a directory
rm file                 # Remove (delete) file
rm -r directory         # Remove the directory and its contents recursively
rm -f file              # Force removal of file without prompting for confirmation
rm -rf directory        # Forcefully remove directory recursively
cp file1 file2          # Copy file1 to file2
cp -r dir1 dir2         # Copy dir1 to dir2. If dir2 doesn't exist, create dir2
mv file1 file2          # Rename or move file1 to file2
ln -s /path/to/file linkname  # Create symbolic link to linkname
touch file              # Create an empty file.
cat file                # View the contents of file
less file               # Browse through a text file
head file               # Display the first 10 lines of file
tail file               # Display the last 10 lines of file
tail 15 file            # Display the last 15 lines of file
tail -f file            # Display the last 10 lines of file and "follow" the file as it grows

system info

uname -a                # Display Linux system information
uname -r                # Display kernel release information
cat myfile              # Reads myfile
uptime                  # Show how long the system has been running + load
hostname                # Show system host name
hostname -I             # Display the IP addresses of the host
last reboot             # Show system reboot history
date                    # Show the current date and time
cal                     # Show this month's calendar

hardware info

dmesg                   # Display messages in kernel ring buffer
cat /proc/cpuinfo       # Display CPU information
cat /proc/meminfo       # Display memory information
free -h                 # Free / used memory ( -h for human, -m for MB, -g for GB.)
lspci -tv               # Display PCI devices
lsusb -tv               # Display USB devices
dmidecode               # Display DMI/SMBIOS (hardware info) from the BIOS
hdparm -i /dev/sda      # Show info about disk sda
hdparm -tT /dev/sda     # Perform a read speed test on disk sda
badblocks -s /dev/sda   # Test for unreadable blocks on disk sda

performance monitoring and statistics

top                     # Display and manage the top processes
htop                    # Interactive process viewer (top alternative)
mpstat 1                # Display processor related statistics
vmstat 1                # Display virtual memory statistics
iostat 1                # Display I/O statistics
tcpdump -i eth0         # Capture and display all packets on interface eth0
tcpdump -i eth0 'port 80' # Monitor all traffic on port 80 ( HTTP )
lsof                    # List all open files on the system
lsof -u user            # List files opened by user
watch df -h             # Execute "df -h", showing periodic updates
tail 100 /var/log/messages  # Display the last 100 syslog messages
tail 100 /var/log/syslog    # Display the last 100 syslog messages on Debian systems

user info and management:

id                      # Display the user and group ids of your current user.
last                    # Display the last users who have logged onto the system.
who                     # Show who is logged into the system.
w                       # Show who is logged in and what they are doing.
groupadd test           # Create a group named "test".
useradd -c "John Smith" -m john # Create an account named john.
userdel john            # Delete the john account.
usermod -aG sales john  # Add the john account to the sales group

process management

ps                      # Display your currently running processes
ps -ef                  # Display all the currently running processes on the system.
ps -ef | grep process1  # Display process information for process1
top                     # Display and manage the top processes
htop                    # Interactive process viewer (top alternative)
kill pid                # Kill process with process ID of pid
killall process1        # Kill all processes named process1
program &               # Start program in the background
bg                      # Display stopped or background jobs
fg                      # Brings the most recent background job to foreground
fg n                    # Brings job n to the foreground

networking

ifconfig -a             # Display all network interfaces and ip address
ifconfig eth0           # Display eth0 address and details
ethtool eth0            # Query or control network driver and hardware settings
ping host               # Send ICMP echo request to host
whois domain            # Display whois information for domain
dig domain              # Display DNS information for domain
dig -x IP_ADDRESS       # Reverse lookup of IP_ADDRESS
host domain             # Display DNS ip address for domain
hostname -i             # Display the network address of the host name.
hostname -I             # Display all local ip addresses
wget http://domain/file # Download http://domain/file
netstat -nutlp          # Display listening tcp and udp ports and corresponding programs

file permissions

chmod 777 filename      # Three digits stand for USER, GROUP, WORLD permissions
chmod 775 filename      # 7 - read, write, execute
chmod 755 filename      # 6 - read, write
chmod 664 filename      # 5 - read, execute
chmod 644 filename      # 4 - read only
chmod +x filename       # Add execute permission
chmod +w filename       # Add write permission
chmod +r filename       # Add read permission

Find the original collection @ https://www.linuxtrainingacademy.com/linux-commands-cheat-sheet/

docker

docker exec -it mycontainer python3 manage.py       # yoyo
docker build -t cccidock/django:1.0.9 -t cccidock/django:1 -t cccidock/django:latest .
docker push cccidock/django
# https://certbot.eff.org/docs/install.html?highlight=docker
docker run -it --rm --name certbot -v "/etc/letsencrypt:/etc/letsencrypt" -v "/var/lib/letsencrypt:/var/lib/letsencrypt" -p 80:80 certbot/certbot certonly
docker run -it --rm --name certbot -v "/etc/letsencrypt:/etc/letsencrypt" -v "/var/lib/letsencrypt:/var/lib/letsencrypt" -p 80:80 certbot/certbot renew

python

python -V                           # Display the version of python on your device
which python                        # Display python installation directory
sudo apt-get update                 # Update apt-get before installing pip
sudo apt-get upgrade                # CHECK
sudo apt-get install python-pip     # Install pip (python3-pip for pip3)
sudo pip install --upgrade setuptools
echo '{"people":[{"name":"Scott", "website":"stackabuse.com", "from":"Nebraska"}]}' | python -m json.tool

git

git config --global user.name "ccci-io"
git config --global user.email "i@ccci.io"
git init            # Create an empty git repo
git push [variable name] :[branch name]
git remote rm repo
git pull https://github.com/ccci-io/myproject.git
git clone https://github.com/ccci-io/myproject.git
git add file.txt
git commit -m “Commit Message”

upload changes to github

git add .
git commit -m "Commit comments"
git push origin master

import a project to github

cd ~/myproject  # Go to your project folder
git init        # Initialize github repo
git config --global user.name "ccci-io"
git config --global user.email "i@ccci.io"
git add .       # Adds the files in the local repository and stages them for commit
git commit -m "First commit"    # Commits the tracked changes
# Start a new repository on https://github.com and copy it's url.
git remote add origin https://github.com/ccci-io/myproject.git  # origin for repository owner
git remote -v   # Verify
git remote set-url origin https://github.com/ccci-io/myproject.git  # Rename if origin exists
git push origin master

Resource @ https://help.github.com/en/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line