X
X
Select Your Currency
₺ Turkish lira $ US Dollar
Skip to content
New Affiliate program: refer customers, earn 20%

ViHyper

Life-Saving Linux Commands for Servers

  • Secure checkout
  • Company invoice
  • Technical support
CentOS 7 1 min read 1633 views

This guide has 13 sections. Use the “Copy” button on code blocks to copy commands.

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.

Affiliate ProgramFound this useful? Share it and earn.Get 20% commission on orders from customers you refer. Joining is free.Details
Turkey location VDS/VPSCompare Turkey-based virtual servers with SSD.
Plans from $2.56

Can't find the information you are looking for?

Create a Support Ticket

Did you find it useful?

(1633 times viewed / 4 people found it helpful)

Categories


Top