Difference between cp and cp -p -i [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I am using cp command in my program to make a copy of a text file. But when I use -p -i with cp I don't understand the difference between the both.
What's the difference between using simple cp and using options -p -i with it?
Here is my line code:
execl("/bin/cp","cp","-p","-i",argv[1],argv[2],NULL);

The -i stands for interactive mode, this will require input from the stdin before it will overwrite a file.
The -p (no capital p) will preserve mode ownership and timestamp. The latter one seems the more interesting one, this will actually cause a difference in your mss. When you're copying a file there is an owner of the file and there are different file permissions and a timestamp attached to it, if you want to keep these then use the -p parameter.

Related

Equivalent Mac "cp -X" on Linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I'm migrating some bash scripts written for Mac to Linux, in which cp -X is used in several places. Some research shows that cp -X on Mac is different from cp -x on Linux.
The first one means "Do not copy Extended Attributes (EAs) or resource forks" while the latter means "stay on this file system".
So is there an equivalent Mac "cp -X" on Linux?
Thanks in advance:)
cp on Linux doesn't copy xattrs by default, and Linux doesn't have resource forks at all.
Thus, you don't need it -- default behavior does what you want.
However, if you want to be completely explicit:
cp --no-preserve=xattr

-a option in `cp` command -- what does it do? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
What does the -a option do in the cp command?
I thought that the -a does not preserve the structure of directories. But, I have never found a case where the structure of directories has been destroyed by the -a option.
is there such a case where the structure of directories has been destroyed by the -a option? Thanks.
-a means 3 things:
preserve timestamps, permissions, group, user (if you're running as root).
preserves symbolic links (no dereference)
recursive copy
read the man page, it has all info there
-a, --archive
same as -dR --preserve=all
To my understanding, it should recursively copy the directories while keeping all the attributes. In which case, it shouldn't be destroying the structure at all.
http://man7.org/linux/man-pages/man1/cp.1.html

pipe viewer does not copy the file when told to [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am trying to use Pipe Viewer command like so:
pv -cN cp file.txt /home/user/Desktop/test/
For some reason it does not copy the file. When use cp without Pipe Viewer it works perfectly. What am I doing wrong?
You can't issue commands to pv like that. This is probably what you are looking for:
pv -c file.txt > /home/user/Desktop/test/file.txt
pv probably isn't the best tool in this case. You should use rsync with the --progress flag.
rsync --progress file.txt /home/user/Desktop/test/

Is there an scp variant of mv command? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am writing a script that will move files from a local system to a remote system. It must do so through an encrypted channel like ssh. What is the best way to do this? I can perform this in two steps like:
scp *.jpg user#ip:
rm *.jpg
But, that is not an atomic process (like mv is for a local filesystem). If the copy fails I will no longer have the local copies either. How can I script this to make sure the local files only get removed if the copy succeeds?
You could use rsync with --remove-source-files:
rsync -avz --remove-source-files /local/dir/*.jpg user#ip:/remote/dir
An other solution, for launch in one time
scp /path/src/*.jpg user#host:/path/dst/ && rm /path/src/*.jpg

How to delete file named "-d" in unix(Mac OSX) from command line? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I was playing with tail, head, cut and awk commands on a text file and somehow these commands created empty files with names "-d" and "-f2" (It could be due to ). Now I am not able to delete these files from command line since all commands take these as options. Of course I can delete these from Finder but I am wondering how to delete these from command line.
Use -- to separate the files from the command line arguments. That is
rm -- -d -f2
Or, you can use the full path or a relative path containing at least a /:
rm ./-d ./-f2

Resources