RHCE Study Notes 2 -- command line operation File

Source: Internet
Author: User
Tags touch command

RHCE Study Notes 2 -- command line operation File
1. Create and delete a file (touch, rm) touch xxxx create a new empty file touch-t 201412250101 xxxx create a file and specify the time attribute (year, month, day, And hour. seconds) [root @ cai home] # touch xxxx [root @ cai home] # touch-t 201412301030 yyyy [root @ cai home] # ls-l xxxx yyyy-rw-r --. 1 root 0 November 2 13:00 xxxx (current time November 2, 2015 02:13)-rw-r --. 1 root 0 December 30 2014 yyyy (specified time on January 1, December 30, 2014) how to modify linux File time to put all. sh file was modified to three months ago (October 13, 2013. Operation Command: [root @ case test] # touch-d "2013/10/13 "*. sh first paste the touch parameter description here: Command Parameter:-a or -- time = atime or -- time = access or -- time = use only to change the access time. -M or -- time = mtime or -- time = modify only changes the change time. -C or -- no-create does not create any documents. -D uses the specified date and time instead of the current time. The time is the string-t that uses the specified date and time instead of the current time. The time format is year month day hour. Second-f this parameter will be ignored and not processed. It is only responsible for solving the compatibility problem of BSD touch commands. -R sets the date time of the specified document or directory to the same as the date time of the reference document or directory. Touch file1.txt update file1.txt access and modification time touch-c file1.txt if file1.txt does not exist, if you do not create a file touch-r ref_file file1.txt, the time stamp of file1.txt is the same as that of ref + file. The time stamp corresponding to the file ref_file is used as the new value of the specified file time stamp touch-t 0811142234.50. file1.txt sets the file time error to, January 1, November 14. The reference file ref_file timestamp value is used as the new value of the specified file timestamp. What is the touch command as we all know, each file is accompanied by a timestamp. This time stamp includes the access time and modification time. The Touch command is mainly used to modify the file access time and modification time. Why do we need to use the touch command? Since the touch command describes changing the timestamp, we may wonder why we need to change the timestamp? This issue will cause us to think deeply. However, I have a reason to explain why we need to use it. If you participate in a global open-source project, the timestamp may become very important. Compiling source code files may require timestamps in the same region. If not, the program may fail to be compiled. (Note: People with obsessive-compulsive disorder also like this command-it cannot be a mess of time;>) the simplest way to use the touch command without any options. Just type $ touch file_name File_1.txt. The original timestamp is. After we use the touch command, it changes. By default, touch changes the file timestamp to the current time. Only change the access time. As we mentioned earlier, each file is accompanied by the Access time and modification time. The above timestamp is. We can see more details. We found that the access time and change time values are the same as 17:08:35, and they belong to the same time zone GMT + 7. If we only need to change the access time, we need to use the-a option. $ Touch-a file_1.txt as you have seen, the access time is changed to 17:51:37, but the modification time is still 17:08:35. [Note: The original Change time (State change time) should be written by the author] only modify (Change) can be implemented using the-m option. Now we use file_2.txt as an example. $ Touch-m file_2.txt Touch-m option now changes the modification time from 12:42:20 to 17:57:20. Note that when a file is accessed or modified, the value of the state change time domain is always recorded. If you change to the custom timestamp-a and-m options, the file timestamp is changed to the current time. Of course, we can also change it to a custom timestamp. Use the-t option. From file_2.txt in the example above, we can see that its timestamp is: Access time: 12:42:20 modification time: 17:57:20 execution date: January 12, 2014 if we want to change the access time and modification time to 09:58:27. We can use the following command to complete the syntax structure: $ touch-t 201401120958.27 file_2.txt-t option: [[CC] YY] MMDDhhmm [. SS] (two years ago, two years later, two months, days, hours, minutes, seconds) another way to change the date and time if you think [[[CC] YY] MMDDhhmm [. SS] format is not suitable for you. We can also use the-d option. The following is an example of the-d option. For example, to change the specified date, we have a file named file_3.txt, and its related attributes are shown in the following. Now we want to change the date from January 1, January 14, 2014 to January 1, December 20, 2013. Run the following command: $ touch-d '10-december-100' file_3.txt is unexpected. The access time and modification time have been changed to January 1, 2013. If you want to change the time zone of the specified GMT, you can also use the-d option. First let file_3.txt move back to the current time. $ Touch file_3.txt: the time zone of file_3.txt is GMT + 0700. To change to the GMT3 time zone, type the following command: $ touch-GMT3 file_3.txt. Now the time has been changed to 10:00:00 AM. You can also use the-d option in a cool way when using the-d option with parameters. Observe the following picture. We can combine the word next Sunday and GMT 3 into a value, and the touch command can still recognize it. The date has been changed to January 21, 2014, and the current date is January 14, 2014. There is another example of the-d option. First, we need to reset file3_3.txt to the current date and time. $ Touch file_3.txt then we try this command: $ touch-d '1 year ago 13:43:07 'file_3.txt is so shocking that Touch can even recognize the word '1 year ago '. The current date and time have been changed to January 14, 2013 13:43:07. [Root @ cai home] # touch-d '4 month ago 13:43:08 'uuu changed the time of the uuu file to 13:43:08 four months ago to create an empty file. When you run the touch command when the target file does not exist, touch creates an empty file with the same name. $ Touch file_10.txt: multiple files can be created simultaneously. You can use spaces to separate the target files to create multiple files. $ Touch doc_10.txt doc_20.txt doc_30.txt summary if you want to deal with timestamps on files or directories, Touch will be very useful to you. As always, you can also type man touch or touch -- help to display the help page for more details. Rm xxx: The command parameter "-f" and "-- force" is used to forcibly delete a file from rm-rf. A message is not displayed. -I, -- interactive deletion-r,-R, and -- recursive indicate that rm will recursively delete all directories and subdirectories listed in the parameter. # Touch ---f: Create a-f file. Because there is a-before f, all characters must be added with two minus signs # ls-l ---f: view the-f file, add two escape characters minus signs before-f. -Rw-r --. 1 root 0 Nov 2-f # rm-rf ---f Delete the-f file and add two escape characters minus signs before-f. 2. Create a directory and delete the directory mkdir xxx to create a directory; mkdir-p xxx/yyy to recursively create a directory; rmdir xxx/to delete an empty directory; rm-rf XXX/forcibly Delete non-empty directories;-p, -- parents can be a path name. In this case, if some directories in the path do not exist, after this option is added, the system will automatically create those directories that do not exist, that is, multiple directories can be created at a time;-v, -- verbose displays information every time a new directory is created # mkdir-p test2/test22 recursively create multiple directories # mkdir-v test4 (information is displayed when a new directory is created) mkdir: directory "test4" # mkdir-vp test5/test5-1 mkdir: directory "test5" mkdir: directory "test5/test5-1" a command has been created to create the directory structure of the Project # mkdir-vp scf/{lib/, bin/, doc/{info, product }, logs/{info, product}, service/deploy/{info, product} mkdir: directory "scf" mkdir: directory "scf/lib" mkdir: You have created a directory named "scf/bin" mkdir: You have created a directory named "scf/doc" mkdir: You have created a directory named "scf/doc/info" mkdir: you have created a directory named "scf/doc/product" mkdir: You have created a directory named "scf/logs" mkdir: You have created a directory named "scf/logs/info" mkdir: you have created a directory named "scf/logs/product" mkdir: You have created a directory named "scf/service" mkdir: You have created a directory named "scf/service/deploy" mkdir: you have created the "scf/service/deploy/info" mkdir: you have created a directory named "scf/service/deploy/product" # tree scf/| -- bin | -- doc | -- info | '-- product | -- lib | -- logs. | -- Info | '-- product' -- service' -- deploy | -- info' -- product 12 directories, 0 files 3. copy the file and directory cp/path1/xxx/path2/yyy to copy the xxx file under the path1 path to the path2 path and name it yyy, if the yyy file already exists, it overwrites the original file. With the-I option, you will be asked whether to overwrite the file. The cp-p/path1/xxx/path2/yyy copy file retains the attributes of the original file; cp-rf/path1 // path2/copy the path1 file to the directory path2 cp-a is the same as cp-dpr = all-d: if the source file is a link file, copy the link file property instead of the file itself.-B or -- backup deletes and overwrites the target file and backs up the file first, the backup file or directory is also created as a symbol Link to the source file or directory link. If this parameter is not added, if a symbolic link is encountered during the copy process, the source file or directory-f will be copied directly to forcibly copy the file or directory, whether the target file or directory already exists or not-I overwrites the file, first ask the user-p or -- preserve to keep the properties of the source file or directory, it is acceptable to use root to "cp-p", including the owner, group, permission, and time, the "cp-p" command is equivalent to "cp" for common users. -- parents retains the path of the source file or directory and uses-r or-R for Recursive processing, process the files in the specified directory along with the subdirectories. -L or -- link creates a hard link to the source file instead of copying the file-s or -- symbolic-link to create a symbolic link to the source file, instead of copying a file-S <backup character string> or -- suffix = <backup character string> after backing up the target file with the "-B" parameter, A backup string is added at the end of the backup file. The default backup suffix is a symbol "~ "After-u or -- update uses this parameter, the object will only exist when the Modification Time of the source file is updated compared with the target file, or the target file with the corresponding names does not exist, to copy the file. copy a file, only when the source file is modified at a later time, copy file cp-u-v file1 file2 copy file file1 to file file2cp file1 file2 copy file file1 to file file2cp-I file1 file2 copy file file1 to file2, because the target file already exists, therefore, use the forced replication mode cp-f file1 file2 to copy the directory dir1 to the directory dir2cp-r dir1 dir2 and copy the files file1, file2, file3, and directory dir1 to dir2 cp-r file1. file2 file3 dir1 dir2: The file attributes cp-p a.txt/tmp are retained during replication. The directory structure cp -- parents/var/tmp/a.txt is retained. /temp/copy the backup file cp-B a.txt tmp/Specify the backup file ending with cp-B-S _ bak a.txt/tmp 4, cut the file mv/path1/xx/path2/ yy: Cut xx in the path1 path to yy in the path2 path, if path1 and path2 are in the same path, rename xx to yy. 5. Viewing the cat xx file is suitable for viewing files with less content; in the same area of more less, you can use the space bar key to flip down the page. The difference is that less allows the up and down keys to browse up, but more does not;

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.