Ask Your Question

Using CP to back up home directory

asked 2018-03-28 05:34:50 -0600

The Evil One gravatar image

I use the following set of commands to backup my home directory on an HDD in a USB dock. I am using the drive in HDD to backup the home directories in my system and I thought this command would work to both do the initial copy and to later copy files that are new or updated.
[Carl@localhost ~]$ su

[root@localhost Carl]# cd /home

[root@localhost home]# cp -r -u -v Carl /run/media/Carl/036107cf-8650-421e-a46d-7f0e7df744ca

As I understand the man page for cp this should copy all files from my home directory Carl to directory Carl in the logical volume whose UUID is 036107cf-8650-421e-a46d-7f0e7df744ca. It should not copy a file if the time stamp of the corresponding file in the destination directory is later than that in the source because of the -u option nor should it ask me whether any files are to be replaced Y/N because I have not specified the -i option however as the following extract shows it is so asking.

cp: overwrite '/run/media/Carl/036107cf-8650-421e-a46d-7f0e7df744ca/Carl/.cache/gnome-software/3.24/upgrades/fedora.json'? n

cp: overwrite '/run/media/Carl/036107cf-8650-421e-a46d-7f0e7df744ca/Carl/.cache/gnome-software/3.24/firmware/firmware.xml.gz.asc'? n

cp: overwrite '/run/media/Carl/036107cf-8650-421e-a46d-7f0e7df744ca/Carl/.cache/gnome-software/3.24/firmware/firmware.xml.gz'? n

cp: overwrite '/run/media/Carl/036107cf-8650-421e-a46d-7f0e7df744ca/Carl/.cache/gnome-software/3.24/ratings/odrs.json'? n

cp: overwrite '/run/media/Carl/036107cf-8650-421e-a46d-7f0e7df744ca/Carl/.cache/gnome-software/3.24/extensions/gnome.json'? n

cp: overwrite '/run/media/Carl/036107cf-8650-421e-a46d-7f0e7df744ca/Carl/.cache/tracker/locale-for-miner-user-guides.txt'? ^C

And since my home directory contains an enormous number of files replying Y or N is impractical especially since I do not know why the command is asking the question.

If cp cannot do what I want is there another command that will?

edit retag flag offensive close merge delete


use rsync and skip directories like ~/.cache (.thumbnails, ...) when backing up.

florian gravatar imageflorian ( 2018-03-28 13:01:44 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2018-03-28 12:04:50 -0600

fcomida gravatar image

In fedora cp is an alias for cp -i. You can unalias it or call /bin/cp directly. Another command is rsync.

edit flag offensive delete link more


I checked with alias and didn't find anything for cp. I also looked in .bashrc and didn't see where I'd changed that command. Where did you get that from? However, I do agree that rsync is probably the best choice.

sideburns gravatar imagesideburns ( 2018-03-28 13:59:44 -0600 )edit

@sideburns you are right, no alias for cp in /etc/bashrc or any of /etc/profile.d/*.sh. Did Fedora ever define those aliases (rm -i too) in the past? I was pretty sure of that.

fcomida gravatar imagefcomida ( 2018-03-28 14:34:36 -0600 )edit

@sideburns Fedora/RHEL does that only for the root account

fcomida gravatar imagefcomida ( 2018-03-28 14:44:29 -0600 )edit

Thank you fcomida, and sideburns, that explains why cp acts as if option -i is specified when I run it under root. The reason that I have to run it under root is that something I have done previously has transferred ownership of some of my files to root.

Is there a command that can list all defined aliases.

In future I will use /bin/cp or rsync.

The Evil One gravatar imageThe Evil One ( 2018-03-30 06:56:49 -0600 )edit

Yes. The command alias when run by itself will do that.

sideburns gravatar imagesideburns ( 2018-03-30 13:07:36 -0600 )edit

answered 2018-03-28 13:33:14 -0600

hmaarrfk gravatar image

A while ago I used: To backup my stuff.

Pretty cool, keeps things as "files" and not encrypted.

edit flag offensive delete link more

Question Tools



Asked: 2018-03-28 05:31:21 -0600

Seen: 140 times

Last updated: Mar 28 '18