![]() |
|
|||||||
| FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below. |
![]() |
|
|
Thread Tools | Display Modes |
|
|||
|
Hi all,
I am trying to do the following: I want to have a list of all files in a directory and its subdirectories with a md5 hash in its first column. This is to get a list off all mp3s which I have double. I though to use find /musiclocation -printf %f or something similar (which does not show the path) But it seems that the command syntax is different. Is there another way I can accomplish this? or is it possible to install a port that has the linux find command? Maybe someone knows another approach to this. Thanks in advance. |
|
||||
|
Perhaps this will be sufficient?
Code:
$ mkdir test
$ cd test
$ touch a b c
$ find . -type f -exec md5 {} > /tmp/results \;
$ cat /tmp/results
MD5 (./a) = d41d8cd98f00b204e9800998ecf8427e
MD5 (./b) = d41d8cd98f00b204e9800998ecf8427e
MD5 (./c) = d41d8cd98f00b204e9800998ecf8427e
$
__________________
OpenBSD LiveCDs/LiveDVDs |
|
|||
|
Quote:
Thanks for your time though. |
|
||||
|
Because that particular find(1) command used a relative directory: "find .".
If you need a full path, use find with /path/to/your/files instead. If you don't want any path information, run the output through awk or perl or python and remove it.
__________________
OpenBSD LiveCDs/LiveDVDs |
|
||||
|
@deadeyes
Code:
~ % cat find.sh
#! /bin/sh
find ${1} -type f \
| while read LINE
do
MD5=$( md5 -q ${LINE} )
FILE=$( basename ${LINE} )
echo "${MD5} ${FILE}"
done
~ % ./find.sh misc/sys/FreeBSD/
3d3991e7f828003c3abe0c7f1e48011a loader.conf
66ac143dc9e53b22df4fd77ae6fa01fa make.conf
01963f0ccdd17822c5ee210bba5df10f xorg.conf
085616e4fc95e7af3771deceab5171c3 sysctl.conf
(...)
~ %
__________________
religions, worst damnation of mankind "If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”. vermaden's: links resources deviantart spreadbsd |
|
|||
|
Quote:
So scripting is not necessary. Python, Perl does make more dependencies. vermaden: nice piece of shell script (and purely bash ) didn't know the command basename ![]() Thanks for your efforts guys! |
|
|||
|
No.. it's purely bourne-compatible.
|
|
||||
|
Quote:
Code:
# pkg_add -r findutils Fetching ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-7.2-release/Latest/findutils.tbz... Done. ~ % pkg_info -L -x findutils | grep bin /usr/local/bin/gfind /usr/local/bin/goldfind /usr/local/bin/glocate /usr/local/bin/gupdatedb /usr/local/bin/gxargs ~ % rehash ~ % gfind --version find (GNU findutils) 4.4.0 Copyright (C) 2007 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Eric B. Decker, James Youngman, and Kevin Dalley. Built using GNU gnulib version e5573b1bad88bfabcda181b9e0125fb0c52b7d3b Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS() CBO(level=0) ~ %
__________________
religions, worst damnation of mankind "If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”. vermaden's: links resources deviantart spreadbsd |
|
||||
|
But if you have spaces in names of songs that may disturb the regex, so maybe this is better:
Code:
find.awk:
a[$4]++ {
regex="\\/[^\\/]*\\)"
if(match($2, regex)) {
pattern=substr($2, RSTART+1, RLENGTH-2);
printf("%s\t%s\n", $4, pattern);
}
}
__________________
The best way to learn UNIX is to play with it, and the harder you play, the more you learn. If you play hard enough, you'll break something for sure, and having to fix a badly broken system is arguably the fastest way of all to learn. -Michael Lucas, AbsoluteBSD |
|
||||
|
If you just want to check and see if you have exact duplicate files, I would suggest using something like sysutils/duff. It is very fast, easy to use, and written entirely in C with no other dependencies.
|
|
|||
|
I knew there were some tools already for doing this but I wanted to write a script myself (as an exercise)
Thanks for you help guys. Eventually the basename command would do the trick but I kept it out of the script as it would not very usefull if you don't really know where those duplicate files are. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to get port's building options? | Sunsawe | FreeBSD Ports and Packages | 14 | 9th May 2009 06:35 PM |
| portupgrade -af, how to submit fetch options? | bsdfan | FreeBSD Ports and Packages | 4 | 28th December 2008 08:05 PM |
| Command to find and replace, but not creating a new file | 18Googol2 | Programming | 4 | 22nd September 2008 10:28 PM |
| Change Makefile options in ports | shep | FreeBSD Ports and Packages | 5 | 18th August 2008 07:58 AM |
| Buildworld make.conf options | siffland | FreeBSD Installation and Upgrading | 4 | 12th May 2008 12:02 AM |