- Linux – Fake File Access, Modify and Change TimeStamps
- Get a File’s TimeStamps
- Difference Between “atime”, “mtime” and “ctime”
- Change File “Access” & “Modification” Time
- Change File “Change” Time
- Stay Stealthy
- 5 Linux Touch Command Examples (How to Change File Timestamp)
- 1. Create an Empty File using touch
- 2. Change File’s Access Time using -a
- 3. Change File’s Modification Time using -m
- 4. Explicitly Setting Access and Modification time using -t and -d
- 5. Copy the Time-stamp from Another File using -r
- Changing a file’s «Date Created» and «Last Modified» attributes to another file’s
- 3 Answers 3
- Example
- Modify via Samba
- Изменение даты создания и даты модификации файла
- 2 ответа 2
- Всё ещё ищете ответ? Посмотрите другие вопросы с метками linux touch или задайте свой вопрос.
- Похожие
- Подписаться на ленту
- How can I change ‘change’ date of file?
- 6 Answers 6
Linux – Fake File Access, Modify and Change TimeStamps
Files in Linux have 3 types of timestamps: atime (access), mtime (modify) and ctime (change).
Someday you may have a situation when you would like to fake a timestamps of some file.
atime and mtime timestamps can be easily changed using touch command, but there is no a standard way to set a different ctime timestamp.
As a possible workaround you can set the system time to the ctime you want to impose, then touch the file and then restore the system time.
Read the below article to learn how to change a file’s timestamps and keep anonymity.
Cool Tip: To cover up the traces – clear the last login history. Read more →
Get a File’s TimeStamps
Use the stat command to see the current file’s timestamps:
Difference Between “atime”, “mtime” and “ctime”
Timestamp | When it gets updated? |
---|---|
atime | Access time gets updated when you open a file or when a file is used for other operations like grep, cat, head and so on. |
mtime | Modify time gets updated when you whenever update content of a file or save a file. |
ctime | Change time gets updated when the file attributes are changed, like changing the owner, changing the permission or moving it to another filesystem, but will also be updated when you modify a file. |
Change File “Access” & “Modification” Time
Change a file’s atime (access time):
Change a file’s mtime (modification time):
Change File “Change” Time
Nevertheless, if you are ready to risk, it is possible;)
Firstly you can set the system time to the ctime you want to impose.
Then touch the file and immediately rollback the system time.
Unexpected impact: Modification of a system time may cause an unexpected impact! Use the below commands on your own risk!
Save the current system’s date and time in the variable NOW :
Set the fake date and time (requires root):
Touch the file to fake the all timestamps:
Rollback the date and time (requires root):
Cool Tip: Clear the BASH history effectively! Read more →
To speedup modification and reduce the possible impact, execute the above commands as follows:
Stay Stealthy
To stay stealthy – unset the variable, clear logs and history.
Unset the variable NOW :
Remove the information about changed time from /var/log/messages (requires root):
atime and mtime timestamps can be easily changed using touch command, but there is no a standard way to set a different ctime timestamp.
Cool Tip: Want to stay anonymous? Learn how to use PROXY on the Linux command line. Read more →
Clear the last login history (requires root):
Источник
5 Linux Touch Command Examples (How to Change File Timestamp)
Every file in Linux is associated with timestamps, which specifies the last access time, last modification time and last change time.
Whenever we create a new file, or modify an existing file or its attributes, these timestamps will be updated automatically.
Touch command is used to change these timestamps (access time, modification time, and change time of a file).
1. Create an Empty File using touch
You can create an empty file using touch command. The following example will create a zero byte new file named tgs.txt.
You can also use -c option to avoid creating new files. If you use -c option, and if a file doesn’t exists, touch will not create the file.
Commands like ls command and find command uses these timestamp information for listing and finding files.
You can also create more than 1 files from a single touch command. The following example will create 4 files named a, b, c, and d.
2. Change File’s Access Time using -a
We can change the access time of a file using -a option. By default it will take the current system time and update the atime field.
Before touch command is executed:
After the above touch command (Please note that the access time is changed):
3. Change File’s Modification Time using -m
You can change the modification time of a file using -m option.
The above method can be used to change the mtime of all obj files, when using make utility.
NOTE: It is not possible to change the ctime using touch command
4. Explicitly Setting Access and Modification time using -t and -d
Instead of taking the current time-stamp, you can explicitly specify the time using -t and -d options.
The format for specifying -t is [[CC]YY]MMDDhhmm[.SS]
The following explains the above format:
- CC – Specifies the first two digits of the year
- YY – Specifies the last two digits of the year. If the value of the YY is between 70 and 99, the value of the CC digits is assumed to be 19. If the value of the YY is between 00 and 37, the value of the CC digits is assumed to be 20. It is not possible to set the date beyond January 18, 2038.
- MM – Specifies the month
- DD – Specifies the date
- hh – Specifies the hour
- mm – Specifies the minute
- SS – Specifies the seconds
Verify the above change using stat command:
You can also use a string to change the time
For developers, touch command will be really helpful when you are working with Makefiles
5. Copy the Time-stamp from Another File using -r
You can also take a file as a reference, and update the time for other files, so that both file will hold the same time.
Источник
Changing a file’s «Date Created» and «Last Modified» attributes to another file’s
I’m using merge cap to create a merge pcap file from 15 files. For the merged file, I have changed the name to that of the first of the 15 files. But I would also like to change the merged file’s attributes like «Date Created» and «Last Modified» to that of the first one. Is there anyway to do this?
I try to access the merged files over a samba server (Ubuntu). So that an extractor function can access auto extract the files to D folder. But as the created date will be changed for the merged file the extraction fails. Is there anyway to fix this?
3 Answers 3
You can use the touch command along with the -r switch to apply another file’s attributes to a file.
NOTE: There is no such thing as creation date in Unix, there are only access, modify, and change. See this U&L Q&A titled: get age of given file for further details.
Example
For example purposes here’s a goldenfile that was created with some arbitrary timestamp.
Now I make some new file:
Now apply goldenfile ‘s attributes to newfile .
Now newfile has the same attributes.
Modify via Samba
I just confirmed that I’m able to do this using my Fedora 19 laptop which includes version 1.16.3-2 connected to a Thecus N12000 NAS (uses a modified version of CentOS 5.x).
I was able to touch a file as I mentioned above and it worked as I described. Your issue is likely a problem with the either the mounting options being used, which may be omitting the tracking of certain time attributes, or perhaps it’s related to one of these bugs:
Источник
Изменение даты создания и даты модификации файла
Как изменить дату модификации и создания файла в Linux ?
2 ответа 2
В терминале вводим :
Где :
1998 — год
07 — месяц
08 — день
12 — час
15 — минута
.25 — секунда
А можно использовать ключ -d , который принимает строковое значение :
Ключи :
-m Дата модификации
-a Дата открытия файла
-t Отметка времени
Изменяем системное время.
sudo date —set 10/04/2019
Создаем и модифицируем файл.
Синхронизируем часы, в Arch Linux.
sudo timedatectl set-ntp true
Всё ещё ищете ответ? Посмотрите другие вопросы с метками linux touch или задайте свой вопрос.
Похожие
Подписаться на ленту
Для подписки на ленту скопируйте и вставьте эту ссылку в вашу программу для чтения RSS.
дизайн сайта / логотип © 2021 Stack Exchange Inc; материалы пользователей предоставляются на условиях лицензии cc by-sa. rev 2021.10.8.40416
Нажимая «Принять все файлы cookie» вы соглашаетесь, что Stack Exchange может хранить файлы cookie на вашем устройстве и раскрывать информацию в соответствии с нашей Политикой в отношении файлов cookie.
Источник
How can I change ‘change’ date of file?
How can I change the «change» date of a file? Using touch doesn’t work:
6 Answers 6
You cannot change the ctime by ordinary means. This is by design: the ctime is always updated to the current when you change any of the file’s metadata, and there is no way to impose a different ctime. To change the ctime of a file, you need to do one of the following:
- Set the system time to the ctime you want to impose, then touch the file, then reset the system time.
- Modify the kernel to add an interface to change the ctime.
- Access the disk image directly (e.g. with debugfs ) and twiddle the bits on the disk (don’t do it while the filesystem is mounted).
You have the answer on related SO question pointed by jw013, for extX, on unmounted disk :
The ctime of a file is updated when any of the metadata is changed.
$ NOW=$(date) && date -s «2030-08-15 21:30:11» && touch file.txt && date -s «$NOW»
evandrix’s answer excerpted in the next line,
NOW=$(date) && date -s «2030-08-15 21:30:11» && touch file.txt && date -s «$NOW»
needs to be improved as described below :
In some systems like mine, date output doesn’t give a valid format to set with date -s
My system bash shell version : GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
My system date command version : date (GNU coreutils) 8.30
My system date command output and setting the date with this format is:
So it is necessary to improve evandrix answer;
It would be better to assign the NOW variable to the timestamp value
change NOW=$(date) to NOW=$(date +@%s)
Adding sudo command for non root user
In this way for easy use, the filename and setting date are assigned as arguments at the end of the line.
Источник