How does the 'mv' command work? - linux

I used the command mv to move files from directory /a/b to directory /v/c. I wanted the whole 'b' directory to be moved to the path /v/c.
Now while running this command- mv /a/b /v/c I interrupted it in middle where the source had a large amount of data. Later I deleted directory 'c' since I thought it had partial files.
Now my question is will the directory 'b' contain all the original files along with the files that where moved to path /v/c? Or did I lose files by deleting the directory 'c'?

mv across filesystems will:
create the destination directory
for each file: copy and remove original
remove origin directory
Thus, if you interrupt it, some of the files will have been moved but not all. A mv of a directory within the same filesystem is atomic as it's just re-linking the directory's inode to a new location.
At one time, mv could only do the latter.

I believe it depends on if the source and destination directories were on the same file system or different file systems. If they were on the same file system then a "move" just changes the path information for each file. But if they're on different file systems the "move" command will copy one file at a time, and subsequently delete it on the source.
So, in your scenario if the source and destination were on separate file systems then yes, you just lost files if you interrupted mv and then deleted "c".

Related

will coping files recursively from one directory to another lead to changes in one directory reflect in another directory files also?

If I copy files from one directory to another directory:
Will their inode numbers also change?
Changes in file of one directory, will it reflect in same file of another directory also?
When I use command like:
cp -r dir1/ dir2/
With a simple copy the file system handle the copied files as newly created ones, therefore assining new inodes to them.
Any change made in the origin wouldn't change the copys. This only happens when you create symbolic or hard links between files.
You can check the inodes of your files with "ls -i filename".

move (or copy) files from a list in Linux

So, I have a list of files in a text file. I believe it's about 100,000 files.
The files in said list are spread across many directories, have different sizes, filenames, extensions, ages, etc.
I am trying to find a way to move those files, and just those, to another drive.
Complicating factor: some of the files have the same name, but are not the same file. They can't just be moved into one folder with an overwriting or ignoring policy towards multiples.
Preferably, I would like them to retain their directory structure, but only have the files that I want inside the destination directory. (the destination drive isn't big enough to simply copy everything).
Below is an example of some lines in the file:
media/dave/xdd/cruzer/F#(NTFS 1)/Raw Files/Portable Network Graphic file/3601-3900/FILE3776.PNG/Windows/winsxs/amd64_microsoft-windows-o..disc-style-memories_31bf3856ad364e35_6.1.7600.16385_none_51190840a935f980/Title_mainImage-mask.png
media/dave/xdd/d1/other/hd1/Program Files/DVD Maker/Shared/DvdStyles/Memories/Title_content-background.png
I have tried to use
rsync -a --files-from=/sourcefile.txt / /media/destinationhdd
However, this just tries to copy my root directory to the destination. Please help, how to I just copy the accursed files that I want to?
cat list | xargs tar cf - | (cd dest; tar xvfp -)
Where list is the file which contains all the file paths.
dest is the target directory

Copy non-directory over directory and vv

How can I avoid the following types of errors, and force the
operation to occur?:
/bin/cp: cannot overwrite directory `./foo' with non-directory
/bin/cp: cannot overwrite non-directory `./usr/share/doc' with directory `/usr/share/doc'
To backup a partition, I want to copy a new version of a
directory onto an old version, to make them identical, with the
command:
/bin/cp -xau --remove-destination / .
The destination directory is in a ZFS filesystem that is being
regularly snapshotted. Relatively few files (or directories)
change.
That is why I don't want to just delete the whole
destination directory -- that will make the snapshot needlessly
large.
This is in Linux.
Thanks.
The following seems to work better (but not perfectly):
tar cf /mytmp/root.tar --one-file-system /
cd /backup/root
tar xvf /mytmp/root.tar --keep-newer-files
Note that this works better when /mytmp is not in the root
partition. :-)
The output from the 2nd tar command was 700K lines. I captured
it inside an emacs buffer and searched it for error messages.
There were two problems with not wanting to replace directories
with links, which I handled manually.

Not symlinking one or two files inside symlinked directory

Is there a way not to symlink one or two files within a symlinked directory in CentOS?
I've got the entire directory symlinked but there are two css files that I would like to use the current copy for the website
In short: no.
Another way to do this would be to symlink all the files in that directory, except those you want local copy of.
Still another way to go might be using unionfs or aufs to union-mount the original directory and a directory containing the files you need local, with the directory containing local files being "on top".
Say, your original directory is orig, the directory with files that should be local is local, the union directory is union, and you want files from both directories to be writable. Then you can union-mount them like this:
unionfs-fuse local=RW:orig=RW union
And unmount like this:
fusermount -u union
See unionfs manpage (unionfs-fuse(8) at least on Debian) for details.

Wget - output directory prefix

Currently I try to use:
"wget --user=xxx --password=xxx -r ftp://www.domain.com/htdocs/"
But this saves output files to current directory in this fashion:
curdir/www.domain.com/htdocs/*
I need it to be:
curdir/*
Is there a way to do this, I only see a way to use output prefix, but i think this will just allow me to define directory outside current dir?
You can combine --no-directories if you want all your files inside one directory or --no-host-directories to have subdirectories but no subdirectories per host with your --directory-prefix option.
2.6 Directory Options
‘-nd’
‘--no-directories’
Do not create a hierarchy of directories when retrieving recursively. With this option turned on, all files will get saved to the current directory, without clobbering (if a name shows up more than once, the filenames will get extensions ‘.n’).
‘-nH’
‘--no-host-directories’
Disable generation of host-prefixed directories. By default, invoking Wget with ‘-r http://fly.srk.fer.hr/’ will create a structure of directories beginning with fly.srk.fer.hr/. This option disables such behavior.
‘-P prefix’
‘--directory-prefix=prefix’
Set directory prefix to prefix. The directory prefix is the directory where all other files and subdirectories will be saved to, i.e. the top of the retrieval tree. The default is ‘.’ (the current directory).
(From the wget manual.)

Resources