Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My computer has one 500GB drive.

I want to move 400GB of data from /unencrypted to /encrypted.

Both directories are on the same partition, but /encrypted is handled by ecryptfs, so mv /uncrypted/* /encrypted would:

  1. Copy all files to destination
  2. Then remove them from source

...which I can't afford, because it requires 800GB.
If files were moved one-by-one, there would be no problem (the ecryptfs zone is dynamic).

Is there an mv option or another tool, that moves a directory file-by-file?
There is a huge number of files, so ARG_MAX might be a problem for script-based solutions.

share|improve this question
up vote 20 down vote accepted

If you have rsync (remove --dry-run to do it for real):

rsync --dry-run --remove-source-files -avHAX /unencrypted/ /encrypted

Otherwise, using bash4+ and GNU stat:


set -e

shopt -s nullglob globstar

for from in /unencrypted/**/*; do
    if [[ -d "$from" ]]; then
        echo mkdir -p "$to"
        echo chmod "$(stat -c %a "$from")" "$to"
        echo chown "$(stat -c %u:%g "$from")" "$to"
        echo cp -a "$from" "$to" && echo rm "$from"

echo rm -r /unencrypted

To run it for real, remove echo from each command.

share|improve this answer
I love the rsync idea! Apparently files are indeed removed as they are moved: superuser.com/questions/405761 – Nicolas Raoul May 16 '13 at 7:09
@NicolasRaoul If I recall correctly, the removals are buffered, but it is close to one-to-one copy/remove. – Chris Down May 16 '13 at 7:10
Chunks are fine for me, as long as each chunk weights less than 50GB. – Nicolas Raoul May 16 '13 at 7:12
Wouldn't you need to remove --dry-run from the rsync command line, too? – Michael Kjörling May 16 '13 at 7:41
@meduz v is optional and just prints the filenames as they are transferred. aHAX is required to keep all possible file attributes -- a is archive, HAX is "keep hardlinks, ACLs, and extended attributes". – Chris Down May 23 '13 at 4:19

Your Answer


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.