Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using Dropbox, and I wind up with a number of files like:
prefs (home's conflicted copy 2009-07-20).js

What I would like to do is find all the "conflicted copy..." files and then compare each with its unconflicted version.

For example, the following command gives me the result:

$ find . -name "*onflict*" -exec ls -ld {} \;
-rw-r--r-- 1 eric eric 24203 2009-07-19 14:42 ./prefs (home's conflicted copy 2009-07-20).js

but I would like an output like:

-rw-r--r-- 1 eric eric 24429 2009-07-21 11:43 prefs.js
-rw-r--r-- 1 eric eric 24203 2009-07-19 14:42 prefs (home's conflicted copy 2009-07-20).js

and then I can decide what I want to do with the conflicted copy. Any ideas?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I figured out something that seems to works, but I would welcome suggestions to improve it, including making it cleaner:

find . -name "*onflict*" | while read name; do ls -ld "$name"; ls -ld "${name/ (*onflict*)/}"; echo -n "$name" | xargs -0 -p rm ; echo ; done

In a more easily read and typed format:

find . -name "*onflict*" | \
while read name; do 
    ls -ld "$name"
    ls -ld "${name/ (*onflict*)/}"
    echo -n "$name" | xargs -0 -p rm 
    echo 
done

References:

share|improve this answer

After you've matched the conflicted filename, use a regular expression to replace the parenthesis and space with a star and do, for example:

ls -d "prefs*.js"
share|improve this answer
    
BTW, the example ls -d "prefs*.js" is an example of shell filename expansion or shell pattern matching, functionality which is a subset of full regular expresions. –  pcapademic Jul 21 '09 at 23:22
    
But how do I apply regular expression to the {} in the find command -exec option? –  pcapademic Jul 21 '09 at 23:34
    
You might want to write a perl version of this instead, but I bet it could be written with just a single line using awk/sed, I'm just not proficient enough to describe it. –  Stefan Thyberg Jul 21 '09 at 23:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.