0

I'm looking to store the hash of my most recently downloaded file in my downloads folder as a variable.

So far, this is what I have:

md5sum $(ls -t | head -n1) | awk '{print $1}'

Output:

user@ci-lux-soryan:~/Downloads$ md5sum $(ls -t | head -n1) | awk '{print $1}'
c1924742187128cc9cb2ec04ecbd1ca6

I have tried storing it as a variable like so, but it doesn't work:

VTHash=$(md5sum $(ls -t | head -n1) | awk '{print $1}')

Any ideas, where am I going wrong

vlumi
  • 1,321
  • 1
  • 9
  • 18

1 Answers1

0

As @Cyrus outlined parsing ls has its own pitfalls and therefore better to avoid it altogether rather than allowing unexpected corner cases. The following shall facilitate the requirements epitomised.

VTHash="$(find -type f -mtime 0 | tail -n 1 | xargs md5sum | awk '{ print $1 }')"
Ashen Gunaratne
  • 435
  • 3
  • 9