script function or simple commands??/

I know that this sort of thing should be second nature by now but I can rarely if ever get anything in bash to do what I want, or even understand how to tell it what I want…

I guess I am just very stupid…

For instance I have my music in a directory called /xxx/music, in it are folders usually by artist.
inside it is a sub-dir also called music so: /xxx/music/music
In this sub-dir is mostly duplicates of stuff in the parent.
I want to check that the files in the sub-dir are in the parent, if so delete them from sub-dir, and if not, move them to the parent, and then delete them, objective being that /xxx/music/music becomes empty with all of its erstwhile contents safely in /xxx/music

This I know should be simple pimple stuff… prolly just using cp…
BUT I can’t get a grip on it, rsync? diff? dircmp? I have tried these but not sure how to tune them…
Rsync as below did not give any clear output:
(These are dummy test dirs, with some music in them)

870 rsync -vrpni --progress music2 music1
871 rsync -vrpn --progress music2 music1
872 rsync -vrp --progress music2 music1
873 rsync -vr --progress music2 music1
874 rsync -avrpni --progress music2 music1

an IRC’er gave me this function:

dupesfind is a function
dupesfind ()
    find -not -empty -type f -printf "%s
" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all --repeated

But I tried it on a dummy pair of dirs in /tmp, and got no results
I tried the find command on its own, with its series of pipes no result there either…

Need more info.

Single level subdirectory?

Single level parent, except for the subdir?

How do you define duplicate? Same name and contents?

What do you do with name clashes, i.e. same name, but contents different?

If those are the constraints, then a script to loop through the files in the subdir, comparing with the file of the same name in the directory above would do the job.

cd parent/subdir
for f in *
  if test ! -e ../"$f"
    mv "$f" ..
    if cmp "$f" ../"$f"
      rm -f "$f"
      # what do you want to do with clashes?

If you have multiple levels of subdir, it’s mostly the same except that you need to generate a list of files to test to feed to the loop.

Also you could probably do it with rsync, but you should simplify matters first by moving the subdir outside the parent’s tree. In fact that would also simplify matters for this shell loop.

ken yap wrote:
> Need more info.

this is not a help forum…

there are no questions in the post, only in the title…

he must just be telling a story, writing a book or something very
interesting–but not asking for help…

When it comes to chocolate, resistance is futile.
CAVEAT: [posted via NNTP w/openSUSE 10.3]

Didn’t notice that. So whip the OP, not me, and move the thread.

I select posts to read from a new post search, that’s why I don’t usually notice the forum.

Thanks for the advice, Ken.
And thanks for the “helpful” intervention, Denver.
Did it really cause you so much pain seeing my post here?
If so, don’t read it. You could certainly have saved yourself some valuable time by simply not replying to it.
Which of the fora would you have deemed appropriate?

  1. Install/Boot/Login
  2. Applications
  3. Multimedia
  4. Games
  5. Hardware
  6. Laptop
  7. 64-bit
  8. Network/Internet
  9. Wireless
  10. Pre-Release/Beta
  11. Looking For Something Other Than Support?

I deliberately did not post in the programming/scripting section, as it is under “development”
The title of the thread explains what it is about. I posted here as I thought others might share their frustrations, and share some pointers, as Ken has kindly done.

noken yap wrote:
> So whip the OP, not me, and move the thread.

not whipping and can’t move myself, much less threads.

CAVEAT: [posted via NNTP w/openSUSE 10.3]

wakou wrote:
> And thanks for the “helpful” intervention, Denver.
> Did it really cause you so much pain seeing my post here?

no pain, it is just the question and good nuggets of info will not be
found by many of the helpful folks who avoid this non-help forum…nor
will they be found in the logical places to look (bash and terminals
are an application and scripting has its own forum)…

really, i don’t care where you post or get answered…i’m thinking
about all the other folks who might want to know the same answer and
may never look in chit-chat for it…

> I deliberately did not post in the programming/scripting section, as it
> is under “development”

but, you are wanting to make, design, craft, create or develop a
script or program to check file locations and move/delete
them…so, what better place than “Programming/Scripting - Questions
about programming, bash scripts, perl, php, cron jobs, ruby, python, etc”?

CAVEAT: [posted via NNTP w/openSUSE 10.3]

DenverD makes an excellent point about appropriate forum postings.

Personally I think a solution would be diff to start or move /xxx/music/music /xxx/music_dupls then do a diff /xxx/music /xxx/music_dupls
You can fine tune the diff command options

Or you could sort and compare ls /xxx/music | sort > file ls /xxx/music/music | sort > file2 and diff file file2 that way you compare on names only.