problem with duplicates [closed]












-1















Good morning,
I need help with writing a script or command which I can give to crontab (I'm only interested in a terminal without gui).
I want the command to find files with the same name in directories
/ Home / user / dir1 / *
/ Home / user / dir2 / *
The files located in / dir2 / * are to be removed.
Files found in / dir1 / * must be.
Can anyone help me?










share|improve this question













closed as unclear what you're asking by Pilot6, user68186, Eric Carvalho, Parto, Thomas Mar 16 at 10:03


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 1





    We don't solve school tasks here.

    – Pilot6
    Mar 15 at 12:30











  • This is not a school task, it's for my personal development ...

    – Starter
    Mar 15 at 12:31











  • What have you tried? This really reads like an intro unix programming quesiton, or it is of the from xyproblem.info . Try telling us why you want to do this?

    – j-money
    Mar 15 at 13:26
















-1















Good morning,
I need help with writing a script or command which I can give to crontab (I'm only interested in a terminal without gui).
I want the command to find files with the same name in directories
/ Home / user / dir1 / *
/ Home / user / dir2 / *
The files located in / dir2 / * are to be removed.
Files found in / dir1 / * must be.
Can anyone help me?










share|improve this question













closed as unclear what you're asking by Pilot6, user68186, Eric Carvalho, Parto, Thomas Mar 16 at 10:03


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 1





    We don't solve school tasks here.

    – Pilot6
    Mar 15 at 12:30











  • This is not a school task, it's for my personal development ...

    – Starter
    Mar 15 at 12:31











  • What have you tried? This really reads like an intro unix programming quesiton, or it is of the from xyproblem.info . Try telling us why you want to do this?

    – j-money
    Mar 15 at 13:26














-1












-1








-1








Good morning,
I need help with writing a script or command which I can give to crontab (I'm only interested in a terminal without gui).
I want the command to find files with the same name in directories
/ Home / user / dir1 / *
/ Home / user / dir2 / *
The files located in / dir2 / * are to be removed.
Files found in / dir1 / * must be.
Can anyone help me?










share|improve this question














Good morning,
I need help with writing a script or command which I can give to crontab (I'm only interested in a terminal without gui).
I want the command to find files with the same name in directories
/ Home / user / dir1 / *
/ Home / user / dir2 / *
The files located in / dir2 / * are to be removed.
Files found in / dir1 / * must be.
Can anyone help me?







duplicate






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 15 at 12:26









StarterStarter

4




4




closed as unclear what you're asking by Pilot6, user68186, Eric Carvalho, Parto, Thomas Mar 16 at 10:03


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by Pilot6, user68186, Eric Carvalho, Parto, Thomas Mar 16 at 10:03


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1





    We don't solve school tasks here.

    – Pilot6
    Mar 15 at 12:30











  • This is not a school task, it's for my personal development ...

    – Starter
    Mar 15 at 12:31











  • What have you tried? This really reads like an intro unix programming quesiton, or it is of the from xyproblem.info . Try telling us why you want to do this?

    – j-money
    Mar 15 at 13:26














  • 1





    We don't solve school tasks here.

    – Pilot6
    Mar 15 at 12:30











  • This is not a school task, it's for my personal development ...

    – Starter
    Mar 15 at 12:31











  • What have you tried? This really reads like an intro unix programming quesiton, or it is of the from xyproblem.info . Try telling us why you want to do this?

    – j-money
    Mar 15 at 13:26








1




1





We don't solve school tasks here.

– Pilot6
Mar 15 at 12:30





We don't solve school tasks here.

– Pilot6
Mar 15 at 12:30













This is not a school task, it's for my personal development ...

– Starter
Mar 15 at 12:31





This is not a school task, it's for my personal development ...

– Starter
Mar 15 at 12:31













What have you tried? This really reads like an intro unix programming quesiton, or it is of the from xyproblem.info . Try telling us why you want to do this?

– j-money
Mar 15 at 13:26





What have you tried? This really reads like an intro unix programming quesiton, or it is of the from xyproblem.info . Try telling us why you want to do this?

– j-money
Mar 15 at 13:26










1 Answer
1






active

oldest

votes


















0














HANDLE WITH CARE as files are removed by this script!



The following script finds all regular files in both directories and sorts them. The comm -12 command finds all common lines in both results. Finally those files are removed in the second directory, as well as the used temporary files.



This works as long as there aren't weird filenames (e.g. containing spaces or other special characters).



#!/bin/bash
cd /home/user/dir1
find . -type f | sort > /tmp/find1
cd /home/user/dir2
find . -type f | sort > /tmp/find2
for i in $(comm -12 /tmp/find1 /tmp/find2)
do
rm $i
done
rm /tmp/find1 /tmp/find2





share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    HANDLE WITH CARE as files are removed by this script!



    The following script finds all regular files in both directories and sorts them. The comm -12 command finds all common lines in both results. Finally those files are removed in the second directory, as well as the used temporary files.



    This works as long as there aren't weird filenames (e.g. containing spaces or other special characters).



    #!/bin/bash
    cd /home/user/dir1
    find . -type f | sort > /tmp/find1
    cd /home/user/dir2
    find . -type f | sort > /tmp/find2
    for i in $(comm -12 /tmp/find1 /tmp/find2)
    do
    rm $i
    done
    rm /tmp/find1 /tmp/find2





    share|improve this answer




























      0














      HANDLE WITH CARE as files are removed by this script!



      The following script finds all regular files in both directories and sorts them. The comm -12 command finds all common lines in both results. Finally those files are removed in the second directory, as well as the used temporary files.



      This works as long as there aren't weird filenames (e.g. containing spaces or other special characters).



      #!/bin/bash
      cd /home/user/dir1
      find . -type f | sort > /tmp/find1
      cd /home/user/dir2
      find . -type f | sort > /tmp/find2
      for i in $(comm -12 /tmp/find1 /tmp/find2)
      do
      rm $i
      done
      rm /tmp/find1 /tmp/find2





      share|improve this answer


























        0












        0








        0







        HANDLE WITH CARE as files are removed by this script!



        The following script finds all regular files in both directories and sorts them. The comm -12 command finds all common lines in both results. Finally those files are removed in the second directory, as well as the used temporary files.



        This works as long as there aren't weird filenames (e.g. containing spaces or other special characters).



        #!/bin/bash
        cd /home/user/dir1
        find . -type f | sort > /tmp/find1
        cd /home/user/dir2
        find . -type f | sort > /tmp/find2
        for i in $(comm -12 /tmp/find1 /tmp/find2)
        do
        rm $i
        done
        rm /tmp/find1 /tmp/find2





        share|improve this answer













        HANDLE WITH CARE as files are removed by this script!



        The following script finds all regular files in both directories and sorts them. The comm -12 command finds all common lines in both results. Finally those files are removed in the second directory, as well as the used temporary files.



        This works as long as there aren't weird filenames (e.g. containing spaces or other special characters).



        #!/bin/bash
        cd /home/user/dir1
        find . -type f | sort > /tmp/find1
        cd /home/user/dir2
        find . -type f | sort > /tmp/find2
        for i in $(comm -12 /tmp/find1 /tmp/find2)
        do
        rm $i
        done
        rm /tmp/find1 /tmp/find2






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 15 at 14:14









        mucluxmuclux

        3,27111130




        3,27111130















            Popular posts from this blog

            數位音樂下載

            格利澤436b

            When can things happen in Etherscan, such as the picture below?