You can use touch -d or –date=STRING option to provide a custom timestamp to touch command. By default, touch command uses the current timestamp value.
Example:
Get the current system time
1 2 |
## Get current timestamp date +"%b %d %T" ## returns Feb 02 18:40:16 |
Create a new empty file
1 2 |
## Create a new empty file touch myfile |
List all available files and directories
1 2 |
## list all available files ls -l ## -rw-r--r-- 1 debjeet debjeet 0 Feb 2 18:40 myfile |
touch -d option example
1 2 |
## touch -d option touch -d 'Jan 26 22:30' myfile |
List all available files and directories
1 2 3 4 |
## list all available files ls -l ## -rw-r--r-- 1 debjeet debjeet 0 Jan 26 22:30 myfile rm myfile |
Observe, the timestamp of myfile changed to “Jan 26 22:30”