[SOLVED] Need to output md5 or sha1 along with fullpath and filesize
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
also, performance is an issue for me, since i need to get the info out of 10m files (approx 6TB), so commands like find are preferred and less iterations among commands would be great too.
Well, first of all, you're right about the system function. It returns the exit value of the command, not the command itself.
But I also see a couple of other errors. First of all, take a look at the output of the find command. You need to specify newlines with printf. And the END section only prints the final values, not once for each line.
In any case, I don't see any easy one-liner way to accomplish what you want. But a simple loop can do the trick.
Code:
while read x; do
size=${x% *}
file=${x#* }
sum="$(md5sum $file 2>/dev/null)"
sum=${sum%% *} #strip off filename to get sum only*
echo "$sum $file $size"
done <<<"$(find . -type f -printf "%s %p\n")"
*Note that the output of md5sum shows the sum, then the filename separated by two spaces. As you seem to want only a single space between each part, I've removed the filename, then printed it separately again on the final line. This step could be removed if you don't mind the extra spaces.
Edit: Hah...tinkster got here first. But I've now added a link too.
Last edited by David the H.; 08-26-2010 at 11:57 PM.
@grail thanks for looking at these:
1. for the first post you probably need to create the md5.sh following Thinkster info at the start of the thread.
2. with the script in your second post i've got
Quote:
$ ./script.sh
./script.sh: line 7: syntax error near unexpected token `done'
./script.sh: line 7: `done << (find -type f -printf '%s %p\n')'
btw i've tried with both "done< <" and "done <<" but no luck...
note i'm using cygwin to run these commands/scripts and i've read on a few blogs that read in cygwin bash does not behave as in ksh, that's probably why i'm stuck...
any other ideas?
Last edited by hanker; 08-27-2010 at 10:12 AM.
Reason: correction
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.