Cpmvtouch commands in Linux

Source: Internet
Author: User
Tags touch command
Linux cpmvtouch command-Linux general technology-Linux programming and kernel information. The following is a detailed description. Today I learned the cp mv touchcp command

This command is used to copy the given file or directory to another file or directory. It is very powerful like the copy command in MSDOS.

Syntax: cp [Option] source file or directory target file or directory

Note: This Command copies the specified source file to the target file or multiple source files to the target directory.

The options of this command are as follows:

-A this option is usually used when copying directories. It retains links and file attributes, and Recursively copies directories. Its role is equal to the combination of dpR options.

-D: the link is retained during copy.

-F delete an existing target file without prompting.

-I and f options are opposite. A prompt is displayed asking the user to confirm before overwriting the target file. When the answer is y, the target file will be overwritten, which is an interactive copy.

-P in addition to copying the source file content, cp also copies the modification time and access permissions to the new file.

-If the source file provided by r is a directory file, cp will recursively copy all subdirectories and files in the directory. The target file must be a directory name.

-L do not copy, but only link files.

It should be noted that, in order to prevent the user from using the cp Command inadvertently to destroy another file, such as the target file name specified by the user already exists, use the cp command to copy the file, this file will be overwritten by the new source file. Therefore, we recommend that you use the I option when using the cp command to copy the file.


Introduction to mv commands
You can use the mv command to rename a file or directory or move the file from one directory to another. This command is like a combination of ren and move in MSDOS.
Syntax: mv [Option] source file or directory target file or directory
Note: depending on the type of the second parameter in the mv command (whether it is the target file or the target directory), the mv command renames the file or moves it to a new directory. When the second parameter type is file, the mv command renames the file. At this time, only one source file (or the source directory name) can be used ), it renames the given source file or directory to the given target file name. When the second parameter is an existing directory name, there may be multiple source files or directory parameters. The mv command moves the source files specified by each parameter to the target directory. When a file is moved across file systems, the mv copies the file first, and then deletes the original file. The link to the file will also be lost.
The meaning of each option in the command is:
-I interactive operation. If the mv operation will overwrite the existing target file, the system will ask whether to rewrite the file and ask the user to Answer y or n. This will avoid overwrite the file by mistake.
-F prohibit interactive operations. When an mv operation overwrites an existing target file, no instructions are given. If this option is specified, the I option will no longer work.
If the target file (not a directory) already exists, the content of the file will be overwritten by the new file. To prevent the user from using the mv command to destroy another file, it is best to use the I option when using the mv command to move the file.

The touch command is used to update the object access and modification time.
Syntax Touch[ -] [ -C] [ -M] [ -F] [ -R RefFile] [ Time| -T Time] { File... | Directory...}
Description TouchCommand update DirectoryThe FileThe access time and modification time of each file specified by the parameter. If no TimeVariable value, TouchCommand to use the current time. If a nonexistent file is specified, TouchCommand to create this file, unless -CFlag.
TouchThe return code of the command is the number of files that have not been successfully modified at the time (including non-existing files and files not created ).
Note: any date beyond January 1, 2038 (including January 1, 2038) is invalid.
Flag
[Table = 98%] [tr] [td = 16%,] -[/Td] [td = 83%,] changed from FileThe Object Access time specified by the variable. Do not change the modification time unless -MFlag. [/Td] [/tr] [tr] [td] -C[/Td] [td] If the file does not exist, do not create it. No diagnostic messages related to this condition were written. [/Td] [/tr] [tr] [td] -F[/Td] [td] tries to force touch to run, regardless of the read and write permissions of the file. [/Td] [/tr] [tr] [td] -M[/Td] [td] Change File. Do not change the access time unless -MFlag. [/Td] [/tr] [tr] [td] -R RefFile[/Td] [td] used RefFileThe corresponding time of the file specified by the variable, instead of the current time. [/Td] [/tr] [tr] [td] Time[/Td] [td] MMDDhhmmThe format of [YY] specifies the date and time of the new time stamp, where: MMSpecify the year January (from 01 to 12 ). DDSpecifies the day (from 01 to 31) of January 1, January ). HhSpecifies the hour of the day (from 00 to 23 ). MmSpecifies the minute of an hour (from 00 to 59 ). YYSpecify the last two digits of the year. If YYThe variable is not specified. The default value is the current year. [/Td] [/tr] [tr] [td] -T Time[/Td] [td] uses the specified time instead of the current time. TimeThe variable is in decimal format [[ CC] YY] MMDDhhmm[ . SS], Where: CCSpecify the first two digits of the year. YYSpecify the last two digits of the year. MMSpecify the year January (from 01 to 12 ). DDSpecifies the day (from 01 to 31) of January 1, January ). HhSpecifies the hour of the day (from 00 to 23 ). MmSpecifies the minute of an hour (from 00 to 59 ). SSSpecifies the second of a minute (from 00 to 59 ). [/Td] [/tr] [/table]
Note:
  1. TouchCommand callUtime ()Subroutine to change the modification and access time of the involved files. When a file is not actually owned, even if the file has the write permission, the flag may makeTouchCommand failed.
  2. When usingTouchIf an error message is received, do not specify the full path name./Usr/bin/touch.
Exit status the command returns the following exit values:
[Table = 98%] [tr] [td = 5%,] 0The [/td] [td = 95%,] command is successfully executed. All request changes have been completed. [/Td] [/tr] [tr] [td] > 0[/Td] [td] error. [/Td] [/tr] [/table]
Security For RBAC users and Trusted AIX users, note the following:This command can be used to perform privileged operations. Only privileged users can run privileged operations. For more information about permissions and privileges, see 《 Security"Privileged command Database" in ". To obtain a list of permissions and privileges related to the command, see /Etc/security/privcmdsDatabase files.
Example
  1. To update the file access and modification time, enter:
    Touch program. CThis willProgram. cThe last access and modification time of the file is set to the current date and time. IfProgram. cThe file does not exist,TouchCommand to create an empty file with the same name.
  2. To avoid creating a new file, enter:Touch-CProgram. c
  3. To update only the modification time, enter:Touch-M*. O
    This updates. OThe last modification time of the file ending with the extension (the access time is not updated ).TouchCommands are often used in this way to changeMakeCommand result.
  4. To explicitly set the access and modification time, enter:Touch-C-T02171425 program. c
    This sets the access and modification time to (p.m.) of the current year .).
  5. To use the time stamp of another file instead of the current time, enter:Touch-RFile1 program. c
    This willProgram. cThe time stamp of the file is set to the same as that of the file1 file.
  6. To process files at a specified time rather than the current time, enter:Touch-T198503030303.55 program. c
    This willProgram. cThe time stamp of the file is set to 3:03:55 AM, January 1, March 3, 1985.
File
[Table = 98%] [tr] [td = 23%,] /Usr/bin/touch[/Td] [td = 76%,] contains TouchCommand. [/Td] [/tr] [/table]
Related information DateCommands, LocaleCommand.
UtimeSubroutine.
Operating System and device management"Directory" describes the structure and features of directories in the file system.
Operating System and device management"File" describes the file, file type, and how to name the file.
Operating System and device management"File and directory access method" describes the ownership of the file and the access permissions of the file and directory.
AIX V6.1 general programming concepts: programming and debugging"Understanding file types" describes the control file commands.
Security"Trusted AIX" in 』.
Security"RBAC" in 』.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.