LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 11-16-2012, 05:14 AM   #1
chinabenjamin66
Member
 
Registered: Mar 2012
Location: Shenzhen Chian
Posts: 73

Rep: Reputation: Disabled
How to find all files in folder and calculate md5 and redirect to a file in one CLI


Hello friends,


Can anyone teach me how to find all files in a folder and calculate md5 hashes and redirect to a file in one command line?

Any idea will be appreciated.
 
Old 11-16-2012, 05:20 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Have a look at this:
Code:
find /path/to/files -type f -exec md5sum {} >> /path/to/outfile \;
This recursively looks for files (-type f) in /pat/to/files, creates the md5sums and stores the results in /path/to/outfile.
 
Old 11-16-2012, 05:20 AM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

how about
Code:
md5sum /path/to/a/folder/* > md5sums.txt

Evo2.
 
1 members found this post helpful.
Old 11-16-2012, 05:21 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Do you mean you want to get the checksum of ALL the files inside a directory? Or do you have to specify some criteria to select some specific files? In the first case:
Code:
find /path/to/dir -maxdepth 1 -type f -exec md5sum {} \+ > all.md5
should do the trick.

Edit: too late! evo2's solution is more straightforward, anyway.

Last edited by colucix; 11-16-2012 at 05:23 AM.
 
Old 11-16-2012, 05:36 AM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Ohh, for completeness, the shell glob version for all files in subdirectories (or folders in OP speak)
Code:
md5sum /path/to/a/folder/**/*(^/) > md5sums.txt
Assuming of course the OP uses zsh. No need for find if you use a decent shell ;-)

Evo2.

Last edited by evo2; 11-16-2012 at 05:39 AM. Reason: Typo!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Using terminal command -Find files in a folder and copy them to a different folder j-jock Linux - General 4 11-28-2011 03:20 AM
Find folders with ONLY one specific file in and delete file and folder - How ? gedi1 Linux - Newbie 5 10-21-2009 09:09 PM
how do i md5 hash all files in a sub-folder and save it as a file? steve51184 Linux - Software 2 09-14-2009 07:38 PM
Redirect a folder to another so I can access files yersin Linux - Newbie 3 03-31-2008 12:31 AM
How to verify downloaded files with MD5 file? ICO Linux - General 3 03-16-2004 12:28 AM


All times are GMT -5. The time now is 06:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration