|
FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below. |
|
Thread Tools | Display Modes |
|
|||
Find command (Linux options?)
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. |
|
|||
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. |
|
||||
@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 |
|
||||
Hm, I don't know what's wrong with suggestion jggimy made? Because the name doesn't come before the hash? Then just:
Code:
$ find . -type f -exec md5 {} + | awk '{ print $4, $2 }' Also, using awk you could filter the duplicates, using something like this: Code:
$ find . -type f -exec md5 {} + | awk -f find.awk find.awk: a[$4]++ { if(match($2, /[^\/]*\)/)) { pattern=substr($2, RSTART, RLENGTH-1); 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 Last edited by s0xxx; 30th July 2009 at 01:51 PM. |
|
||||
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 |
|
|||
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. |
|
|
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 09: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 |