Speed Up Linux Ops: Fast Bulk Deletion, Safe rm, Disk Refresh & User Group Tricks
This article shares practical Linux administration techniques, including using rsync to delete massive files quickly, employing Bash parameter expansion to protect rm from accidental root deletion, adding iSCSI disks in vSphere without reboot, mounting remote filesystems with sshfs, and managing supplementary groups efficiently with gpasswd.
1. Fast Deleting Large Files on Linux
Using rm to delete many small files or large directories is slow and may leave disk space unreleased because each entry is unlinked individually. Replacing rm with rsync dramatically speeds up the operation by swapping the target directory with an empty one.
mkdir -p /del_tmp # create an empty directory
# target directory to clear
/del_dest
rsync --delete-before -a -H -v --progress --stats ./del_tmp/ ./del_dest/ --delete-before: delete destination files before transfer -a: archive mode (recursive, preserve attributes) -H: preserve hard links -v: verbose output --progress: show progress --stats: display transfer statistics
2. Detect New iSCSI Disk in vSphere Without Reboot
When a new iSCSI LUN is attached to a VM, the guest OS normally requires a reboot to rescan the SCSI bus. Two command‑line methods avoid downtime.
Method 1 – Add the device via /proc/scsi/scsi
echo 'scsi add-single-device 2 0 1 0' > /proc/scsi/scsiParameters:
HOST : adapter number (2 in this example)
Channel : SCSI channel (0)
ID : target ID (1)
LUN : LUN number (0)
Method 2 – Rescan SCSI hosts
# Refresh each SCSI host (adjust count to your system)
for i in 0 1 2; do echo "- - -" > /sys/class/scsi_host/host${i}/scan; doneBoth methods make the new disk visible without restarting the VM.
3. Making rm Safer with Bash Parameter Expansion
The Bash colon builtin can be used to provide a default value when a variable is empty, preventing accidental deletion of the root directory.
# Dangerous example (dest empty → rm -rf /)
rm -rf ${dest:-test}
# Safe version – defaults to a harmless directory
rm -rf /${dest:-test}If dest is unset or empty, the command expands to rm -rf /test, avoiding a catastrophic rm -rf /.
4. Quick Mounting Between Linux Servers
Instead of setting up NFS, sshfs can mount a remote filesystem over SSH in a few commands.
# Install sshfs
yum install sshfs
# Create a local mount point
mkdir /mnt/data
# Mount remote directory
sshfs user@host:/home/user/ /mnt/data
# If SSH keys are configured, use the key explicitly
sshfs -o IdentityFile=~/.ssh/id_rsa user@host:/home/user/ /mnt/dataThis approach is fast, requires no server‑side configuration, and works well for temporary data sharing.
5. Adding Users to Supplementary Groups Efficiently
Using usermod -G overwrites existing group memberships. The gpasswd utility adds a user to a group without affecting other groups.
# Add test1 to test2
gpasswd -a test1 test2
# Add test1 to test3
gpasswd -a test1 test3After each command, id test1 shows the cumulative group list, eliminating the need to know the current groups beforehand.
Conclusion
By applying these straightforward commands—rsync for bulk deletion, SCSI rescanning for disk detection, Bash parameter expansion for safe rm, sshfs for rapid mounts, and gpasswd for group management—Linux system administrators can solve common operational problems more efficiently and with less risk.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
dbaplus Community
Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
