Rsync --link-dest option for single file - rsync

I have been using rsync with --link-dest option to backup directories.
I want to achieve the same thing with single files, i.e., I want to copy file srcfile to dstfile knowing that I have a previous version of the file named prevfile in destfile directory.
For directories I use: rsync -a --link-dest=prevdir srcdir dstdir
However link-dest can only take directory values. It cannot take files. I would like to do something like: rsync -a --link-dest=prevfile srcfile dstfile

It's a pity this doesn't work--I agree it would be very useful. But all you have to do to simulate it is make the link yourself:
ln prevfile dstfile
rsync -a srcfile dstfile
By the way, I filed this as a bug: https://bugzilla.samba.org/show_bug.cgi?id=8594

Related

Why rsync --delete flag just puts ~ at end of filename

Using the --delete flag in rsync with verbose mode and I see when i run it is says 'deleting file xxxxx' because the file no longer exists in the source. However when I list the folder, the file is still there but just with a ~ at the end of the filename?
I'd think those are backup files. From man rsync:
-b, --backup
With this option, preexisting destination files are renamed as each file is transferred or deleted. You can control where the backup file goes and what (if any) suffix gets appended using the
--backup-dir and --suffix options.
--suffix=SUFFIX
This option allows you to override the default backup suffix used with the --backup (-b) option. The default suffix is a ~ if no --backup-dir was specified, otherwise it is an empty string.
I ran into this same problem before and there's essentially an error in the rsync documentation. If you are using the -a archive option like I was, which I bet you are, the documentation says -a is equivalent to -rlptgoD it's actually equivalent to -rlptgoDb so just use -rlptgoD instead of -a so you aren't using the -b (backup) option inadvertantly

Copying multiple files of different file types UNIX

I have some files that are .py and others that are ".txt". Instead of
cp *.py myDir/
cp *.txt myDir/
is there a way to perform this in one line on the command line?
Thanks
Try this:
cp *.{py,txt} myDir/
More info about *nix wildcards you can find here.

What is the differences between real so file and ln -s

for example, my directory like this:
lib
|
+--foo.so
+--bar.so -> bar.so.1.0.0.0
+--bar.so.1.0.0.0
Are these both ways always same?
The reason I ask this question is that I found unix will copy to real so file when I
cp -r lib /path/to/
new directory like this:
/path/to/lib
|
+--foo.so
+--bar.so
+--bar.so.1.0.0.0
The difference between so and ls -s is the difference between a file and a symbolic link. Symbolic links are like aliases to other files and operations on them result in changes in the linked files. When you do cp, it copies the linked file to the target directory with the link name as the file name, i.e., it reads the linked file when it opens the symbolic link to copy it. So lose the link and instead get a copy of the linked file. If you use -P option of the cp command you can preserve the symbolic link information.
cp -P lib /path/to/

How to copy a entire directory which contains symlinks?

I want to copy a complete directory content from /home/private_html/userx/ into the /home/private_html/usery/, the problem is that the directory userx contains few symlinks, and when using the cp it just skip them (skip occurs, if symlinks directs into a file, in case if it points into the directory, it just copy WHOLE directory instead...).
The command I was using looks following:
# cp -iprv /home/private_html/userx/ /home/private_html/usery/
Has anyone a solution to copy the directory "just as it is" into other place?
On FreeBSD, cp doesn't have an -r option. It does have -R, which should do what you want:
-R If source_file designates a directory, cp copies the directory and
the entire subtree connected at that point. If the source_file
ends in a /, the contents of the directory are copied rather than
the directory itself. This option also causes symbolic links to be
copied, rather than indirected through, and for cp to create spe‐
cial files rather than copying them as normal files. Created
directories have the same mode as the corresponding source direc‐
tory, unmodified by the process' umask.
Roland is right about the -R flag. You could also use a pair of tar-processes, which would make your command a little bit more system-independent:
tar -C /home/private_html/userx/ -cpf - . | tar -C /home/private_html/usery/ -epf -

Untar a UNIX-based operating system

I am trying to untar UNIX-based operating system from a .tar.gz file. In order to do so I use the following command:
tar -xvf rootfs.tar.gz -o
The -o flag is to not to preserve the ownership of the files (it gave some problems). The problem is that when a symbolic link is untared the following message shows up
Cannot create symlink to `toto': Operation not permitted
Moreover, mknod also gives problems
dev/tty0: Cannot mknod: Operation not permitted
I am in a FAT system. Does anyone know how to untar that file?
Thanks in advance
If the file is a tar.gz you must use:
tar -xvzf rootfs.tar.gz
And notice that a FAT filesystem doesn't support symbolic links, so it doesn't know how to make it on that FS, and it explains the Operation Not Permitted Error.
+1 fpr Ivan's answer
please note that:
flags always go right after the name of the command!
you will need to study "man tar" to see what other options you want, e.g. preserve owner, permissions, time-creation date, etc..
The correct answer is that if you're trying to untar a UNIX root file system, that's going to include special files such as device nodes (which is why tar is invoking mknod).
To create those successfully, tar must be allowed to run as root. Therefore, the correct answer is to use sudo, like so:
sudo tar -xvzf rootfs.tar.gz
Try this to untar a tar file. Hopefully it will work fine without any problem, as this one solved my issue
tar -xvvf foo.tar

Resources