LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 06-18-2016, 09:42 AM   #1
t@sh
LQ Newbie
 
Registered: Jun 2016
Posts: 1

Rep: Reputation: Disabled
Question Regarding equating file attributes in "ls" command


I have a folder in which there are thousands of images. Of those thousand images, I want to bring together all those images whose “Last created” and “Last modified” attributes are exactly same.
( In other words, I want to separate all the images I didn’t ever rename for example )

Is there a way to do this from terminal ?

these are the two commands that I want to concatenate
ls -tU lists file by creation date. (I'm on a mac)
ls -lt lists file by modified date

such that I want to
"List files whose date created = date modified"

Last edited by t@sh; 06-18-2016 at 09:47 AM. Reason: properties = attributes
 
Old 06-18-2016, 10:07 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,550

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Try the find command?
 
Old 06-18-2016, 10:46 AM   #3
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 2,620
Blog Entries: 3

Rep: Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155
If you are using a file system that supports "time of file birth" in "stat" then you can do it. But as far as I know, EXT4 and HFS+ don't. You can check with "stat" on a file:

Code:
stat -c "%Y %W" ./somefile
That will print out two numbers, if the second is zero then you cannot find the creation time of the file and you'll have to try a different approach. If the second number is not zero, then you can do it if you make "find" jump through some hoops with the option -exec and the program "test"
 
Old 06-18-2016, 11:45 AM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,393

Rep: Reputation: 409Reputation: 409Reputation: 409Reputation: 409Reputation: 409
[specific to OSX]

There is mdls command
Code:
mdls file..
You can select information with (for example)
Code:
mdls -name kMDItemFSCreationDate -name kMDItemFSContentChangeDate file...
But really I think you should just compare last modified with last changed, which is more meaningfull imo
Code:
stat -f "%m %c" file...

Last edited by keefaz; 06-18-2016 at 11:46 AM.
 
Old 06-18-2016, 01:33 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,711

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
The usual problem is that no two files are created at "exactly the same time".

If you look at the file dates using the stat command, you will see timestamps into the nanosecond range - thus the dates are almost guaranteed to be unique.

Depending on how the files are modified/backed up/restored the modified timestamp MAY be recorded to the second.

But the access/creation/birth (if recorded) will be to the nanosecond.
 
Old 06-18-2016, 05:11 PM   #6
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,393

Rep: Reputation: 409Reputation: 409Reputation: 409Reputation: 409Reputation: 409
Just tested in an OSX box, this seems to work:
Code:
cd directory
stat -f "%c:%a:%N" * | awk -F: '$1 != $2 {print $3}'
%c: time when the inode was last changed
%a: time when file was last accessed
%N: file name

Last edited by keefaz; 06-18-2016 at 05:13 PM.
 
Old 06-18-2016, 05:40 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,711

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
Quote:
Originally Posted by keefaz View Post
Just tested in an OSX box, this seems to work:
Code:
cd directory
stat -f "%c:%a:%N" * | awk -F: '$1 != $2 {print $3}'
%c: time when the inode was last changed
%a: time when file was last accessed
%N: file name
I don't know what you are looking for, but if you CHANGE a file, you are also ACCESSING the file...

Also note that some backup/restore facilities can set the changed and modification dates to whatever is desired...(see "touch" command), and neither has anything to do with created date (which is more properly called "inode modification date").

Last edited by jpollard; 06-18-2016 at 05:42 PM.
 
Old 06-18-2016, 05:44 PM   #8
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,393

Rep: Reputation: 409Reputation: 409Reputation: 409Reputation: 409Reputation: 409
I am looking at what was modified, but I was wrong

Quote:
Originally Posted by t@sh View Post

such that I want to
"List files whose date created = date modified"
So, awk expression becomes:
Code:
stat -f "%c:%a:%N" * | awk -F: '$1 == $2 {print $3}'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unpredictable "delete" "move to trash" or "cut" file menu option dorianrenato Linux - General 3 11-28-2011 07:41 PM
[SOLVED] Errors executing shell script: "command not found" and "no such file or directory" eko000 Linux - Newbie 1 01-14-2011 08:54 AM
rkhunter warnings on "possible promiscuous interface" and file properties checks vinnie_vinodh Linux - Newbie 1 04-29-2009 03:44 AM
Command "mail" returns "panic: temporary file seek" kenneho Linux - Software 5 12-23-2008 04:27 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration