Skip to content

Instantly share code, notes, and snippets.

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
# Shorter output for dig command, similar to the host command
dig +short AAAA
# Exit out of a hung terminal
<Enter> <Shift-`> <Period>
# Exit out of a shell or proc, or cause a End of Transmission (EOT)
# Clear screen in shell
# Mysql dump with progress
mysqldump [parameters] | pv > output.sql
mysqldump [parameters] | pv | gzip -c > output.sql.gz
# Download TLS certificate
openssl s_client -servername -connect </dev/null | \
# 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
# 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.