20

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.

1 Answer 1

20

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:

#!/bin/bash

set -e

shopt -s nullglob globstar

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

echo rm -r /unencrypted

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

9
  • I love the rsync idea! Apparently files are indeed removed as they are moved: superuser.com/questions/405761 May 16, 2013 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, 2013 at 7:10
  • Chunks are fine for me, as long as each chunk weights less than 50GB. May 16, 2013 at 7:12
  • Wouldn't you need to remove --dry-run from the rsync command line, too?
    – user
    May 16, 2013 at 7:41
  • 1
    @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, 2013 at 4:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .