Replication of Linux Commands (CP)

xiaoxiao2021-03-06  35

The function of the CP command is that the function is copied to another file or directory to another file or directory, just like the Copy command under MSDOS, the function is very powerful.

For example, there are two folders AA and BB in the root directory (/), there is a AA.TXT file in AA, there is a bb.txt file in the BB, now copy AA.txt to BB Inside (now / directory) steps (1) CP without parameters (aa.txt is different from bb.txt content) Administrator @ Song / CD /AA/AA.TXT / BB Administrator @ Song /

(2) Note: If the file name in the AA is the same as the file name in the BB, it is aa.txt, and the file content is different, then the above operation will override the AA.txt (3) CP band parameters in the BB. - a This option is usually used when copying the directory. It retains links, file properties, and recursively copys the directory, which is equal to the combination of DPR options. If aa.txt is read-only attribute, after the CP operation, the original property does not change the Administrator @ Song / $ CP /AA/AA.TXT / BB. If this parameter is not selected (4) - D Reserved Link when D copy. (Copy the link file) (5) - f Delete the existing target file without prompting (6) - I and f option, the prompt is given to the user to confirm before overwriting the target file. When the answer y, the target file will be overwritten and is an interactive copy. (7) - p At this point, the CP will also copy its modification time and access to the new file (8) - r if the source file is given to a directory file, at this time Recute all subdirectories and files in this directory. At this point the target file must be a directory name. (9) - L is not copied, just link file (hard link) (10) -u When the source file is more than the target file, or the update copy (11) -v does not exist when the target file does not exist, and Copy (12) -X extended information (13) - L (soft link) For example, Administrator @ song / cp -l /aa/aa.txt /bb/c.txt This time C.TXT content with aa.txt changes Change, AA.TXT also changes with C.TXT, but Del is aa.txt, C.TXT still exists, then C.TXT is just a alienistrator @ Song / CP -L / AA /aa.txt /bb/c.txt This time C.TXT content does not change as Aa.txt changes, and AA.TXT does not change as C.TXT changes, if Del is AA.TXT, C. TXT still exists

The link file is a bit similar to the so-called shortcuts of Windows, but is not exactly the same. There are two ways, soft links and hard links.

Soft link file Soft link is also called a symbolic link, which contains the path name of another file. It can be any file or directory that can be linked to files of different file systems. The link file can even link the file that does not exist, which is generally called "broken" problem (or "" phenomena "), the link file can even loop yourself. Similar to recursive in the programming language. When reading or writing a symbol file, the system will automatically convert the operation to the operation of the source file, but when the link file is deleted, the system only deletes the link file without deleting the source file itself.

The hard link file INFO LN command tells us that hard links are another name that already exists files, which is a bit confusing. Two restrictions on hard link files

1. Do not allow a hard link to the directory; 2, the link can only be created between files in the same file system.

The result is the same as the soft link to read and write and delete the hard link file. But if we delete the source file of the hard link file, the hard link file still exists, and the content will be preserved. At this time, the system "Forgot" It used to be a hard link file. And treat him as a normal file

The specific function of the other parameters is finishing, such as -b -h -p -r, because it does not understand the reason, I hope the master is added // pay attention to the command environment Cygwin

转载请注明原文地址:https://www.9cbs.com/read-64923.html

New Post(0)