Speed up hard link creation in unix

402 views Asked by At

I have a work to make new hardlinks for 60000+ (30.3 GB) files with different names. The problem is, the directories, the old file names, and the new hard link names is stored in a CSV file. Right now, I am writing a script to do it automatically (parsing the csv, looping through records, and making the link). Below is the sneak peek from the script

while read col1 col2 col3 col4
do
        if [ $counter -ne 0 ];
        then
                if [ ! -f "$col2$col3.jpg" ]; then
                        # File not found, need to track how much is not found
                        echo "$col2$col3.jpg"
                        notfound=$(expr $notfound + 1)
                else
                        if [ $(expr $hash / 10) -eq 1 ]; then
                                hash=$(expr $hash - 10)
                        fi

                        ln "$col2$col3.jpg" ./testtemp-1/$hash/$col4.jpg
                        hash=$(expr $hash + 1)
                fi
        else
                counter=$(expr $counter + 1)
        fi
done < test.csv

It takes around 15 minutes to complete this thing. May I know if there is any idea to shorten the time? It is quite time sensitive task which will be done in the production (right now it is on testing).

PS: I need the hashing so it can't be deleted. Not found is also required. $col2 -> directory name, $col3 -> file name, $col4 -> new hard link name

1

There are 1 answers

0
Reynaldi Wijaya On

I managed to cut down the time to a very reasonable one (2 mins) by changing the expr and skipping the first line check logic. Thanks for the comments :)