Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cheatsheet for Fedora, CentOS, and RedHat family members of Linux
# Fix user and directory permissions:
find . -type f -print0 | sudo xargs -0 chmod 664
find . -type d -print0 | sudo xargs -0 chmod 775
# Copy user permissions to group permissions:
chmod -R g=u .
# Make new files inherit the group of the container directory
chmod g+s <directory>
# Give sudo privileges:
sudo usermod -aG wheel <user>
# Service management:
sudo chkconfig --list
sudo service <name> <start|stop|restart|status>
# Directory find and replace:
find * -name *.php -print | xargs perl -pi -w -e 's/error_reporting\(.*\)/error_reporting\(0\)/g;'
# Calculate size of directory:
du -hs * 2>/dev/null | sort -h
# Calculate size of directory alternative format:
sudo du /var/ | sort -nr | head -n20 | awk '{print $2}' | sudo xargs -L1 du -sh
# Find orphaned file handles:
lsof | grep deleted
# Save files as root in vim without an elevated vim:
:w !sudo tee %
# Clone a website:
wget --mirror --convert-links --backup-converted --adjust-extension http://url/of/web/site
# Check if after installing updates we need to reboot:
sudo dnf needs-restarting
# Check if we can open an interactive editor for final composition
if [ -n "$EDITOR" ] && [ -t 0 ]; then
# Allow composing the final message
$EDITOR /tmp/somefile < /dev/tty > /dev/tty
fi
# Shorter output for dig command, similar to the host command
dig +short carlbennett.me AAAA
# Exit out of a hung terminal
<Enter> <Shift-`> <Period>
# Exit out of a shell or proc, or cause a End of Transmission (EOT)
<Ctrl-D>
# Clear screen in shell
<Ctrl-L>
# Mysql dump with progress
mysqldump [parameters] | pv > output.sql
mysqldump [parameters] | pv | gzip -c > output.sql.gz
# Download TLS certificate
openssl s_client -servername example.com -connect example.com:443 </dev/null | \
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' >example.com.crt
# Show failed services when systemd status shows degraded
systemctl --failed
# Debug dhcp IPv6 lease issues
sudo dhclient -6 -d
# Group by most common requesting IP in access log
tail -n 5000 access_log | awk '{print $1}' | sort | uniq -c | sort -gr | head
# Run a process on a specific NUMA node
numactl --cpunodebind=1 ./binary
# Decrypt a PGP message from 'file.asc' to 'file'
gpg file.asc
# Encrypt a PGP message from 'file' to 'file.asc'
gpg -a -e -r <from> -r <to> [-r <cc>] file
# Boot into multi-user mode on a systemd distribution
# Append the following to the linux/linuxefi boot directive in grub
systemd.unit=multi-user.target
# Don't update with weak dependencies
dnf update --setopt=install_weak_deps=False --best
# Full database backup with mysqldump
mysqldump --host="${MYSQLHOST}" --user="${MYSQLUSER}" \
--password="${MYSQLPASS}" \
--opt --order-by-primary \
--complete-insert --single-transaction --triggers --routines \
--hex-blob --add-drop-database \
--result-file "$(date +%Y-%m-%d_%H:%M:%S.sql)" \
--databases "${DATABASE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.