|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <title>cp Command Explanation</title> |
| 7 | + <link rel="stylesheet" href="style.css"> |
| 8 | +</head> |
| 9 | +<body> |
| 10 | + <div class="container"> |
| 11 | + <h1>Understanding the <code>cp</code> Command</h1> |
| 12 | + |
| 13 | + <section> |
| 14 | + <h2>Basic Usage of <code>cp</code></h2> |
| 15 | + <p>The <code>cp</code> command is used to copy files and directories in Linux. The most basic usage is:</p> |
| 16 | + <div class="code-block"> |
| 17 | + <code>cp [source_file] [destination]</code> |
| 18 | + </div> |
| 19 | + <p>This will copy the specified file from the source to the destination.</p> |
| 20 | + </section> |
| 21 | + |
| 22 | + <section> |
| 23 | + <h2>Options Available with <code>cp</code></h2> |
| 24 | + |
| 25 | + <h3><code>cp</code> (Basic Copy)</h3> |
| 26 | + <p>Copies a file or directory from one location to another:</p> |
| 27 | + <div class="code-block"> |
| 28 | + <code>cp file1.txt /home/user/directory/</code> |
| 29 | + </div> |
| 30 | + |
| 31 | + <h3><code>cp -r</code> (Recursive Copy)</h3> |
| 32 | + <p>Copies directories recursively (i.e., it copies the directory along with all its files and subdirectories):</p> |
| 33 | + <div class="code-block"> |
| 34 | + <code>cp -r directory1/ /home/user/directory2/</code> |
| 35 | + </div> |
| 36 | + |
| 37 | + <h3><code>cp -f</code> (Force Overwrite)</h3> |
| 38 | + <p>Forces the overwrite of existing files without confirmation:</p> |
| 39 | + <div class="code-block"> |
| 40 | + <code>cp -f file1.txt /home/user/directory/</code> |
| 41 | + </div> |
| 42 | + |
| 43 | + <h3><code>cp -i</code> (Interactive Mode)</h3> |
| 44 | + <p>Prompts the user for confirmation before overwriting files:</p> |
| 45 | + <div class="code-block"> |
| 46 | + <code>cp -i file1.txt /home/user/directory/</code> |
| 47 | + </div> |
| 48 | + |
| 49 | + <h3><code>cp -u</code> (Update Only)</h3> |
| 50 | + <p>Copies only when the source file is newer than the destination file or if the destination file does not exist:</p> |
| 51 | + <div class="code-block"> |
| 52 | + <code>cp -u file1.txt /home/user/directory/</code> |
| 53 | + </div> |
| 54 | + |
| 55 | + <h3><code>cp -v</code> (Verbose Output)</h3> |
| 56 | + <p>Displays detailed information about the copying process:</p> |
| 57 | + <div class="code-block"> |
| 58 | + <code>cp -v file1.txt /home/user/directory/</code> |
| 59 | + </div> |
| 60 | + |
| 61 | + <h3><code>cp -p</code> (Preserve File Attributes)</h3> |
| 62 | + <p>Preserves file attributes such as modification time, access time, and file permissions:</p> |
| 63 | + <div class="code-block"> |
| 64 | + <code>cp -p file1.txt /home/user/directory/</code> |
| 65 | + </div> |
| 66 | + |
| 67 | + <h3><code>cp -a</code> (Archive Mode)</h3> |
| 68 | + <p>Preserves the original file structure, attributes, and symbolic links while copying directories recursively:</p> |
| 69 | + <div class="code-block"> |
| 70 | + <code>cp -a directory1/ /home/user/directory2/</code> |
| 71 | + </div> |
| 72 | + |
| 73 | + <h3><code>cp --parents</code></h3> |
| 74 | + <p>Copies the file along with its parent directory structure:</p> |
| 75 | + <div class="code-block"> |
| 76 | + <code>cp --parents dir1/dir2/file.txt /destination/</code> |
| 77 | + </div> |
| 78 | + |
| 79 | + <h3><code>cp -n</code> (No Overwrite)</h3> |
| 80 | + <p>Prevents overwriting existing files at the destination:</p> |
| 81 | + <div class="code-block"> |
| 82 | + <code>cp -n file1.txt /home/user/directory/</code> |
| 83 | + </div> |
| 84 | + |
| 85 | + <h3><code>cp --help</code></h3> |
| 86 | + <p>Displays the help manual for the <code>cp</code> command:</p> |
| 87 | + <div class="code-block"> |
| 88 | + <code>cp --help</code> |
| 89 | + </div> |
| 90 | + </section> |
| 91 | + |
| 92 | + <section> |
| 93 | + <h2>Summary of Options</h2> |
| 94 | + <table> |
| 95 | + <thead> |
| 96 | + <tr> |
| 97 | + <th>Option</th> |
| 98 | + <th>Description</th> |
| 99 | + </tr> |
| 100 | + </thead> |
| 101 | + <tbody> |
| 102 | + <tr> |
| 103 | + <td><code>cp [source_file] [destination]</code></td> |
| 104 | + <td>Basic file copy.</td> |
| 105 | + </tr> |
| 106 | + <tr> |
| 107 | + <td><code>cp -r [directory]</code></td> |
| 108 | + <td>Recursively copies directories and their contents.</td> |
| 109 | + </tr> |
| 110 | + <tr> |
| 111 | + <td><code>cp -f [file]</code></td> |
| 112 | + <td>Forces overwriting of existing files.</td> |
| 113 | + </tr> |
| 114 | + <tr> |
| 115 | + <td><code>cp -i [file]</code></td> |
| 116 | + <td>Prompts for confirmation before overwriting files.</td> |
| 117 | + </tr> |
| 118 | + <tr> |
| 119 | + <td><code>cp -u [file]</code></td> |
| 120 | + <td>Copies only if the source file is newer or the destination file doesn't exist.</td> |
| 121 | + </tr> |
| 122 | + <tr> |
| 123 | + <td><code>cp -v [file]</code></td> |
| 124 | + <td>Verbose mode, showing details during the copy process.</td> |
| 125 | + </tr> |
| 126 | + <tr> |
| 127 | + <td><code>cp -p [file]</code></td> |
| 128 | + <td>Preserves file attributes like timestamps and permissions.</td> |
| 129 | + </tr> |
| 130 | + <tr> |
| 131 | + <td><code>cp -a [directory]</code></td> |
| 132 | + <td>Preserves the file attributes, symbolic links, and structure while copying.</td> |
| 133 | + </tr> |
| 134 | + <tr> |
| 135 | + <td><code>cp --parents [file]</code></td> |
| 136 | + <td>Copies the file along with its parent directory structure.</td> |
| 137 | + </tr> |
| 138 | + <tr> |
| 139 | + <td><code>cp -n [file]</code></td> |
| 140 | + <td>Prevents overwriting existing files.</td> |
| 141 | + </tr> |
| 142 | + <tr> |
| 143 | + <td><code>cp --help</code></td> |
| 144 | + <td>Displays help information.</td> |
| 145 | + </tr> |
| 146 | + </tbody> |
| 147 | + </table> |
| 148 | + </section> |
| 149 | + |
| 150 | + <section> |
| 151 | + <h2>Manual Pages</h2> |
| 152 | + <p>For more detailed information, use the manual page for the <code>cp</code> command:</p> |
| 153 | + <div class="code-block"> |
| 154 | + <code>man cp</code> |
| 155 | + </div> |
| 156 | + </section> |
| 157 | + </div> |
| 158 | +</body> |
| 159 | +</html> |
0 commit comments