Last active
April 4, 2024 12:21
-
-
Save abalaci/1489033a1db8f196d3676f26080c8969 to your computer and use it in GitHub Desktop.
A Bash cheat sheet for various tasks on Ubuntu-based distros.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add a string to the beginning of each line in a file: | |
awk '{ print "prefix" $0 }' PATH-TO-FILE | |
# Append a directory to the PATH environment variable: | |
PATH="${PATH:+${PATH}:}/path/to/directory" | |
# Change author for last N Git commits: | |
git rebase -i HEAD~N -x "git commit --amend --author 'Author Name <author.name@mail.com>' --no-edit" | |
# Change the password of a Linux user account: | |
[sudo] passwd [USERNAME] | |
# Clean all files not tracked by Git, including those present on ignore lists: | |
git clean -dfx | |
# Compress a PDF file: | |
ps2pdf -dPDFSETTINGS=/ebook PATH-TO-INPUT.pdf PATH-TO-OUTPUT.pdf | |
# Create a PEM file from a PPK file: | |
[sudo] apt-get update && [sudo] apt-get install putty-tools | |
puttygen INPUT-FILE.ppk -O private-openssh -o OUTPUT-FILE.pem | |
# Create a symbolic link to a given file: | |
[sudo] ln -s PATH-TO-FILE PATH-TO-LINK | |
# Delete a directory and all of its contents: | |
[sudo] rm -rf PATH-TO-DIRECTORY | |
# Delete all subdirectories with a specific name: | |
find PARENT-DIRECTORY -type d -name "SUBDIRECTORY" -exec rm -rf {} + | |
# Delete KDE icons cache: | |
rm ~/.cache/icon-cache.kcache | |
# Disable a service from starting on boot: | |
[sudo] systemctl disable SERVICE-NAME | |
# Display current system time, date, and timezone: | |
## If your system was booted using systemd, use: | |
timedatectl | |
## Otherwise, use: | |
date | |
# Download all PDF files from a web page: | |
wget -r -A.pdf WEB-PAGE-URL | |
# Export GPG private key: | |
gpg --export-secret-key KEY-ID > KEY-FILE | |
# Export GPG public key: | |
gpg --export KEY-ID > KEY-FILE | |
# Fast-copy files/directories: | |
[sudo] rsync --info=progress2 -auvz PATH-TO-SOURCE PATH-TO-DESTINATION | |
# Find common lines between 2 text files: | |
grep -iFxf PATH-TO-FIRST-FILE PATH-TO-SECOND-FILE | |
# Find running processes matching a specific pattern: | |
psgrep -la PROCESS-PATTERN | |
# Get the SHA256 fingerprint of an SSH key: | |
ssh-keygen -lf PATH-TO-SSH-KEY | |
# Import GPG public/private key: | |
gpg --import KEY-FILE | |
# List all enabled software repositories: | |
grep ^deb /etc/apt/sources.list /etc/apt/sources.list.d/* | |
# List all environment variables: | |
printenv | |
# List all Git branches containing a specific commit: | |
git branch --contains COMMIT_HASH | |
# List all TCP connections from a specific IP address | |
netstat -t | grep IP-ADDRESS | |
# List available memory hardware: | |
[sudo] lshw -c memory | |
# List local Git tags: | |
git tag -n | |
# List installed packages: | |
apt list --installed | |
# List network interfaces: | |
ip link show | |
# List OS version details: | |
cat /etc/os-release | |
# Parse a CSV file using GNU awk: | |
gawk -vFPAT='[^,]*|"[^"]*"' '{ print $1 }' | |
# Remove all quotes from a string using awk: | |
awk '{ gsub(/"/, "", $0); print $0 }' | |
# Skip the first line in a file when using awk: | |
awk 'NR>1 { print $0 }' | |
# Test whether a port on a remote machine is reachable: | |
nc -v HOSTNAME|IP-ADDRESS PORT | |
# Truncate a specific file: | |
[sudo] cat /dev/null > PATH-TO-FILE | |
# Update all snap packages: | |
[sudo] snap refresh | |
# Verify the GPG signature of a Git commit: | |
git verify-commit COMMIT-HASH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment