mv deleting files at the end instead of one by one

1

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?

Paperino

Posted 2018-09-19T18:25:54.850

Reputation: 156

an mv should 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 – 2018-09-19T18:39:39.493

Apparently mv doesn't do things recursively. It will move each top level folder. That is good enough for me content is split evenly between top level folders anyway and I have enough room for 2 copies of each of them. P.S. my case was related to 2 ZFS file systems on the same pool. From a mv perspective these are different, from a storage perspective it's shared. I don't know if it makes sense. – Paperino – 2018-09-19T21:38:20.967

ahh, that makes sense. multi-disk aggregations do confuse the matter. unfortunately, mv won't work for you by itself, so perhaps look into alternatives like a shell script to enumerate the sub directories and process them individually (copy, delete, rinse, repeat), or perhaps something like rsync may work better for you. – Frank Thomas – 2018-09-19T22:12:50.510

Answers

0

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 file

If 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 exit

The 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 backups  

existing, nil

numbered if numbered backups exist, simple otherwise  

simple, never

always make simple backups

Source: https://linux.die.net/man/1/mv

Frank Thomas

Posted 2018-09-19T18:25:54.850

Reputation: 29 039