Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
07-04-2017, 08:38 AM
|
#1
|
Member
Registered: Oct 2009
Location: Los Angeles, CA
Distribution: Centos 5.x
Posts: 133
Rep:
|
Finding files created after 01-01-2017
For the life of me I cannot remember the command to find files created in the year 2017. I know that there are numerous was but as I recall it was a 'find' command and possibly used '-mtime'.
Thanks in advance.
|
|
|
07-04-2017, 09:20 AM
|
#2
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
Entering linux find files year in Google Search returns the following page:
https://unix.stackexchange.com/quest...-based-on-year
which suggests:
Quote:
find /media/WD/backup/osool/olddata/ -newermt 20120101 -not -newermt 20130101
|
for 2012 (modify as necessary).
|
|
|
07-04-2017, 10:03 AM
|
#3
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,600
|
The specifics for that would be in the manual page for find under -newerXY. In the above example, X is m to check the modification time and Y is t to reference a time string.
|
|
|
07-04-2017, 06:44 PM
|
#4
|
Member
Registered: Oct 2009
Location: Los Angeles, CA
Distribution: Centos 5.x
Posts: 133
Original Poster
Rep:
|
This is on CentOS 6.9 and fails.
Quote:
find: invalid predicate `-newermt'
|
is of little help to a newbie... I've already scoured Google and cannot find the prior solutons.
|
|
|
07-04-2017, 06:58 PM
|
#5
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
Entering find invalid predicate in Google Search returns the following page:
https://stackoverflow.com/questions/...-using-newermt
which suggests that your operating system may not support -newermt, in which case you can use -newer and compare the dates against two files for which you have set the modification dates.
|
|
|
07-04-2017, 07:54 PM
|
#6
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,415
|
Just a minor point, but *nix filesystems don't (usually) store create date
Quote:
Three fields in the inode structure contain the last access, change, and modification times: atime, ctime, and mtime. The atime field is updated each time the pointer to the file's data blocks is followed and the file's data is read. The mtime field is updated each time the file's data changes. The ctime field is updated each time the file's inode changes. The ctime is not creation time; there is no way under standard Unix to find a file's creation time.
|
Perl Cookbook
The 'find' cmd allows you to specify which one you want to use.
|
|
|
07-04-2017, 08:11 PM
|
#7
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
Quote:
Originally Posted by chrism01
Just a minor point, but *nix filesystems don't (usually) store create date.
|
Just to add some info, the ext4 filesystem's extended inodes do include crtime, which stores the file creation time.
|
|
|
07-05-2017, 12:48 AM
|
#8
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,600
|
Quote:
Originally Posted by krazybob
This is on CentOS 6.9 and fails.
is of little help to a newbie...
|
Right. But it is of some help, and the goal is to move forward even if in small steps. What did the manual page show in regards to -newerXY for your CentOS 6.x? Your choices are limited to what the documentation on your machine shows.
If -newer is the only such option, then you'll have to touch two files with custom dates and then use -newer and \! -newer instead.
Code:
touch --date=20170601 start.foobar
touch --date=20170630 end.foobar
find /some/dir/ -type f -newer start.foobar \! -newer end.foobar -print
The backslash \ is there to escape the exclation mark ! so that it is passed to find instead of being processed by the shell. In the shell it is a special symbol that would cause other actions to be taken.
|
|
|
07-05-2017, 06:38 AM
|
#10
|
Member
Registered: Oct 2009
Location: Los Angeles, CA
Distribution: Centos 5.x
Posts: 133
Original Poster
Rep:
|
But this server is a EXT3 system. I appreciate the help by man find is as helpful as telling a blind man that the 7-11 down on the corner on the left. Maybe he can smell the nachos. Bad example but hopefully you get my point.
I was once a prolific programmer. But with Linux and the plethora of command line switches make learning a struggle for me. Which ones work with others? Etc. I'm struggling. My newest server using Centos 6.9. I am trying to clean out all of the sites that have been hacked and used to build websites within web sites. Alibaba. They hide files everywhere.
|
|
|
07-05-2017, 06:47 AM
|
#11
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,600
|
Quote:
Originally Posted by krazybob
Which ones work with others?
|
That's what the manual pages are for. They are how you navigate the system. They are references to look up stuff in and are terse as references should be.
Quote:
Originally Posted by krazybob
Etc. I'm struggling. My newest server using Centos 6.9. I am trying to clean out all of the sites that have been hacked and used to build websites within web sites. Alibaba. They hide files everywhere.
|
Sorry to hear that. Yes, once they are in they can and do hide files everywhere. Figure out how they got in ...
But once they have gotten in you have one option and one option only: backup your data again, backup your logs, reformat and do a fresh but locked down install of CentOS. What kind of recovery plan do you have on file?
|
|
|
07-05-2017, 10:10 AM
|
#12
|
Member
Registered: Oct 2009
Location: Los Angeles, CA
Distribution: Centos 5.x
Posts: 133
Original Poster
Rep:
|
This works
Code:
touch --date "2017-12-01" /tmp/start
touch --date "2017-12-31" /tmp/end
find . -type f -newer /tmp/start -not -newer /tmp/end
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 03:00 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|