I'm copying files from a git repository into a virtualhost folder, although none of the following commands do overwrite existing files:
sudo cp -R /home/git/repo /var/www/website
sudo cp -R -f /home/git/repo /var/www/website
How can I make sure the cp
command overwrites existing files?
Edit: Quick test, copying files from the webdir to the repo does overwrite files, so apparently something (www-data?
) is locking the files in the webdir. The mount
output:
~$ mount | column -t
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=1005964k,nr_inodes=251491,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=204840k,mode=755)
/dev/vda1 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=27,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=204840k,mode=700,uid=1000,gid=1000)
And:
df -h /var/www
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 30G 20G 8.9G 69% /
-v
option to understand better the problem. – Giacomo Catenazzi Oct 19 '16 at 07:29-v
option shows all files being copied, but again, not overwritten. – Kurt Van den Branden Oct 19 '16 at 22:06mount
may help a lot. I suspect a network mount that may be configured in strange ways. – grochmal Oct 20 '16 at 22:35cp
command (i.e./usr/bin/cp
), or iscp
an alias, such ascp -n
? – countermode Oct 21 '16 at 06:37cp
is not an alias. Tested it with\cp
andalias cp
That last one returned-bash: alias: cp: not found
– Kurt Van den Branden Oct 21 '16 at 07:23~$ getenforce The program 'getenforce' is currently not installed
– Kurt Van den Branden Oct 21 '16 at 09:39ls -l {file}
anddf -h {file}
(yes, really.df
with the file's pathname, egdf -h /etc/hosts
) 2. Can you overwrite that file with e.g.sudo cp /etc/hosts {file}
(you may want to save the real file's contents and replace it afterwards).ls -l index.html -rw-r--r-- 1 root root 98151 Oct 20 12:56 index.html
– Kurt Van den Branden Oct 21 '16 at 13:49df
please, just as I described – Chris Davies Oct 21 '16 at 15:13df -h /var/www/website/repo/index.html
returns/dev/vda1 30G 20G 8.8G 69% /
– Kurt Van den Branden Oct 23 '16 at 11:13ls -l
on the source files, and on the destination files before and after the copy. And post the commands you entered exactly. Something like 'ls -l /home/git/repo/foo ; ls -l /var/www/website/repo/foo ; cp -a /home/git/repo /var/www/website/ ; ls -l /var/www/website/repo/foo` – ilkkachu Oct 23 '16 at 14:04ls -l
listing a couple of comments up doesn't show where thatindex.html
is located.) – ilkkachu Oct 23 '16 at 14:07/etc/exports
. Or is Samba running? Please also check what could be locking the file:fuser -v /var/www/website/repo/index.html
. – Joshua Huber Oct 25 '16 at 16:31PS1='\$ '
, and then show the entire terminal output concisely that illustrates the difficulty you are having. Many good suggestions in the comments on how to do this, but the point is that it should be possible from reading the terminal output alone to see what your problem is. – Wildcard Oct 26 '16 at 02:04