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
rmto delete many small files or large files can be slow and may leave disk space unreleased because each entry is unlinked individually. Replacing
rmwith
rsyncimproves performance by creating an empty directory and syncing it over the target, avoiding extensive traversal.
Key
rsyncdelete options:
<code>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 files
</code>Typical fast‑delete command:
<code>mkdir -p /del_tmp
rsync --delete-before -a -H -v --progress --stats ./del_tmp/ ./del_dest/</code>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:
<code>echo 'scsi add-single-device 2 0 1 0' > /proc/scsi/scsi</code>Parameters: HOST=2 (adapter), Channel=0, ID=1 (new disk).
Method 2 – trigger a SCSI bus scan for each host:
<code># 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/scan</code>Either 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
rmcommands.
<code># Dangerous example (may delete root if $dest is empty)
rm -rf ${dest:-test}
# Safer version
rm -rf /${dest:-test}</code>4. Fast Mount Between Linux Servers
While NFS is common for sharing directories,
sshfsprovides a quick, SSH‑based alternative.
<code># 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/data</code>This approach is simple and works well for ad‑hoc data sharing.
5. Quickly Add Users to Supplementary Groups
Using
usermod -Goverwrites existing groups. The
gpasswdcommand can add a user to an additional group without needing to know the current group list.
<code># Add test1 to test2 group
gpasswd -a test1 test2
# Add test1 to test3 group
gpasswd -a test1 test3</code>Summary
By applying these straightforward Linux and vSphere techniques—rsync for bulk deletion, SCSI rescanning for iSCSI disks, safe
rmpatterns, SSHFS for rapid mounts, and
gpasswdfor group management—operations teams can improve efficiency and reduce manual overhead.
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.