- Linux Find Files By Date And List Files Modified On a Specific Date
- ls command example to find files by date
- find Command Example
- Linux find file by date using the date command
- Say hello to -newerXY option for find command
- To see all files modified on the 24/Sep/2017 in the current directory:
- 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
- joostvanveen / linux_find_size_modified_date_and_remove_files.sh
- Date Command in Linux: How to Set, Change, Format and Display Date
- Linux date Command Syntax
- How to Use date Command in Linux
- Linux date Command Format Options
- Set or Change Date in Linux
- Display Past Dates
- Display Future Dates
- Display the Date String at Line of File
- Display Last Modified Timestamp of a Date File
- Override a Time Zone
- Use date with Other Commands
- Use Unix Epoch Time (Epoch Converter)
Linux Find Files By Date And List Files Modified On a Specific Date
H ow do I find files by date under UNIX and Linux system? How search for files that created on a specific date on Linux or Unix-like system? How to get a list all files that have been modified on a specific date on Linux or Unix?
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | No |
Requirements | Linux or Unix |
Est. reading time | 4 mintues |
Linux and UNIX like operating systems do not store file creation time. However, you can use file access and modification time and date to find out file by date. For example, one can list all files that have been modified on a specific date.
Let us see how to find file by date on Linux. You need to use the ls command and find command.
ls command example to find files by date
The syntax is as follows:
You need to use the grep command/egrep command to filter out info:
$ ls -lt /etc/ | grep filename
ls -lt /etc/ | grep ‘Jun 20’
A better and recommended solution is the find command:
find . -type f -ls |grep ‘2017’
find . -type f -ls |grep ‘filename’
find /etc/ -type f -ls |grep ’25 Sep’
find Command Example
If you need a specific date range many days ago, than consider using the find command. In this example find files modified between Jan/1/2007 and Jan/1/2008, in /data/images directory:
You can save list to a text file called output.txt as follows:
find /data/images -type f -newer /tmp/start -not -newer /tmp/end > output.txt
Linux find file by date using the date command
Gnu find as various command line option to list files by a modification and access date/time stamp.
Say hello to -newerXY option for find command
The syntax is as follows:
find /dir/ -type f -newerXY ‘yyyy-mm-dd’
find /dir/ -type f -newerXY ‘yyyy-mm-dd’ -ls
The letters X and Y can be any of the following letters:
- a – The access time of the file reference
- B – The birth time of the file reference
- c – The inode status change time of reference
- m – The modification time of the file reference
- t – reference is interpreted directly as a time
To see all files modified on the 24/Sep/2017 in the current directory:
find . -type f -newermt 2017-09-24
## pass the -ls option to list files in ls -l format ##
find . -type f -newermt 2017-09-24 -ls
OR
find . -type f -newermt 2017-09-24 ! -newermt 2017-09-25
find . -type f -newermt 2017-09-24 ! -newermt 2017-09-25 -ls
Sample outputs:
Источник
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.
Источник
joostvanveen / linux_find_size_modified_date_and_remove_files.sh
# # NOTE: when finding file by time, use one of the following flags: |
# ctime : the time a file was changed, in hours. On most systems this timestamp cannot be altered by any user, so it is fairly reliable |
# atime : the time a file was last accessed, in hours. This is also set by the system. |
# mtime : the modified time of a file, in hours. This can be set by any user. So if you are looking for mailcious files, never use this flag. |
# cmin : same as mtime, but in minutes. |
# amin : same as atime, but in minutes. |
# mmin : same as mtime, but in minutes. |
# Find all files in current directory changed more than 8 hours ago (480 minutes) |
find $PWD -mindepth 1 -type f -cmin +480 |
# Find all files in current directory modified more than 31 days ago |
find $PWD -mindepth 1 -type f -ctime +31 |
# Find all files in current directory modified in the last 2 days, exclude any cache, log and media folders |
find data/web/ -type f -ctime -2 -not -path » */cache/* » -not -path » */log/* » -not -path » */media/* » -not -path » */session/* « |
# LIST filename and modified date of all files in current directory modified more than 8 hours ago (480 minutes) |
find $PWD -mindepth 1 -type f -cmin +480 -exec stat -c » %n %y » <> \; |
# LIST filename and modified date and highlight modified date of all files in current directory modified more than 8 hours ago (480 minutes) |
find $PWD -mindepth 1 -type f -cmin +480 -exec stat -c » %n %y » <> \; | grep ‘ 9\<4\>-7\<2\>-7\ <2\>8\<2\>:7\<2\>:8\ <2\>‘ |
# Find 10 largest folders |
du -hsx * | sort -rh | head -10 |
# Find 10 largest folders, but do not list their subfolders |
du -hx —max-depth=0 * | sort -rh | head -10 |
# Find 10 largest folders, and also list their subfolders 1 level deep |
du -hx —max-depth=1 * | sort -rh | head -10 |
# Find 10 largest files and display size in a human readable way |
find . -type f -exec du —human <> + | sort —human —reverse | head -10 |
# Find largest log files in current directory |
find $PWD -name ‘ *.log ‘ -type f -exec ls -lh <> + | sort -nr | head -10 |
# — DELETE . —— all files modified more than 8 hours ago (480 minutes), recursively from the current directory |
find $PWD -mindepth 1 -type f -cmin +480 -exec rm <> \; |
# Find used disk space |
df -h |
# Find any line in a file that does NOT contain a certain string, for instance ‘Magento’ |
cat somefile.log | grep -v ‘ Magento ‘ |
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник
Date Command in Linux: How to Set, Change, Format and Display Date
Home » SysAdmin » Date Command in Linux: How to Set, Change, Format and Display Date
Linux date command displays and sets the system date and time. This command also allows users to print the time in different formats and calculate future and past dates.
Read on to learn how to use the date command in Linux.
- A system running Linux
- A user account with root privileges
- Access to a terminal window/command line
Linux date Command Syntax
The syntax for the date command is:
How to Use date Command in Linux
To show the current system time and date, type in the date command:
The output displays the day of the week, day of the month, month, year, current time, and time zone. By default, the date command is set to the time zone of the operating system.
The -d option allows users to operate on a specific date. For example, we can type in the following command:
You can use the —date command to display the given date string in the format of a date. This command does not affect the system’s actual date and time values, and it only prints the requested date. For example:
Linux date Command Format Options
To format the date command’s output, you can use control characters preceded by a + sign. Format controls begin with the % symbol and are substituted by their current values.
Here, the %Y character is replaced with the current year, %m with month, and %d with the day of the month:
Here are another two formatting examples:
These are the most common formatting characters for the date command:
-
- %D – Display date as mm/dd/yy
- %Y – Year (e.g., 2020)
- %m – Month (01-12)
- %B – Long month name (e.g., November)
- %b – Short month name (e.g., Nov)
- %d – Day of month (e.g., 01)
- %j – Day of year (001-366)
- %u – Day of week (1-7)
- %A – Full weekday name (e.g., Friday)
- %a – Short weekday name (e.g., Fri)
- %H – Hour (00-23)
- %I – Hour (01-12)
- %M – Minute (00-59)
- %S – Second (00-60)
To see all formatting options, run date —help or the man command man date in your terminal.
Set or Change Date in Linux
To change the system clock manually, use the —set command. For example, to set the date and time to 5:30 PM, May 13, 2010, type:
Most Linux distributions have the system clock synchronized using the ntp or the systemd-timesyncd services, so be careful when the setting the clock manually.
Display Past Dates
Use the —date option to display past dates in Linux. The date command accepts values such as «tomorrow» , «Friday» , «last Friday» , «next Friday» , «next week» , and similar. So, use the following strings to print past dates::
Display Future Dates
The —date option can also display future dates. Like with past dates, you can type in strings to print upcoming dates:
Display the Date String at Line of File
The —file option prints the date string present at each line of the file. Unlike the —date option, —file can present multiple date strings at each line.
This is the syntax for the —file command:
Here we use the cat command to add dates to a file and then print them with the date command:
Display Last Modified Timestamp of a Date File
When you use the -r option, the date command prints the last modification time of a file. For example, the following command prints the last time the hosts file was changed:
Override a Time Zone
By default, the date command uses the time zone defined in /etc/localtime . To use a different time zone in the environment, set the TZ variable to the desired time zone.
For example, to switch to New York time, enter:
Type in the date command to return the system to its default time zone. To see all available time zones, use the timedatectl list-timezones command.
The date command can also show the local time for a different time zone. For example, to display the local time for 4:30 PM next Monday on the Australian east coast, type:
Use date with Other Commands
You can use the date command to create file names that contain the current time and date. The input below creates a backup MySQL file in the format of the current date:
Another common use of the date command is in shell scripts. Below we assign the output of date to the date_now variable:
Use Unix Epoch Time (Epoch Converter)
You can use the date command as an Epoch converter. Epoch, or Unix timestamps, is the number of seconds that have passed since January 1, 1970, at 00:00:00 UTC.
To show the number of seconds from the epoch to the current day, use the %s format control:
To see how many seconds passed from epoch to a specific date, enter:
You now have a good understanding of how to use the date command in Linux. If you are interested in more date/time configuration options for Linux, read How to Set or Change Timezone/Date/Time on Ubuntu.
Источник