Operations 8 min read

Essential Safety Checklist for Dangerous Linux Commands

This guide outlines critical precautions and best‑practice tips for executing risky Linux commands—such as rm, chmod, cat, dd, tar, and MySQL—by verifying environments, backing up data, using safe aliases, and avoiding common pitfalls that can cause catastrophic data loss.

Efficient Ops
Efficient Ops
Efficient Ops
Essential Safety Checklist for Dangerous Linux Commands

1. Preparation

Before executing dangerous commands, take a deep breath and verify the target server using ifconfig or ip addr, then confirm the working directory with pwd.

$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:16:3e:34:e9:a9 brd ff:ff:ff:ff:ff:ff
    inet 172.19.26.39/20 brd 172.19.31.255 scope global dynamic noprefixroute eth0
    inet6 fe80::216:3eff:fe34:e9a9/64 scope link
$ pwd
/etc/nginx

2. rm -rf

The -rf option recursively deletes files; a missing space or an unintended / can wipe entire systems. Examples:

rm -rf ./* => rm -rf /
rm -rf abc/ => rm -rf abc /

When scripting, always check variables before using rm, e.g., avoid rm -rf ${p}/* which becomes rm -rf / if ${p} is empty.

3. chmod

Changing permissions carelessly can be as destructive as rm. Backup permissions with getfacl -R / > chmod.txt and restore using setfacl --restore=chmod.txt.

4. cat

Using redirection incorrectly (e.g., cat >> file missing a >) can erase file contents. The same risk applies to echo and other redirection operators.

5. dd

The dd if=/dev/zero of=/dev/sda bs=512 count=1 command formats a disk; accidental execution will destroy data.

6. cp

Enable interactive mode with alias cp='cp -i' to prompt before overwriting files; the same applies to mv.

7. tar

Extracting with tar -xf can overwrite existing files in the current directory, leading to data loss.

8. vim

Opening large files in vim may trigger the OOM killer. Use read‑only mode ( view) or safer tools like less or more.

9. mkfs.*

Commands such as mkfs.ext4 format disks and should never be run on production systems.

10. MySQL

Use mysql -U (or --safe-updates) to prevent UPDATE/DELETE without a WHERE clause, set an alias, wrap critical operations in transactions, and prefer inplace for DDL to reduce locking.

Online environments are priceless; proceed with caution, prioritize stability over speed, and remember that thorough approvals often take days—saving a few seconds is not worth a disaster.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

OperationsLinuxSafetyBackupcommand-linermchmod
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.