Bash: mv directory one at a time

I am trying to move all subdirectories of a folder to another share on the same server. If I do a mv *, I will run out of space since the folders are not removed until all folders get transferred. So I'd like to create a short script that loops through each one. Does any one have an example that I can look at? I've searched around but can't find exactly what I am looking for.


You could use rsync(1):

rsync --remove-source-files /path/to/source /path/to/destination

This will remove successfully transferred files from the original path.


You want for.

An example (this will just show what will be done):

for item in *; do
    echo mv "$item" /destination/directory
done

When you're happy, remove echo to do it for real.


Using the mv command to move files from one volume to a different volume is a copy operation. But how would you run out of space on the source volume? You would only run out of space on the target volume if that volume is smaller than the total size of the files you're moving. But either way, you're only deallocating space on the source volume, not allocating more space on it.

If you use mv to "move" files from one directory to another on the same volume, that's just a rename operation. You're not copying data, you're just adjusting file pointers to present a different directory hierarchy. You're not going to run out of space because the file data stays right where it was.

Either way, I'm not sure I see the problem. :-) Have you actually been trying this and running out of space, or are you just trying to plan ahead?


ls -1 | xargs -n1 -i echo mv '{}' destination

Just remove the echo when happy.