-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcp.txt
More file actions
143 lines (87 loc) · 4.32 KB
/
Copy pathcp.txt
File metadata and controls
143 lines (87 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
Interesting flags from bash cp man page:
--attributes-only
don't copy the file data, just the attributes
--backup[=CONTROL]
make a backup of each existing destination file
-b like --backup but does not accept an argument
-d same as --no-dereference --preserve=links
-H follow command-line symbolic links in SOURCE
-l, --link
hard link files instead of copying
-L, --dereference
always follow symbolic links in SOURCE
-n, --no-clobber
do not overwrite an existing file (overrides a previous -i option)
-P, --no-dereference
never follow symbolic links in SOURCE
-R, -r, --recursive
copy directories recursively
-s, --symbolic-link
make symbolic links instead of copying
-H: What does this do?
-L: What does this do? Sounds like -H. See the find man page. Find has
HLP flags relating to symlinks. Seems to be related.
-s: Seems like ln -s, except that it has to stay in the same directory.
----------------------------------------------------------------------
Initially, do:
-l: Create a hard link to the file
-P: Copy symlink as is. If link target is relative, then copy may not make sense.
-r
----------------------------------------------------------------------
cp can create hard links and symbolic links. This overlaps with the ln
command. (ln does hard link, or symbolic if -s specified.)
----------------------------------------------------------------------
cp -P: preserves links. "never follow" means the link is kept as is.
cp -H: Top-level link is followed. Below top-level, link is kept as is.
cp -L: All symlinks followed.
----------------------------------------------------------------------
Design:
cp [SOURCE_FILENAME ...] TARGET_FILENAME
SOURCE_FILENAME Filename or glob pattern of a file to be moved.
TARGET_FILENAME Filename or glob pattern of the destination.
The source files are copied to the target. Even if TARGET_FILENAME is
a glob pattern, a single target must be identified. If there is one
source file, then the target may be an existing file, an existing
directory, or a path to a non-existent file. If there are multiple
source files, then the target must be an existing directory.
If no SOURCE_FILENAMEs are specified, then the source files are taken
from the input stream. In this case, each input object must be a
1-tuple containing a File, and TARGET_FILENAME must identify a
directory that already exists. (Note that the behavior is based on
syntax -- whether SOURCE_FILENAMEs are provided. If a SOURCE_FILENAME
is provided, then source files are not taken from the input stream,
even if SOURCE_FILENAME fails to identify any files.)
Flags (from linux cp):
-r | --recursive
-P | --preserve-all-symlinks keep all symlinks (don't follow them)
-H | --preserve-non-top-symlinks follow top-level symlinks only
-L | --preserve-no-symlinks follow all symlinks
-l | --hard-link-to-source create hard links?
-s | --symlink-to-source create symlinks?
-p | --preserve preserve metadata
----------------------------------------------------------------------
Details of copying
See cp_behavior.ods, which has results from cp_behavior.py.
Rules:
- If source doesn't exist (including via link), then cp fails: "No
such file or directory"
- Copy file: Always copy file preserving name. Fails if target is
dangling link: "not writing through dangling symlink").
- Copy link to file: Same as copying file, except that -P copies the
link, replacing the target. In other words, default and -HL is like
copying a file.
- Copy dir: Always copy except:
- target is file (or link to file)
- target is dangling link
In these cases: cannot overwrite non-directory
- Copy link to dir:
- default, -P: Like copying file-link with -P: the link is copied
over the target or into it.
- -HL: Like copying dir
Tools, from shutil:
- Copy file: copy(source, target, follow_symlinks)
- Works for file or dir target
- follow_symlinks controls source symlink
- Copy dir: copytree(source, target, symlinks)
- target directory is created.
- symlinks = true preserves symlinks