How to change the ownership of the file during the copy itself. I mean the cp command how to add ownership
cp
I cannot rely on --preserve and copy the file, and then change the ownership of the file due to some restrictions. Thanks
--preserve
Not easy. Perhaps you could run the cp command as the user you want to own the new file, or copy it aside to a temporary location, chown , then copy it to where it wants to get it, but cp itself lacks chown .
chown
This is not a direct answer to your question, but if you have GNU cpio , you can use it (in copy mode) to copy files when changing ownership. eg.
cpio
echo 'some_file_name' | cpio -p --owner someuser:somegroup destination_directory
As stated here: https://unix.stackexchange.com/questions/124855/move-files-and-change-ownership-at-the-sametime
Use rsync (1):
rsync \ --remove-source-files \ --chown=wanteduser:wantedgroup \ /home/oldfolder /home/newfolder
I use a workaround with the scp command:
scp -p file.txt <user>@localhost:<destination>
Example:
scp -p /home/reportuser/dailyReport.doc root@localhost :/root/dailyReports/20150105/
-p - save the timestamp of the source file
Source: https://habr.com/ru/post/950817/More articles:Related / related objects / classes in C # such as LINQ - linked-listAutoMapper problem accessing DTO from ViewModel - c #https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/950814/using-dropboxjs-to-authenticate-the-client-with-oauth-2-what-about-the-server&usg=ALkJrhgk2Umevc1C6doeUV-9A8-OxsHq5QJava Thread.currentThread (). SetUncaughtExceptionHandler () not working with JUNIT? - javaError trying to use inline forms in Symfony2 - formsBest practice for preventing further instantiation of Java classes - javaHow to get inline results in a worksheet in Eclipse / Scala -IDE on Ubuntu 12.04? - eclipseScala Results Encoding Eclipse Worksheet Plugin - eclipsehttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/950821/log-gate-mdevactioncompletedgate-m-seems-to-delay-execution-on-android&usg=ALkJrhgIFDxupFiEfDnNUIVGtxgYNAl77AHow to save a variable number of arguments using the arguments of the variational pattern? - c ++All Articles