4
votes
cp without overwriting destination permissions
By default, GNU cp (version 8.32) will NOT overwrite destination permissions, so the question is moot:
% ls -li
total 8,192
19392015 -rwxrwxrwx 1 ravi ravi 4 Jan 3 16:54 bar*
19392014 -rw-r--r-- 1 ...
3
votes
How to move and partially rename files on linux
This worked for me - could also be done with find instead of ls:
#touch foo-1.3.{1..10}.war
#ls -1
foo-1.3.10.war
foo-1.3.1.war
foo-1.3.2.war
foo-1.3.3.war
foo-1.3.4.war
foo-1.3.5.war
...
3
votes
UNIX Copy/Move files in same directory preserving timestamp
Only root can change ownership of files, so user3 will need to be able to use sudo to change ownership of files belonging to user1 and user2.
mv will always preserve all metadata, including ...
3
votes
How to make cp report an error when file was not copied?
I doubt you can do that with CP, because it only tells you if the command ran sucessfully or not. I would use rsync instead
https://unix.stackexchange.com/questions/512571/rsync-keep-in-textfile-...
3
votes
mv fails but cp succeeds on nfs mount
Are your password / group databases in sync between client and
server?
Do you see any files on nfs mounted directory on nfs client as owned
by
nobody nobody
Can you post output of nfsidmap -d from ...
3
votes
cp -p will preserve times for some files but not all?
I know this is old, but I was having the same issue of trying to copy over cifs shares. I have several commands set up in sudoers with the NOPASSWD option and one is cp. If I do sudo cp -r from.file ...
3
votes
copy files, get file names from a list
Xargs is nice/fast/etc but isn't easy to understand for novices in shell scripting.
I think that's will be much more readable (and more clean than for with subshell).
#!/bin/bash
while read ...
2
votes
cpio VS tar and cp
I understand from the comments and other background that cpio is less ubiquitous now and inconsistent between versions. But cpio has one advantage I recently found invaluable when dealing with a large ...
2
votes
copy files, get file names from a list
You can do this
IFS=$'\n' ; for file in `cat file_list.txt` ; do cp $file /path/ ; done
Explanation
Set internal field separator to newline
Read file_list.txt and loop through each line assigning ...
2
votes
Accepted
Is it OK to copy files installed with rpm to another location?
Doing it that way negates most the the advantages of using packages.
Fix the package to put its files where you want them. That way if you use rpm to verify files it will checksum the files in use.
...
2
votes
Accepted
Why I can do a wildcard copy from one location, but can't from another?
sudo cp /home/jenkins/dist/*.war /opt/tomcat/webapps/
Here, your (non-privileged) shell will attempt to expand the '*' before passing the resulting command line to sudo - hence its behaviour will ...
2
votes
Accepted
Safest way to move a mount point that is a parent of other mount points on Linux to a new physical device
If you bind mount a directory, then the submounts will not be bound. So create a dummy directory somewhere, and do
mount --bind /var/lib/kubelet/ /mnt/tmptmp_dummy/
Then the contents of the /var/lib/...
2
votes
Accepted
How to move and partially rename files on linux
Using just bash and commands in most common distributions by default:
find . -name "foo-*.war" -exec sh -c 'mv "$1" "other_folder/foo-dev-${1#foo-}"' _ {} \;
2
votes
Accepted
using find, exec and cp to copy specific files while preserving directory path
You have a race condition: since temp/s is in find's search path, find is listing files, while the spawned cps are adding new files.
You have to exclude the sub-directory while running find:
find . -...
1
vote
How can I check if a transfer initiated with `aws s3 cp` was 100% successful?
One can use --only-show-errors: if the transfer is 100% successful, then nothing will be output.
Documentation:
--only-show-errors (boolean) Only errors and warnings are displayed. All other output ...
1
vote
How to move and partially rename files on linux
You could use Perl implementation of rename program (there is another program called rename which is a part of util-linux package) like that:
$ touch foo-1.3.{1..10}.war
$ ls -l
total 0
-rw-r--r-- 1 ...
1
vote
Accepted
Making a copy of all .acignore->.gitignore in place, recursively
This should do the trick:
find ./ -name '.acignore' | sed 's/.acignore//g' | xargs -I {} cp {}.acignore {}.gitignore
It's "./" if you are inside the "c" directory. If you are ...
1
vote
Copying files in Linux keeps full path
To copy folder world to ~/backups/backup_2019-05-04:
backupdir=~/backups/backup_$(date +%F)
mkdir -p "$backupdir"
cp -av ~/world "$backupdir"
I used flag -a for archive mode which includes -R. You ...
1
vote
what is the best approach to copy /var content
Instead of cp I suggest
rsync -aqxP /var/* /var_copy
...but your plan will break many things (rm -rf /var "under" a running system).
Better to
copy things
modify /etc/fstab
reboot
... as ...
1
vote
Accepted
Create copy of file in the same location
cp /very/long/file/path{,.bak}
vim !$
or
cpvi() {
name=$1
cp "${name}" "${name}.bak"
$EDITOR "${name}.bak"
}
cpvi /very/long/file/path
1
vote
Accepted
cp is too slow, same with rsync (I assume) - is there a way to share files in two locations?
You could copy using reflinks `cp --reflink=always', which will create a differential file that references a static original. If you do this, you'll probably want to make the original immutable so the ...
1
vote
ACL mask not updated when cp a directory with g=r-x to directory with default:mask::rwx and default:group::rwx
To copy ACLs from a directory to another, you had to instruct cp to do that, using the -a switch. In other words, use cp -a src dst
EDIT
The inherited ACLs will not grant permissions which the file ...
1
vote
Accepted
copy files, get file names from a list
cat file_list.txt | tr '\n' '\0' | xargs -r0i cp -t /path/to/dest/ "{}"
1
vote
Turning off cp (copy) command's interactive mode (cp : overwrite ?)
Yea the reason for cp command to be interactive because in many common shells by default copy comes with alias as cp -i this can be found by running command as follows :
alias cp
output will be
...
Only top scored, non community-wiki answers of a minimum length are eligible