cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Cloud



Etc


Reference














.

os:linux:command:cp.html



Linux Commands#File, Directory

cp - How to use cp command in Linux with examples

man tree

NAME
       cp - copy files and directories


       -f, --force
              if an existing destination file cannot be opened, remove it and try again 
              (this option is ignored when the -n option is also used)

       -i, --interactive
              prompt before overwrite (overrides a previous -n option)

       -p     same as --preserve=mode,ownership,timestamps

       -R, -r, --recursive
              copy directories recursively


Hot to check permission

How to change root permission file.

$ sudo touch /tmp/root.txt
$ sudo -u user touch /tmp/user.txt

$ su - user
$ cp /tmp/root.txt /tmp/user.txt
$ echo "aaa" > /tmp/user.txt
$ sudo cp  /tmp/user.txt /tmp/root.txt
user.txt : owner is user
root.txt : owner is root


How to change user1 permission file.

$ sudo -u user1 touch /tmp/user1.txt

$ sudo su - user2
$ echo "aaa" > /tmp/user2.txt
$ sudo -u user1 cp  /tmp/user2.txt /tmp/user1.txt
user2.txt : owner is user2
user1.txt : owner is user1



os/linux/command/cp.html.txt ยท Last modified: 2024/03/14 by admin

Page Tools