The details
Apache
-
Switch php versions
sudo a2dismod php<version>
sudo a2enmod php<version>
sudo service apache2 restart
archive
-
gzip
create gzip file
gzip file
tar
Create archive without absolute paths
tar -czf new_archive.tar.gz -C folder .
Extract to a specific folder
tar –xvzf documents.tar.gz –C /home/user/destination
cat
-
concatenate files and print on the standard output
cat <file>
cat access logs, pipe to [[grep]] to extract uniq IPs in order
cat access.log | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | sort -u -V
curl
-
get header info
curl -ILv https://your_domain
- I, --headShow document info only
- L, --location Follow redirects
- -v, --verbose Make the operation more talkative
test for gzip
curl -H "Accept-Encoding: gzip" -I http://your_domain/some_text_file
date time
-
Time zone
list times zones
timedatectl list-timezones
set time zone
sudo timedatectl set-timezone Africa/Johannesburg
disk
-
DF
The ‘df’ command stands for “disk free” and is used to display information about the file systems on your Linux system. It provides a snapshot of disk usage, showing the total space, used space, available space, and the percentage of use for each mounted file system.
df -h /
DU (and NCDU)
The `du` command in Linux is a powerful utility that allows users to analyze and report on disk usage within directories and files.
du -h --max-depth=1 /path
Docker
-
Set up
Run Docker without sudo. Use usermod to add current username to the docker group.
sudo usermod -aG docker ${USER}To apply the new group membership, log out of the server and back in, or type the following:
su - ${USER}Images
List images
docker images
Remove image
docker rmi image_name_or_id
docker image rm image_id
Containers
List all containers
docker ps -a
List container IDs containers
docker ps -q
Stop all containers
docker stop $(docker ps -aq)
Volumes
List volumes
docker volume ls
Remove unused volumes
docker volume prune
firefox
-
changes to the about:config
scrollbar size
widget.non-native-theme.scrollbar.size.override = 20
widget.non-native-theme.scrollbar.style = 4
cookiebanner
cookiebanners.ui.desktop.enabled = true
find
-
find file with name
find . -type f -name <file name>
find all *.log files created in last 90 days except for last 7 days
find . -type f -name "*.log" -mtime +7 -mtime -90 -ls
- search current directory + subdirectories for files (-type f):
- with the .log extension (-name "\*.log")
- that were last modified more than 7 days ago (-mtime +7)
- but less than 90 days ago (-mtime -90)
- list (-ls) results
- option: case insensitive search replace the -name "\*.log" with -iname "\*.log"
find delete all *.log files created in last 90 days except for last 7 days
find . -type f -name "*.log" -mtime +7 -mtime -90 -delete
git
-
rebase
git rebase <base>
get the remote URL
git ls-remote --get-url
grep
-
find string in files recursively and show line numbers
grep -rn <search string> .
grep -rn --exclude-dir=<directory name> <search string> .
keys
-
generate ssh key
ssh-keygen
- set key type as rsa|dsa|ecdsa|ed25519
-t rsa
- set bit length to 4096
-b 4096
Convert PPK to id_rsa
puttygen example.ppk -O private-openssh -o example_id_rsa
Convert id_rsa to PPK
puttygen example.ppk -O private-openssh -o example_id_rsa
- set key type as rsa|dsa|ecdsa|ed25519
link
-
unlink
unlink <file name>
mysql (or my squirrel)
-
login with user name and password
mysql -u database_user -p
mysql -h database_host -u database_user -p
export a database
mysqldump -u root -p database_name > database_name.sql
import database
mysql -u root -p database_name < file.sql
create user
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
FLUSH PRIVILEGES;
show users
select * from mysql.user;
update
UPDATE _table_name_ SET _column1_ = _value1_, _column2_ = _value2_, ... WHERE _condition_;
rsync
-
sync
rsync -az --info=progress2
/ / - a:recursively transferred in "archive" mode, ensures symbolic links, devices, attributes, permissions, ownerships, etc.
- z: enable compression
- --info=progress2: statistics based on the whole transfer
sed
-
find and replace string in file
sed -i -e 's/abc/XYZ/g' /tmp/file.txt
Short URLs
-
- bit.ly - add + at the end
- cutt.ly - add @
- tiny.cc - add =
- tinyurl.com - add preview. before tinyurl.com
Space and size
-
disk space
df -h /
folder size
du -h --max-depth 1 /
du -h -d 1 /
ssh
-
ssh -i <identity_file> -t <user>@<host> "<command>"
- `-t` Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine
text
-
sort
Dedupe text file:
sort -u input-file output-file
- -u, --unique
- with -c, check for strict ordering; without -c, output only the first of an equal run
wget
-
Output response of url to file and print server response
wget -O <output file> -S <url>
wget -SO- -T 5 -t 1 https://example.com