For those who want to set a custom modification timestamps for their file, the -c and -t options might be of use. Use the following format to do the same. To change the timestamp of the file in a more user-friendly way, use the -d flag with the touch command. You will have to specify the time that you want to set in simple language. By combining the date command with touch, you can add a new modification timestamp in accordance with the old one. If the timestamp of the file is pm, then executing the aforementioned command will set am as the new mtime for the file.
You can also set custom modification timestamp for files at the time of creation. The -t flag allows you to do the same. For example, to create a new file with 12 December , pm as the timestamp, use the following command. If you can't figure out the path to the file that you want to modify, use the find command to search for files with a similar name.
You can also set the mtime and atime of the file individually during creation. Use the -a and -m flags with the command. To copy the timestamp of any other file, use the -r flag with the touch command. The default syntax of the command is:. Managing timestamps of a file has never been easier with the touch command.
If you are looking to create a new file on Linux, there are multiple options such as touch, cat, etc. But these choices are viable for only those who have decent experience working with any Linux-based operating system. For those who are not comfortable with the command line, several file managers are available that allow you to create new files in a graphical manner.
Similar to the commands above, you can use -a option to make touch only update the access time field of a file:. Finally, the really useful option for synchronizing access and modification time fields between multiple files is to use reference file.
By specifying this file using a -r option, you can use the touch command to set the same atime and mtime values to any file of yours:. Why modify file timestamps? Changing timestamps of a time to the current system time The default behavior of touch command is to change all three timestamps associated with a file to the current system time. Changing file timestamps to a specific date and time If you have a specific time and date you would like to be used for all the timestamps of a file or directory, touch command will gladly accempt a timestamp template with -t command line option.
Timestamp means that it will update the access and modification times of the file or directory specified. If we do the long list of this file using ls -l it will show the last access time. Next, we use touch command and long list it again. Now the access time gets updated. Note: If the specified file does not exist then a new file with that name is created. Thus, we can also touch command to create new files. But it will not create a new directory if it does not already exist.
For example:. By default, touch assign current time. But what if you want a time of your own choice. Note : -d option allows different formats to specify the new date and time.
By default touch assign current time.
0コメント