Skip to main content
added 6 characters in body
Source Link
icarus
  • 19.1k
  • 1
  • 42
  • 57

You can use back to back tar to do the copy. For example

 tar cf - file1 file2 dir1/file3 | su user_b tar -C ~user_b/somewhere -xf - 

This will create ~user_b/somewhere/file1 as a copy of file1. ~user_b/somewhere has to exist first. There are some limitations on the tar format, but you are unlikely to hit them.

If it is just a single file then

 su - user_b bash -c 'cat > ~~user_b/file1' < file1 

followed by adjusting the permissions might be less trouble.

You can use back to back tar to do the copy. For example

 tar cf - file1 file2 dir1/file3 | su user_b tar -C ~user_b/somewhere -xf - 

This will create ~user_b/somewhere/file1 as a copy of file1. ~user_b/somewhere has to exist first. There are some limitations on the tar format, but you are unlikely to hit them.

If it is just a single file then

 su user_b bash -c 'cat > ~/file1' < file1 

followed by adjusting the permissions might be less trouble.

You can use back to back tar to do the copy. For example

 tar cf - file1 file2 dir1/file3 | su user_b tar -C ~user_b/somewhere -xf - 

This will create ~user_b/somewhere/file1 as a copy of file1. ~user_b/somewhere has to exist first. There are some limitations on the tar format, but you are unlikely to hit them.

If it is just a single file then

 su - user_b bash -c 'cat > ~user_b/file1' < file1 

followed by adjusting the permissions might be less trouble.

su not sudo
Source Link
Jasen
  • 3.9k
  • 16
  • 16

You can use back to back tar to do the copy. For example

 tar cf - file1 file2 dir1/file3 | su user_b tar -C ~user_b/somewhere -xf - 

This will create ~user_b/somewhere/file1 as a copy of file1. ~user_b/somewhere has to exist first. There are some limitations on the tar format, but you are unlikely to hit them.

If it is just a single file then

 sudosu user_b bash -c 'cat > ~/file1' < file1 

followed by adjusting the permissions might be less trouble.

You can use back to back tar to do the copy. For example

 tar cf - file1 file2 dir1/file3 | su user_b tar -C ~user_b/somewhere -xf - 

This will create ~user_b/somewhere/file1 as a copy of file1. ~user_b/somewhere has to exist first. There are some limitations on the tar format, but you are unlikely to hit them.

If it is just a single file then

 sudo user_b bash -c 'cat > ~/file1' < file1 

followed by adjusting the permissions might be less trouble.

You can use back to back tar to do the copy. For example

 tar cf - file1 file2 dir1/file3 | su user_b tar -C ~user_b/somewhere -xf - 

This will create ~user_b/somewhere/file1 as a copy of file1. ~user_b/somewhere has to exist first. There are some limitations on the tar format, but you are unlikely to hit them.

If it is just a single file then

 su user_b bash -c 'cat > ~/file1' < file1 

followed by adjusting the permissions might be less trouble.

Source Link
icarus
  • 19.1k
  • 1
  • 42
  • 57

You can use back to back tar to do the copy. For example

 tar cf - file1 file2 dir1/file3 | su user_b tar -C ~user_b/somewhere -xf - 

This will create ~user_b/somewhere/file1 as a copy of file1. ~user_b/somewhere has to exist first. There are some limitations on the tar format, but you are unlikely to hit them.

If it is just a single file then

 sudo user_b bash -c 'cat > ~/file1' < file1 

followed by adjusting the permissions might be less trouble.