- How to Get Last Modified Date of File in Linux
- 1. Using stat command
- 2. Using date command
- 3. Using ls -l command
- 4. Using httpie
- Output
- Conclusion
- More Articles You May Like
- 1 thought on “How to Get Last Modified Date of File in Linux”. add one
- How to find recently modified files in Linux
- How to check all timestamps of a file?
- 1) Sorting files & folders based on conversion time
- 2) Sorting only folders based on conversion time
- 3) How to find only files that were modified 120 days ago
- 4) How to find only files that were modified in last 15 days
- 5) How to find only files that were modified exactly 10 days ago
- 6) How to find only files that were modified within last 30 Mins
- 7) How to find only the folder’s modified in last 5 Days
- 8) How to find both Files and Folders that were modified in last 15 Days
- 9) How to find modified files and folders starting from a given Date to the latest Date
- 10) How to find all files and folders modified in the Last 24 Hours
- 11) How to find a list of “sh” extension files accessed in the Last 30 Days
- 12) How to find files that have been modified over a period of time
- 13) How to find a list of files created Today
- Closing Notes
- How to find recently modified files on Linux
- Support Xmodulo
- How to Find Recent or Today’s Modified Files in Linux
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- Get Last Modified Date of File in Linux
- 7 Answers 7
How to Get Last Modified Date of File in Linux
Sometimes, you may be required to check detailed information about a file (timestamp) such as its last modified date. This can come in handy when you want to check when the file was last edited. Additionally, it ensures that you have the latest version of the file.
In this article, you will learn 4 ways to get the last modified date of file in Linux.
1. Using stat command
The ls -l command is just okay in giving you basic information about a file such as file ownership and permissions, file size, and creation date. The stat command returns detailed information file attributes such as the last time the file was accessed and modified.
The syntax is quite simple. stat is followed by the file name or the full path to the file.
From the above output, we can clearly see when the file was last accessed ( Access date ), Modify date, Change date among other parameters.
If you wish to view the modified date only and leave out all the other information, run the following command:
The -c option is used to return the date in a custom format, while the ‘%y’ flag displays the last modification time. For directories, the syntax remains the same. Simply replace the file name with that of the directory.
2. Using date command
The date command in its basic syntax displays the current date. However, when used with the -r option, you can display the last modification date of a file as shown.
3. Using ls -l command
The ls -l command is usually used for long listing — display additional information about a file such as file ownership and permissions, size and creation date. To list and display the last modified times, use the lt option as shown.
4. Using httpie
Another way you can check the last modified date is by using the httpie HTTP command-line client tool. The tool is usually used for interacting with HTTP servers and APIs and can also check when a file residing on a web server was last modified.
But first, you need to install it using the command:
On Ubuntu / Debian / Mint, run the command:
To check when a file on a web server was last modified, use the syntax:
Output
Conclusion
This wraps up this article. In this guide, we have featured various ways that you can use to list the last modified date of a file on a Linux system, and even a file hosted on a web server using the httpie tool. Hopefully, you won’t have an issue viewing when files were last modified.
More Articles You May Like
1 thought on “How to Get Last Modified Date of File in Linux”. add one
I prefer using ‘ls’ over all the others because ls allows you to control precisely how the date and time are displayed. I believe stat only gives the choice between seconds-since-epoch and human-readable, with no control over the human-readable format.
For ls, the relevant option is ‘—time-style’ and its format specifiers are fairly straightforward, using the same specifiers used by /bin/date. See ‘man date’ for all the available specifiers. My personal favorite is —time-style=»+%Y-%m-%d %H:%M:%S». I use this alias for my day-to-day ls needs.
alias l=»/bin/ls —time-style=\»+%Y-%m-%d %H:%M:%S\» —group-directories-first -lLFAGv»
Источник
How to find recently modified files in Linux
If you are working on thousands of files a day and want to find a list of files that have been modified recently in a directory for certain purposes, this can be done easily using the find command.
The find command is used to search or locate files based on various criteria such as timestamp, file type and file permissions in Linux.
Please refer to our previous article on how to find a directory size in Linux.
In this article, we have included 13 examples for locating files based on timestamp and I hope this article will meet your needs.
In Linux, a file contains three timestamps, which are updated when a file is accessed or modified or replaced.
Types of file timestamps:
- atime: access time or Last access time
- mtime: modify time or Last modification time
- ctime: change time or Last change time
Read the below explanation for better understanding about timestamp.
- atime/amin: The last time the file was accessed by some command or application.
- mtime/mmin: The last time the file’s contents was modified.
- ctime/cmin: The last time the file’s attribute was modified.
How to check all timestamps of a file?
It can be easily seen using ‘stat’ command, which displays all three timestamps of a file.
The common syntax is as follows:
We can use numerical arguments with ‘mtime’. Use “-mtime n” command to return a list of files that were last modified “n” hours ago.
- +n: for greater than n
- -n: for less than n
- n: for exactly n
See the format below for a better understanding.
- -mtime +10: This will find all files that were modified 10 days ago.
- -mtime -10: It will find all files that were modified in the last 10 days.
- -mtime 10: Use this format to find all files that were modified EXACTLY 10 days ago.
1) Sorting files & folders based on conversion time
This can be done by using the ls command with some options as shown below, which sorts the files and folders in reverse order based on the conversion time.
2) Sorting only folders based on conversion time
Use the following format to sort only folders in reverse order based on conversion time.
3) How to find only files that were modified 120 days ago
The below find command will show a list of files that were changed 120 days ago.
4) How to find only files that were modified in last 15 days
The below find command will show a list of files that have changed in the last 15 days:
5) How to find only files that were modified exactly 10 days ago
The below find command will show you a list of files that were changed exactly 10 days ago:
6) How to find only files that were modified within last 30 Mins
The below find command will show a list of files that have changed within the last 30 mins.
7) How to find only the folder’s modified in last 5 Days
This command displays only folders modified within the last 5 days.
8) How to find both Files and Folders that were modified in last 15 Days
This command displays a list of files and folders modified within last 15 days:
9) How to find modified files and folders starting from a given Date to the latest Date
This command allows you to find a list of files and folders that have been modified starting from a given date to the latest date:
10) How to find all files and folders modified in the Last 24 Hours
Alternatively, you can use an easy-to-understand format like the one below to find files and folders that have changed over the past 24 hours.
11) How to find a list of “sh” extension files accessed in the Last 30 Days
This command helps you to find a list of files with “sh” extension accessed in the last 30 days.
12) How to find files that have been modified over a period of time
The below command shows a list of files that have changed in the last 20 minutes.
13) How to find a list of files created Today
This command enables you to find a list of files created today:
Closing Notes
This article explained how to find recently modified files & folders in Linux.
If you have any questions or feedback, feel free to comment below.
Источник
How to find recently modified files on Linux
Last updated on September 27, 2020 by Dan Nanni
There are various occasions where you would like to search for files that have been changed/created in your Linux system recently or within any time frame. For example, as a system admin, you have done some configuration on your Linux system, but forgot where it was saved. You want to verify whether/how your Linux file system has been tampered with by someone recently. If you would like to find recently updated files on Linux, you can use find command as follows.
To find the most recently modified files, sorted in the reverse order of update time (i.e., the most recently updated files first):
The above command sorts files in /etc (and all its subdirectories), in the reverse order of their update time, and prints out the sorted list, along with their location and update time. If you want to examine directories as well, you can omit -type f option in the command.
To search for files in /target_directory and all its sub-directories, that have been modified in the last 60 minutes:
To search for files in /target_directory and all its sub-directories, that have been modified in the last 2 days:
To search for files in /target_directory and all its sub-directories no more than 3 levels deep, that have been modified in the last 2 days:
You can also specify the range of update time. To search for files in /target_directory and all its sub-directories, that have been modified in the last 7 days, but not in the last 3 days:
All these commands so far only print out the locations of files that are matched. You can also get detailed file attributes of recently modified files, using -exec option as follows.
To search for files in /target_directory (and all its sub-directories) that have been modified in the last 60 minutes, and print out their file attributes:
Alternatively, you can use xargs command to achieve the same thing:
Note that files that have been created within the specified time frame will also matched by these commands.
Support Xmodulo
This website is made possible by minimal ads and your gracious donation via PayPal (Credit Card) or Bitcoin ( 1M161JGAkz3oaHNvTiPFjNYkeABox8rb4g ).
Источник
How to Find Recent or Today’s Modified Files in Linux
In this article, we will explain two, simple command line tips that enable you to only list all today’s files.
One of the common problems Linux users encounter on the command line is locating files with a particular name, it can be much easier when you actually know the filename.
However, assuming that you have forgotten the name of a file that you created (in your home folder which contains hundreds of files) at an earlier time during the day and yet you need to use urgently.
Below are different ways of only listing all files that you created or modified (directly or indirectly) today.
1. Using the ls command, you can only list today’s files in your home folder as follows, where:
- -a – list all files including hidden files
- -l – enables long listing format
- —time-style=FORMAT – shows time in the specified FORMAT
- +%D – show/use date in %m/%d/%y format
Find Recent Files in Linux
In addition, you can sort the resultant list alphabetically by including the -X flag:
You can also list based on size (largest first) using the -S flag:
2. Again, it is possible to use the find command which is practically more flexible and offers plenty of options than ls, for the same purpose as below.
- -maxdepth level is used to specify the level (in terms of sub-directories) below the starting point (current directory in this case) to which the search operation will be carried out.
- -newerXY , this works if timestamp X of the file in question is newer than timestamp Y of the file reference. X and Y represent any of the letters below:
- a – access time of the file reference
- B – birth time of the file reference
- c – inode status change time of reference
- m – modification time of the file reference
- t – reference is interpreted directly as a time
This means that, only files modified on 2016-12-06 will be considered:
Find Today’s Files in Linux
Important: Use the correct date format as reference in the find command above, once you use a wrong format, you will get an error as the one below:
Alternatively, use the correct formats below:
Find Todays Modified Files in Linux
You can get more usage information for ls and find commands in our following series of articles on same.
In this article, we explained two important tips of how to list only today’s files with the help of ls and find commands. Make use of the feedback form below to send us any question(s) or comments about the topic. You can as well inform us of any commands used for the same goal.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
Get Last Modified Date of File in Linux
I’m new to Linux. I’m using the command-line. I’m trying to view the last modified date of a file. How do I do that in Linux from the Command Line?
7 Answers 7
As mentioned by @edvinas.me, stat tells you various information about the file including the last modified date.
At first, I was confused with Modify and Change, just to clarify, stat output lists:
- Access shows the time of last data access (e.g. read).
- Modify shows the time of last data modification.
- Change shows the time the file status last changed.
Use stat command for that:
Another way that is more flexible is using date -r . From man date :
This has the advantage of allowing you to specify the output format, e.g.
ls -l should do the work.
Building off of @Adam Taylor ‘s comment in @phoops ‘s answer and @Sparhawk ‘s answer.
To specifically just get the date (using October 3, 2019 for examples because it was my last birthday, here’s my venmo if you feel led to bless me financially: @levi_uzodike)
- stat -c %y file | cut -d’ ‘ -f1 will give you 2019-10-03
- date +%F -r file will also give you 2019-10-03
- date +%D -r file will give you 10/03/19
- date +%x -r file will probably give either 10/03/2019 , or 10/03/19 if you’re in the U.S. and either 03/10/2019 , or 03/10/19 if you’re in the U.K., just to name a couple examples (of course there are more possibilities)
These date format options are, to my understanding, combinations of other format options. Here are some explanations from the man page:
%b locale’s abbreviated month name (e.g., Jan)
%B locale’s full month name (e.g., January)
.
%d day of month (e.g, 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
.
%m month (01..12)
.
%x locale’s date representation (e.g., 12/31/99)
.
%y last two digits of year (00..99)
%Y year
.
By default, date pads numeric fields with zeroes.
The following optional flags may follow `%’:
— (hyphen) do not pad the field
_ (underscore) pad with spaces
0 (zero) pad with zeros
^ use upper case if possible
# use opposite case if possible
N.B.: These flags don’t work on the «combo formats» like %F , %D and %x . They are for the «singular field formats«.
Apparently this last flag (#) does not work as I’d expect (e.g., if date +%b gives Oct , date +%#b gives OCT as opposed to oCT ) I guess this would be useless, but I’d think a lower case option would be more useful. date +%#p does turn date +%p which might give PM or AM into pm or am , respectively. So I guess it’s not a ‘per-character’ case switch but sets the case of all the characters in the string to the opposite case of the majority of the characters? Also date +%P gives pm or am , but neither date +%^P nor date +%#P change its output. My guess for this case is that %P is just an alias for %#p , and it seems that whenever you add more than one flag, the behavior is undefined/unpredictable ( e.g., date +%0-e gives the same as date +%-e : 3 and date +%-0e gives the same as date +%0e : 03 , which makes you think that only the flag next to the letter works or that it goes left to right, but both date +%#^p and date +%^#p give pm or am , [depending on the time of course] ) unless there’s some hidden order of operations? Sorry for digressing.
Also, if you run the command locale -k LC_TIME | grep ^d_fmt , you can see the combo for the specific locale of your system (e.g., d_fmt=»%m/%d/%Y» ).
And you can make your own combo. For example,
- date +%^b\ %-e\ %Y -r file will give you OCT 3 2019
Источник