0

I'm trying to convert this command to something that does not use parallel.

find . -type f -iregex '.*.ts\|.*.js\|.*.tsx\|.*.jsx' | parallel 'touch {} -d "$(date -d \@$((0x$(md5sum {} | cut -b 1-7))))"'

What I came up with does not work

find . -type f -iregex '.*.ts\|.*.js\|.*.tsx\|.*.jsx' -print0 | xargs -0 md5sum | cut -b 1-7 | xargs -0 -I {} touch -d \@0x{}

What I'm trying to accomplish is to set the files mtime to its md5sum for caching purposes

4
  • (1) Please explain what you are trying to do. (Put your explanation in your question; we don’t like links.)  (2) What you’re trying doesn’t look very much like what you’re starting with. (3) For the purpose of asking a clear question, can you simplify your find command? Commented Apr 2, 2019 at 1:13
  • Which parallel are you using? GNU parallel, this one or another?
    – nxnev
    Commented Apr 2, 2019 at 1:25
  • GNU parallell...
    – Rob Jones
    Commented Apr 2, 2019 at 1:36
  • I made a simple script file=$1 md5=$(date -d \@$((0x$(md5sum $file | cut -b 1-7)))) touch $file -d $md5 and changed my command to find . -type f -iregex '.*.ts\|.*.js\|.*.tsx\|.*.jsx' -print0 | xargs -0 -L1 ./build/set-mtime-to-md5.sh but it is now making files that are equal to $md5
    – Rob Jones
    Commented Apr 2, 2019 at 2:15

2 Answers 2

1

You do not write the reason why you want to convert the script. Maybe you want the script not to depend on GNU Parallel.

If that is the case you might be interested in parallel --embed which will embed GNU Parallel in a shell script:

parallel --embed > newscript

Then edit the end of newscript.

You can then use newscript on machines that do not have GNU Parallel installed.

--embed has been available since version 20180322.

0

xargs is not so radically different from GNU parallel that you need to radically change the structure of the command.  This

find . <find_args> -print0 | xargs -0 -L 1 sh -c 'touch "$1" -d "$(date -d @$(( 0x$(md5sum "$1" | cut -b 1-7) )) )"' sh
works.

Moreover, on my system, you don’t need to use date -d; touch can also handle -d @number, so you can do

find . <find_args> -print0 | xargs -0 -L 1 sh -c 'touch "$1" -d "@$(( 0x$(md5sum "$1" | cut -b 1-7) ))"' sh

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .