Mass Deleting With split and map

# First off - this is how I got into the mess in the first place.

# Step 1: make a really big random file:
head -c $(( 1024 * 1024 * 1024 )) /dev/urandom > $(mktemp '/DataSwap/big.XXXXXXXX')

# Step 2: Screw up and split it into a million (actually 1024*1024)
# separate 1024byte files.
split -b 1024 /DataSwap/big.KFGgJs8S '/DataSwap/parts'

# Trying to delete them normally just fails because the command line is two long.

# This seems to be about as fast as I can get, using a whole
# bunch of parallel deleters.

# First make separate files of 1000 entries to remove and put in shared
# memory for speed (linuxisum).
ls | split - '/dev/shm/lses' 

# Now make a function which can read a block and delete all
# the files listed.
function rm_block { for f in $(cat $1); do rm "/DataSwap/$f"; done; }

# A wrapper to easily put that in the background.
function rm_block_bg { rm_block $1 & }

# Now kick off the delete:
ls /dev/shm/ls* | map rm_block_bg

# Go make a cup of tea whilst the linux kernel schedules
# up the work for you...

Comments

Popular posts from this blog

oche, lik echo but a bit easier to use.

Bithon: Run Python Interactively Inside Bash

Parsing Columns From Files WITHOUT awk