In Linux what happens if 1000 files in a directory are moved to another location while another 300 files were...

After checking in online, how do I know whether I need to go show my passport at airport check-in?

Would tunnel walls be stronger if built using cut granite block walls reinforced with carbon based cords?

What to look for when criticizing poetry?

Why is Agricola named as such?

Why are all my replica super soldiers young adults or old teenagers?

How do you catch Smeargle in Pokemon Go?

In Linux what happens if 1000 files in a directory are moved to another location while another 300 files were added to the source directory?

Crontab: Ubuntu running script (noob)

What is the data structure of $@ in shell?

With regard to distributive law of inner product in vector algebra

How to make ice magic work from a scientific point of view?

Is using an 'empty' metaphor considered bad style?

Avoid page break between paragraphs

How does Leonard in "Memento" remember reading and writing?

Differences between prior distribution and prior predictive distribution?

It took me a lot of time to make this, pls like. (YouTube Comments #1)

Square Root Distance from Integers

Early credit roll before the end of the film

How can a large fleets maintain formation in interstellar space?

Identify KNO3 and KH2PO4 at home

Why would space fleets be aligned?

Airplane generations - how does it work?

A Missing Symbol for This Logo

Clues on how to solve these types of problems within 2-3 minutes for competitive exams



In Linux what happens if 1000 files in a directory are moved to another location while another 300 files were added to the source directory?


Any way to sync directory structure when the files are already on both sides?rsync: delete only extraneous files with a timestamp earlier than the newest in the source directoryLinux Shell script to copy files from one location to another locationhow to check for duplicates and rename file if there are any while copying them from another sourcemoving files from one location to another while they are being usedHow to delete duplicate files of two folders?What happens in linux when you copy a hardlink on top of another hardlink to the same file?What happens if I edit a folder while copying it?ZIP: What are the temporary binary files which names start with `zi`?What happens if you delete a file while it was moving from one filesystem(ext4) to another(NTFS)?













18















In Linux what happens if 1000 files in a directory are moved to another location and another 300 files were added to the source directory while original 1000 files were being moved. Will the destination end up being 1300 files? or will there be 300 files remaining in the source folder.










share|improve this question







New contributor




Shayan Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 3





    This is not a direct answer, which seems to be well provided by @Eugene-Rieck. But, you might find it interesting/userful to read about Race Conditions (en.wikipedia.org/wiki/Race_condition ). They seem to be relevant to your question. In effect, if the specific commands you use to do the moving and adding of files create a race condition, then unusual things will happen.

    – user02814
    8 hours ago













  • @user02814: The problem with race conditions is that unusual things might happen. When you're looking for them or writing tests, they usually don't happen. When you're putting code in production, they will surely happen. :)

    – Eric Duminil
    55 mins ago
















18















In Linux what happens if 1000 files in a directory are moved to another location and another 300 files were added to the source directory while original 1000 files were being moved. Will the destination end up being 1300 files? or will there be 300 files remaining in the source folder.










share|improve this question







New contributor




Shayan Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 3





    This is not a direct answer, which seems to be well provided by @Eugene-Rieck. But, you might find it interesting/userful to read about Race Conditions (en.wikipedia.org/wiki/Race_condition ). They seem to be relevant to your question. In effect, if the specific commands you use to do the moving and adding of files create a race condition, then unusual things will happen.

    – user02814
    8 hours ago













  • @user02814: The problem with race conditions is that unusual things might happen. When you're looking for them or writing tests, they usually don't happen. When you're putting code in production, they will surely happen. :)

    – Eric Duminil
    55 mins ago














18












18








18


3






In Linux what happens if 1000 files in a directory are moved to another location and another 300 files were added to the source directory while original 1000 files were being moved. Will the destination end up being 1300 files? or will there be 300 files remaining in the source folder.










share|improve this question







New contributor




Shayan Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












In Linux what happens if 1000 files in a directory are moved to another location and another 300 files were added to the source directory while original 1000 files were being moved. Will the destination end up being 1300 files? or will there be 300 files remaining in the source folder.







linux filesystems operating-systems






share|improve this question







New contributor




Shayan Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Shayan Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Shayan Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









Shayan AhmadShayan Ahmad

9616




9616




New contributor




Shayan Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Shayan Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Shayan Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 3





    This is not a direct answer, which seems to be well provided by @Eugene-Rieck. But, you might find it interesting/userful to read about Race Conditions (en.wikipedia.org/wiki/Race_condition ). They seem to be relevant to your question. In effect, if the specific commands you use to do the moving and adding of files create a race condition, then unusual things will happen.

    – user02814
    8 hours ago













  • @user02814: The problem with race conditions is that unusual things might happen. When you're looking for them or writing tests, they usually don't happen. When you're putting code in production, they will surely happen. :)

    – Eric Duminil
    55 mins ago














  • 3





    This is not a direct answer, which seems to be well provided by @Eugene-Rieck. But, you might find it interesting/userful to read about Race Conditions (en.wikipedia.org/wiki/Race_condition ). They seem to be relevant to your question. In effect, if the specific commands you use to do the moving and adding of files create a race condition, then unusual things will happen.

    – user02814
    8 hours ago













  • @user02814: The problem with race conditions is that unusual things might happen. When you're looking for them or writing tests, they usually don't happen. When you're putting code in production, they will surely happen. :)

    – Eric Duminil
    55 mins ago








3




3





This is not a direct answer, which seems to be well provided by @Eugene-Rieck. But, you might find it interesting/userful to read about Race Conditions (en.wikipedia.org/wiki/Race_condition ). They seem to be relevant to your question. In effect, if the specific commands you use to do the moving and adding of files create a race condition, then unusual things will happen.

– user02814
8 hours ago







This is not a direct answer, which seems to be well provided by @Eugene-Rieck. But, you might find it interesting/userful to read about Race Conditions (en.wikipedia.org/wiki/Race_condition ). They seem to be relevant to your question. In effect, if the specific commands you use to do the moving and adding of files create a race condition, then unusual things will happen.

– user02814
8 hours ago















@user02814: The problem with race conditions is that unusual things might happen. When you're looking for them or writing tests, they usually don't happen. When you're putting code in production, they will surely happen. :)

– Eric Duminil
55 mins ago





@user02814: The problem with race conditions is that unusual things might happen. When you're looking for them or writing tests, they usually don't happen. When you're putting code in production, they will surely happen. :)

– Eric Duminil
55 mins ago










2 Answers
2






active

oldest

votes


















45














This depends on which tools you use: Let's check a few cases:



If you run something along the lines of mv /path/to/source/* /path/to/dest/ int a shell, you will end up with the original 1000 files being moved, the new 300 being untouched. This comes from the fact, that the shell will expand the * before starting the move operation, so when the move is in progress, the list is already fixed.



If you use Nautilus (and other GUI friends), you will end up the same way: It will run the move operation based on which files were selected - this doesn't change when new files show up.



If you use your own program using syscalls along the line of loop over glob and only one mv until glob stays empty, you will end up with all 1300 files in the new directory. This is because every new glob will pick up the new files, that have showed up in the meantime.






share|improve this answer



















  • 5





    What happens if you opendir() the source, then loop over readdir() or getdents()?

    – grawity
    yesterday








  • 2





    Is that true for all filesystems, and regardless of the amount of files? I assumed the kernel generally returns live results through readdir(), and doesn't pre-cache them or anything.

    – grawity
    23 hours ago






  • 11





    The result-set of an opendir() is stable according to POSIX. A quick test with PHP's opendir() confirms that (but I tested only ext4).

    – Eugen Rieck
    23 hours ago






  • 7





    @grawity: POSIX says: If a file is removed from or added to the directory after the most recent call to opendir() or rewinddir(), whether a subsequent call to readdir() returns an entry for that file is unspecified. Also, NFS may put some restrictions on what is implementable, IIRC it complicates implementation of telldir()/seekdir()

    – ninjalj
    20 hours ago






  • 1





    @grawity: tangentially related: lwn.net/Articles/544520

    – ninjalj
    19 hours ago



















7














When you tell the system to move all the files from a directory, it lists all the files and then starts moving them. If new files appear in the directory, they aren't added to the list of files to move, so they'll remain in the original location.



You can, of course, program a way of moving files different to mv which will periodically check for new files in the source directory.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Shayan Ahmad is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1409532%2fin-linux-what-happens-if-1000-files-in-a-directory-are-moved-to-another-location%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    45














    This depends on which tools you use: Let's check a few cases:



    If you run something along the lines of mv /path/to/source/* /path/to/dest/ int a shell, you will end up with the original 1000 files being moved, the new 300 being untouched. This comes from the fact, that the shell will expand the * before starting the move operation, so when the move is in progress, the list is already fixed.



    If you use Nautilus (and other GUI friends), you will end up the same way: It will run the move operation based on which files were selected - this doesn't change when new files show up.



    If you use your own program using syscalls along the line of loop over glob and only one mv until glob stays empty, you will end up with all 1300 files in the new directory. This is because every new glob will pick up the new files, that have showed up in the meantime.






    share|improve this answer



















    • 5





      What happens if you opendir() the source, then loop over readdir() or getdents()?

      – grawity
      yesterday








    • 2





      Is that true for all filesystems, and regardless of the amount of files? I assumed the kernel generally returns live results through readdir(), and doesn't pre-cache them or anything.

      – grawity
      23 hours ago






    • 11





      The result-set of an opendir() is stable according to POSIX. A quick test with PHP's opendir() confirms that (but I tested only ext4).

      – Eugen Rieck
      23 hours ago






    • 7





      @grawity: POSIX says: If a file is removed from or added to the directory after the most recent call to opendir() or rewinddir(), whether a subsequent call to readdir() returns an entry for that file is unspecified. Also, NFS may put some restrictions on what is implementable, IIRC it complicates implementation of telldir()/seekdir()

      – ninjalj
      20 hours ago






    • 1





      @grawity: tangentially related: lwn.net/Articles/544520

      – ninjalj
      19 hours ago
















    45














    This depends on which tools you use: Let's check a few cases:



    If you run something along the lines of mv /path/to/source/* /path/to/dest/ int a shell, you will end up with the original 1000 files being moved, the new 300 being untouched. This comes from the fact, that the shell will expand the * before starting the move operation, so when the move is in progress, the list is already fixed.



    If you use Nautilus (and other GUI friends), you will end up the same way: It will run the move operation based on which files were selected - this doesn't change when new files show up.



    If you use your own program using syscalls along the line of loop over glob and only one mv until glob stays empty, you will end up with all 1300 files in the new directory. This is because every new glob will pick up the new files, that have showed up in the meantime.






    share|improve this answer



















    • 5





      What happens if you opendir() the source, then loop over readdir() or getdents()?

      – grawity
      yesterday








    • 2





      Is that true for all filesystems, and regardless of the amount of files? I assumed the kernel generally returns live results through readdir(), and doesn't pre-cache them or anything.

      – grawity
      23 hours ago






    • 11





      The result-set of an opendir() is stable according to POSIX. A quick test with PHP's opendir() confirms that (but I tested only ext4).

      – Eugen Rieck
      23 hours ago






    • 7





      @grawity: POSIX says: If a file is removed from or added to the directory after the most recent call to opendir() or rewinddir(), whether a subsequent call to readdir() returns an entry for that file is unspecified. Also, NFS may put some restrictions on what is implementable, IIRC it complicates implementation of telldir()/seekdir()

      – ninjalj
      20 hours ago






    • 1





      @grawity: tangentially related: lwn.net/Articles/544520

      – ninjalj
      19 hours ago














    45












    45








    45







    This depends on which tools you use: Let's check a few cases:



    If you run something along the lines of mv /path/to/source/* /path/to/dest/ int a shell, you will end up with the original 1000 files being moved, the new 300 being untouched. This comes from the fact, that the shell will expand the * before starting the move operation, so when the move is in progress, the list is already fixed.



    If you use Nautilus (and other GUI friends), you will end up the same way: It will run the move operation based on which files were selected - this doesn't change when new files show up.



    If you use your own program using syscalls along the line of loop over glob and only one mv until glob stays empty, you will end up with all 1300 files in the new directory. This is because every new glob will pick up the new files, that have showed up in the meantime.






    share|improve this answer













    This depends on which tools you use: Let's check a few cases:



    If you run something along the lines of mv /path/to/source/* /path/to/dest/ int a shell, you will end up with the original 1000 files being moved, the new 300 being untouched. This comes from the fact, that the shell will expand the * before starting the move operation, so when the move is in progress, the list is already fixed.



    If you use Nautilus (and other GUI friends), you will end up the same way: It will run the move operation based on which files were selected - this doesn't change when new files show up.



    If you use your own program using syscalls along the line of loop over glob and only one mv until glob stays empty, you will end up with all 1300 files in the new directory. This is because every new glob will pick up the new files, that have showed up in the meantime.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered yesterday









    Eugen RieckEugen Rieck

    10.6k22429




    10.6k22429








    • 5





      What happens if you opendir() the source, then loop over readdir() or getdents()?

      – grawity
      yesterday








    • 2





      Is that true for all filesystems, and regardless of the amount of files? I assumed the kernel generally returns live results through readdir(), and doesn't pre-cache them or anything.

      – grawity
      23 hours ago






    • 11





      The result-set of an opendir() is stable according to POSIX. A quick test with PHP's opendir() confirms that (but I tested only ext4).

      – Eugen Rieck
      23 hours ago






    • 7





      @grawity: POSIX says: If a file is removed from or added to the directory after the most recent call to opendir() or rewinddir(), whether a subsequent call to readdir() returns an entry for that file is unspecified. Also, NFS may put some restrictions on what is implementable, IIRC it complicates implementation of telldir()/seekdir()

      – ninjalj
      20 hours ago






    • 1





      @grawity: tangentially related: lwn.net/Articles/544520

      – ninjalj
      19 hours ago














    • 5





      What happens if you opendir() the source, then loop over readdir() or getdents()?

      – grawity
      yesterday








    • 2





      Is that true for all filesystems, and regardless of the amount of files? I assumed the kernel generally returns live results through readdir(), and doesn't pre-cache them or anything.

      – grawity
      23 hours ago






    • 11





      The result-set of an opendir() is stable according to POSIX. A quick test with PHP's opendir() confirms that (but I tested only ext4).

      – Eugen Rieck
      23 hours ago






    • 7





      @grawity: POSIX says: If a file is removed from or added to the directory after the most recent call to opendir() or rewinddir(), whether a subsequent call to readdir() returns an entry for that file is unspecified. Also, NFS may put some restrictions on what is implementable, IIRC it complicates implementation of telldir()/seekdir()

      – ninjalj
      20 hours ago






    • 1





      @grawity: tangentially related: lwn.net/Articles/544520

      – ninjalj
      19 hours ago








    5




    5





    What happens if you opendir() the source, then loop over readdir() or getdents()?

    – grawity
    yesterday







    What happens if you opendir() the source, then loop over readdir() or getdents()?

    – grawity
    yesterday






    2




    2





    Is that true for all filesystems, and regardless of the amount of files? I assumed the kernel generally returns live results through readdir(), and doesn't pre-cache them or anything.

    – grawity
    23 hours ago





    Is that true for all filesystems, and regardless of the amount of files? I assumed the kernel generally returns live results through readdir(), and doesn't pre-cache them or anything.

    – grawity
    23 hours ago




    11




    11





    The result-set of an opendir() is stable according to POSIX. A quick test with PHP's opendir() confirms that (but I tested only ext4).

    – Eugen Rieck
    23 hours ago





    The result-set of an opendir() is stable according to POSIX. A quick test with PHP's opendir() confirms that (but I tested only ext4).

    – Eugen Rieck
    23 hours ago




    7




    7





    @grawity: POSIX says: If a file is removed from or added to the directory after the most recent call to opendir() or rewinddir(), whether a subsequent call to readdir() returns an entry for that file is unspecified. Also, NFS may put some restrictions on what is implementable, IIRC it complicates implementation of telldir()/seekdir()

    – ninjalj
    20 hours ago





    @grawity: POSIX says: If a file is removed from or added to the directory after the most recent call to opendir() or rewinddir(), whether a subsequent call to readdir() returns an entry for that file is unspecified. Also, NFS may put some restrictions on what is implementable, IIRC it complicates implementation of telldir()/seekdir()

    – ninjalj
    20 hours ago




    1




    1





    @grawity: tangentially related: lwn.net/Articles/544520

    – ninjalj
    19 hours ago





    @grawity: tangentially related: lwn.net/Articles/544520

    – ninjalj
    19 hours ago













    7














    When you tell the system to move all the files from a directory, it lists all the files and then starts moving them. If new files appear in the directory, they aren't added to the list of files to move, so they'll remain in the original location.



    You can, of course, program a way of moving files different to mv which will periodically check for new files in the source directory.






    share|improve this answer




























      7














      When you tell the system to move all the files from a directory, it lists all the files and then starts moving them. If new files appear in the directory, they aren't added to the list of files to move, so they'll remain in the original location.



      You can, of course, program a way of moving files different to mv which will periodically check for new files in the source directory.






      share|improve this answer


























        7












        7








        7







        When you tell the system to move all the files from a directory, it lists all the files and then starts moving them. If new files appear in the directory, they aren't added to the list of files to move, so they'll remain in the original location.



        You can, of course, program a way of moving files different to mv which will periodically check for new files in the source directory.






        share|improve this answer













        When you tell the system to move all the files from a directory, it lists all the files and then starts moving them. If new files appear in the directory, they aren't added to the list of files to move, so they'll remain in the original location.



        You can, of course, program a way of moving files different to mv which will periodically check for new files in the source directory.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        chorobachoroba

        13.3k13341




        13.3k13341






















            Shayan Ahmad is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            Shayan Ahmad is a new contributor. Be nice, and check out our Code of Conduct.













            Shayan Ahmad is a new contributor. Be nice, and check out our Code of Conduct.












            Shayan Ahmad is a new contributor. Be nice, and check out our Code of Conduct.
















            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1409532%2fin-linux-what-happens-if-1000-files-in-a-directory-are-moved-to-another-location%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Benedict Cumberbatch Contingut Inicis Debut professional Premis Filmografia bàsica Premis i...

            Monticle de plataforma Contingut Est de Nord Amèrica Interpretacions Altres cultures Vegeu...

            Escacs Janus Enllaços externs Menú de navegacióEscacs JanusJanusschachBrainKing.comChessV