A collection of useful command-line one-liners, scripts, and tips for Linux/Unix systems administration and development.
- Benchmarking
- User Management
- System Configuration
- Date and Time
- Pastebin Services
- Docker
- AWK
- Find
- Sed
- Network Tools
- SSH
- Bash Loops
- Archive Handling
- Vim/Neovim Plugin Management
- Cat with Heredoc
Quick server benchmarking scripts.
Method 1:
wget -qO- bench.sh | bashMethod 2:
curl -Lso- bench.sh | bash
⚠️ Security Note: Always review scripts before piping to bash. Consider running without| bashfirst to inspect the content.
Option 1: Add to main sudoers file
echo "$USER ALL=(ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoersOption 2: Create user-specific sudoers file (recommended)
For Debian:
echo 'debian ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/debianFor Ubuntu:
echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/ubuntuFor CentOS/RHEL:
echo 'centos ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/centos
⚠️ Security Warning: NOPASSWD is convenient but reduces security. Use only for development/testing environments.
Useful for distinguishing root from regular users.
Regular user (green prompt):
echo "PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '" >> ~/.bashrcRoot user (red prompt):
echo "PS1='\[\e[1;31m\][\u@\h \W]\$\[\e[0m\] '" >> ~/.bashrcApply changes:
source ~/.bashrcIncrease the inotify watch limit:
echo fs.inotify.max_user_watches=100000 | sudo tee -a /etc/sysctl.conf
sudo sysctl -pUseful date formatting for timestamps.
Basic date format (YYYYMMDD):
date +"%Y%m%d"Example output: 20131016
ISO date format (YYYY-MM-DD):
date +"%Y-%m-%d"Example output: 2013-10-16
Full timestamp (YYYYMMDD_HHMMSS):
date +"%Y%m%d_%H%M%S"Example output: 20131016_193655
Quick text sharing via netcat.
Pipe any output to termbin:
ls -la | nc termbin.com 9999Website: http://termbin.com/
Modern Rust-based pastebin service.
Pipe to paste.rs:
echo "Hello World" | curl --data-binary @- https://paste.rsFrom file:
curl --data-binary @file.txt https://paste.rsWebsite: https://paste.rs
Simple pastebin via curl.
Pipe any output:
ls -la | curl -F 'f:1=<-' ix.ioFrom file:
curl -F 'f:1=<-' ix.io < file.txtModern method (recommended):
Ubuntu/Debian:
sudo apt-get update
sudo apt-get install docker.io docker-composeRHEL/CentOS/Fedora:
sudo dnf install docker docker-composeArch Linux:
sudo pacman -S docker docker-composeQuick install script (for supported distros):
curl -fsSL https://get.docker.com | sudo sh
⚠️ Note: Always review scripts before piping to shell.
Add current user to docker group:
sudo usermod -aG docker $USERAdd specific user (e.g., ubuntu):
sudo usermod -aG docker ubuntuApply group changes (or logout/login):
newgrp dockerGet IP of specific container (by ID):
docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CID}Get IP of specific container (by name):
docker inspect --format '{{ .NetworkSettings.IPAddress }}' container_nameGet IPs of all running containers:
docker inspect --format '{{ .Name }} - {{ .NetworkSettings.IPAddress }}' $(docker ps -q)Using jq for JSON parsing:
docker inspect container_name | jq -r '.[0].NetworkSettings.IPAddress'Powerful text processing examples.
Print the first statement on first line:
cat file | awk 'NR==1{print $1}'Print assigned IP addresses on network interface:
arp -n | grep eth0 | awk '{print $1}'Print all columns:
awk '{print $0}' filePrint the 3rd column:
awk '{print $3}' filePrint the 1st and 3rd columns:
awk '{print $1 $3}' filePrint all columns except the 3rd:
awk '{$3=""; print $0}' filePrint all columns except the 1st and 2nd:
awk '{$1=$2=""; print $0}' fileFor directories:
find . -type d -exec chmod 755 {} +For files:
find . -type f -exec chmod 644 {} +SSH directory example:
find $HOME/.ssh/ -type f -exec chmod 600 {} +sudo find . -type d -user root -exec chown idv:idv {} \;find . -name "*.sh" -execdir chmod u+x {} +du -hsx * | sort -rh | head -10Disable GRUB boot animation:
Ubuntu/Debian:
sudo sed -i 's/quiet splash//' /etc/default/grub && sudo update-grubRHEL/CentOS/Fedora:
sudo sed -i 's/quiet splash//' /etc/default/grub && sudo grub2-mkconfig -o /boot/grub2/grub.cfgLocale correction:
sed -i 's/uk_UA.UTF-8/en_US.UTF-8/' /etc/default/localeReplace hostname in /etc/hosts:
sed -i "s/ubuntu1404/$(hostname)/" /etc/hostsMethod 1: Using grep and xargs
grep -rl "windows" . | xargs sed -i "s/windows/linux/g"Method 2: Using find
find /path -type f -exec sed -i 's/example.com/superexample.com/g' {} +💡 Tip: Use
sed -i.bakto create backups before replacing.
Get external IP:
curl ifconfig.coGet all network information:
curl ifconfig.co/allAlternative services:
curl ifconfig.me
curl icanhazip.com
curl ipinfo.io/ipModern syntax (preferred):
eval "$(ssh-agent -s)"Check agent socket:
echo $SSH_AUTH_SOCKLegacy syntax (still works):
eval `ssh-agent`Add default key:
ssh-addAdd specific key:
ssh-add ~/.ssh/id_ed25519List loaded keys:
ssh-add -lLocal port forward syntax:
ssh -L <local_port>:<destination_server>:<destination_port> user@<ssh_server> -p <ssh_port>Example: Access router's web interface
If router's WAN IP is 12.23.34.45, SSH port is 9999, and web interface is on port 80:
ssh -L 12345:localhost:80 root@12.23.34.45 -p 9999Then access via: http://localhost:12345
Multiple port forwards:
ssh -L 8080:127.0.0.1:80 \
-L 8443:127.0.0.1:443 \
-L 8001:127.0.0.1:8001 \
-L 5901:127.0.0.1:5901 \
-L 1313:127.0.0.1:1313 \
user@hostfor i in {1..10}; do command; donefor i in {18,20,21}; do
sleep 10
ssh node-$i "tar zcvf - /var/log/ceilometer | cat > /tmp/ceilometer-node$i.tar.gz"
donefor i in {18,20,21}; do
scp node-$i:/tmp/ceilometer-node$i.tar.gz .
doneDownload and extract archives in one command.
Uncompressed tar:
wget http://example.com/archive.tar -O - | tar -xGzipped tar:
wget http://example.com/archive.tar.gz -O - | tar -xzBzip2 tar:
wget http://example.com/archive.tar.bz2 -O - | tar -xjUncompressed tar:
curl http://example.com/archive.tar | tar -xGzipped tar:
curl http://example.com/archive.tar.gz | tar -xzBzip2 tar:
curl http://example.com/archive.tar.bz2 | tar -xjInstall Pathogen plugins from file (if you have a plugins file listing GitHub repositories):
while read plugin; do
git clone https://github.com/$plugin ~/.vim/bundle/
done < pluginsvim-plug (most popular):
Add to ~/.vimrc:
call plug#begin()
Plug 'tpope/vim-sensible'
Plug 'junegunn/fzf'
call plug#end()Native package management (Vim 8+):
git clone https://github.com/tpope/vim-sensible.git \
~/.vim/pack/vendor/start/vim-sensibleNeovim with lazy.nvim: Modern Lua-based plugin manager for Neovim users.
sql=$(cat <<EOF
SELECT foo, bar FROM db
WHERE foo='baz'
EOF
)Check the variable:
echo -e "$sql"cat <<EOF > print.sh
#!/bin/bash
echo \$PWD
echo $PWD
EOFThe print.sh file will contain:
#!/bin/bash
echo $PWD
echo /home/usercat <<EOF | grep 'b' | tee b.txt | grep 'r'
foo
bar
baz
EOFThis creates b.txt with both bar and baz lines but prints only bar.
Feel free to submit pull requests with additional tips and tricks!
MIT License - feel free to use these commands in your own work.