A collection of Linux commands that make everyday server administration easier.
Repeat the last command
!!
Runs the most recently executed command again.
Run a command at a set time
sudo apt install -y at
echo "halt" | at 10:20
Schedules the given command to run at the time you specify.
Find files that contain a word
find . -iname "*.js" | xargs grep "js.map" -sl
Lists the files that contain the given text.
Show the processes using the most memory
ps aux | sort -nk 4 | tail
Remove comment lines from a file
sed -e '/^#/d' -e 's/#.*$//' file.txt
Deletes lines starting with # and trailing comments from the output.
Stop all processes of a user
killall -u username
List files between 50 MB and 1 GB
find / -type f -size +50M -size -1G
Limit a process’s CPU usage
sudo apt install -y cpulimit
ps aux | grep chrome
cpulimit -p <PID> -l 50
Find the process ID (PID) in the ps output, then limit it to 50% CPU.
Compare two directories or files
diff -rq /home/user/site1 /home/user/site1_backup
diff -c one.txt two.txt
Copy with a progress bar
rsync -rv /home/user/sites.zip /home/backup/sites.zip --progress
Sort files and folders by size
du -skh * | sort -hr
du -skh /var/log/* | sort -hr
Close the shell without saving history
kill -9 $$
To keep a single command out of the history instead, start it with a space (this works when HISTCONTROL includes ignorespace, the default on many distributions).
Delete all files except some
shopt -s extglob
rm -- !(5.txt)
rm -- !(5.txt|6.txt)
Deletes every file in the current directory except the ones listed. Check the directory carefully before running it.
Can't find the information you are looking for?