I am moving a folder recursively between two filesystems using mv -v. It seems like deletions happen at the end (in order to make mv transactional ?). I don't have enough space to hold two copies of the same folder, is there a way to force mv to delete a file as soon as it is done?
2 Answers
As the other answers and comments note, there is no such functionality in mv. But rsync has a --remove-source-files switch which behaves as you want, removing files from the source continuously as the operation progresses.
I'd also recommend the -a switch ("archive mode") to preserve (most) file metadata if you're making backups (mv doesn't do this if the move is between filesystems, so rsync is actually better in that regard).
- 158
No, the Man pages for mv do not indicate any switches that change the behavior of the command in the way you describe. You will have to look into other commands or algorithms.
Name
mv - move (rename) files Synopsis
mv [OPTION]... [-T] SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...
Description
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
--backup[=CONTROL]
make a backup of each existing destination file-b
like --backup but does not accept an argument-f, --force
do not prompt before overwriting-i, --interactive
prompt before overwrite-n, --no-clobber
do not overwrite an existing fileIf you specify more than one of -i, -f, -n, only the final one takes effect.
--strip-trailing-slashes
remove any trailing slashes from each SOURCE argument-S, --suffix=SUFFIX
override the usual backup suffix-t, --target-directory=DIRECTORY
move all SOURCE arguments into DIRECTORY-T, --no-target-directory
treat DEST as a normal file-u, --update
move only when the SOURCE file is newer than the destination file or when the destination file is missing-v, --verbose
explain what is being done--help
display this help and exit--version
output version information and exitThe backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control method may be selected via the --backup option or through the VERSION_CONTROL environment variable. Here are the values:
none, off
never make backups (even if --backup is given)numbered,t
make numbered backupsexisting, nil
numbered if numbered backups exist, simple otherwisesimple, never
always make simple backups
Source: https://linux.die.net/man/1/mv
- 36,135
mvshould only allocate additional disk space if its being moved to another partition. otherwise, it just updates the inodes to indicate the new location on the partition, and neither copies nor deletes anything. if you are copying to a new partition however, its unclear to me why you can't spare the disk space as both partitions should have sufficient to hold the entire directory (or this whole proposition is never going to work because the destination is too small). – Frank Thomas Sep 19 '18 at 18:39