Accelerate Linux Ops: Fast Deletion, iSCSI Detection & Quick Group Management
This guide presents practical Linux and vSphere techniques—including using rsync for rapid bulk file deletion, detecting newly added iSCSI disks without reboot, safeguarding rm commands, mounting remote filesystems with SSHFS, and quickly adding users to supplementary groups via gpasswd—to boost operational efficiency.
1. Fast Deletion of Large Number of Files in Linux
Using rm to delete many small files or large files can be slow and may leave disk space unreleased because each entry is unlinked individually. Replacing rm with rsync improves performance by creating an empty directory and syncing it over the target, avoiding extensive traversal.
Key rsync delete options:
rsync --help | grep delete
--del an alias for --delete-during
--delete delete files that don't exist on the sending side
--delete-before receiver deletes before transfer (default)
--delete-during receiver deletes during transfer, not before
--delete-after receiver deletes after transfer, not before
--delete-excluded also delete excluded files on the receiving side
--ignore-errors delete even if there are I/O errors
--max-delete=NUM don't delete more than NUM filesTypical fast‑delete command:
mkdir -p /del_tmp
rsync --delete-before -a -H -v --progress --stats ./del_tmp/ ./del_dest/2. Detect New iSCSI Disk in vSphere Without Reboot
When a new iSCSI disk is added to a VM, the filesystem can be refreshed without reboot using either of two methods.
Method 1 – add the device via the SCSI host interface:
echo 'scsi add-single-device 2 0 1 0' > /proc/scsi/scsiParameters: HOST=2 (adapter), Channel=0, ID=1 (new disk).
Method 2 – trigger a SCSI bus scan for each host:
# Refresh SCSI; repeat for each host
echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scanEither method makes the new disk visible without restarting the VM.
3. Prevent Accidental Deletion with rm
The colon ( :) in Bash is a built‑in command that can be used for parameter expansion. By leveraging the `${parameter:-default}` syntax, you can avoid dangerous empty variables in rm commands.
# Dangerous example (may delete root if $dest is empty)
rm -rf ${dest:-test}
# Safer version
rm -rf /${dest:-test}4. Fast Mount Between Linux Servers
While NFS is common for sharing directories, sshfs provides a quick, SSH‑based alternative.
# Install SSHFS
yum install sshfs
# Create mount point
mkdir /mnt/data
# Mount remote directory
sshfs [email protected]:/home/test/ /mnt/data
# Use key‑based authentication (optional)
sshfs -o IdentityFile=~/.ssh/id_rsa [email protected]:/home/test/ /mnt/dataThis approach is simple and works well for ad‑hoc data sharing.
5. Quickly Add Users to Supplementary Groups
Using usermod -G overwrites existing groups. The gpasswd command can add a user to an additional group without needing to know the current group list.
# Add test1 to test2 group
gpasswd -a test1 test2
# Add test1 to test3 group
gpasswd -a test1 test3Summary
By applying these straightforward Linux and vSphere techniques—rsync for bulk deletion, SCSI rescanning for iSCSI disks, safe rm patterns, SSHFS for rapid mounts, and gpasswd for group management—operations teams can improve efficiency and reduce manual overhead.
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.
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.
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.
