Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to find the files that have been modified recently or today in Linux

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to find out the recent or modified files in Linux, I believe most people do not know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. Let's learn about it together.

One of the common problems encountered by Linux users on the command line is to locate files with specific names, which may be much easier if you know a certain file name.

However, suppose you forget the name of the file you created earlier in the day (in your home folder that contains hundreds of files), but now you have an emergency.

The following lists only all the files you create or modify today (directly or indirectly) in different ways.

1. Use the ls command to list only today's files in your home folder.

# ls-al-- time-style=+%D | grep 'date +% D'

Where:

-a-lists all files, including hidden files

-l-enables long list format

-- time-style=FORMAT-displays the time of the specified FORMAT

+% D-display or use date in% m/%d/%y (month / day / year) format

Find the most recent file in Linux

In addition, you use the can-X flag to sort the results alphabetically:

# ls-alX-- time-style=+%D | grep 'date +% D'

You can also use the-S flag to sort based on size (from large to small):

# ls-alS-- time-style=+%D | grep 'date +% D'

2. In addition, using the find command is more flexible and provides more options than ls to achieve the same goal.

The-maxdepth level is used to specify the search level (subdirectory level) at the starting point of the search operation (in this case, the current directory).

-newerXY, a file whose timestamp X is newer than the timestamp Y of the referenced file. X and Y denote any of the following letters:-a-access time of the reference file-B-creation time of the reference file-c-inode state change time of the reference file-m-modification time of the reference file-t-specify an absolute time directly

The following command means to find only the files modified on 2016-12-06:

# find. -maxdepth 1-newermt "2016-12-06"

Find today's files in Linux

Important: use the correct date format as the reference time in the above find command. Once you use the wrong format, you will get the following error:

# find. -maxdepth 1-newermt "12-06-2016" find: I cannot figure out how to interpret'12-06-2016'as a date or time

Or, use the following correct format:

# find. -maxdepth 1-newermt "12 Universe 06 Universe 2016" or # find. -maxdepth 1-newermt "12-06-16"

The above is all the contents of the article "how to find the most recent or modified files in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 246

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report