Operations 11 min read

Boost Ops Efficiency: Fast File Deletion, iSCSI Detection, and Linux User Management Tricks

This article shares practical Linux and Vsphere techniques—including using rsync for rapid bulk deletions, detecting new iSCSI disks without reboot, safeguarding rm commands, mounting remote filesystems with SSHFS, and adding users to supplementary groups via gpasswd—to streamline daily operations.

Efficient Ops
Efficient Ops
Efficient Ops
Boost Ops Efficiency: Fast File Deletion, iSCSI Detection, and Linux User Management Tricks

Requirements

During operations we often encounter scenarios such as quickly deleting massive files, detecting newly added iSCSI disks in Vsphere without reboot, preventing accidental rm deletions, fast mounting between Linux servers, and adding users to supplementary groups.

Linux: How to quickly delete a large number of files?

Vsphere: How to recognize newly added iSCSI disks without restarting?

Linux: How to make rm safe from accidental deletion?

How to quickly mount between different Linux servers?

How to add a user to supplementary groups efficiently?

1. How to quickly delete massive files on Linux?

Using

rm

on many small files is slow and may leave disk space unreleased. Replace

rm

with

rsync

, which creates an empty directory and swaps it with the target, avoiding extensive traversal.

Relevant rsync delete 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>

Fast directory deletion

<code>1. mkdir -p /del_tmp
2. /del_dest   # target directory
3. rsync --delete-before -a -H -v --progress --stats ./del_tmp/ ./del_dest/
# options explanation:
--delete-before  delete before transfer
--progress       show progress
-a               archive mode (recursive, preserve attributes)
-H               preserve hard links
-v               verbose output
--stats          display transfer statistics
</code>

Fast file deletion

Note: When SRC and DEST types differ, errors occur; when both are files, the file content is cleared instead of deletion; when both are directories, all files are removed leaving an empty directory.

2. How to detect newly added iSCSI disks in Vsphere without reboot?

Two methods are available.

Method 1

<code>echo 'scsi add-single-device 2 0 1 0' > /proc/scsi/scsi</code>

Parameters:

HOST – host adapter identifier (0 for first, 2 for the new disk).

Channel – SCSI channel on the host adapter (00 for both).

ID – SCSI device identifier, starting from 00; the new disk is 01.

Method 2

<code># Refresh SCSI; repeat for each host.
# If the system has 3 scsi hosts, run three times:
echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scan
</code>

Both methods allow the system to recognize newly added disks without a reboot; choose based on your environment.

3. How to make rm safe from accidental deletion?

Leverage Bash parameter expansion to provide a safe default path.

<code># Unsafe example (may delete root if $dest is empty)
rm -rf ${dest:-test}
# Improved safe version
rm -rf /${dest:-test}
</code>

4. How to quickly mount between different Linux servers?

Instead of NFS, use SSHFS for fast, secure mounting over SSH.

<code># Install SSHFS
yum install sshfs

# Create mount point
mkdir /mnt/data

# Mount remote filesystem
sshfs [email protected]:/home/test/ /mnt/data

# With key authentication
sshfs -o IdentityFile=~/.ssh/id_rsa [email protected]:/home/test/ /mnt/data
</code>

SSHFS provides a convenient alternative to NFS.

5. How to add a user to supplementary groups quickly?

Using

usermod

overwrites existing groups.

gpasswd

can add a user to a group without needing to know current memberships.

<code># Add test1 to test2 group
gpasswd -a test1 test2

# Add test1 to test3 group
gpasswd -a test1 test3
</code>

Summary

Regular operations can solve most issues, but efficiency and convenience improve by using tools such as rsync for bulk deletions, SSHFS for rapid mounts, and gpasswd for group management, along with the demonstrated commands for iSCSI detection and safe rm usage.

operationsLinuxrsynciSCSIVsphereSSHFS
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

login 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.