LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 08: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 08:47 AM. Reason: properties = attributes
 
Old 06-18-2016, 09:07 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Try the find command?
 
Old 06-18-2016, 09:46 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
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, 10:45 AM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
[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 10:46 AM.
 
Old 06-18-2016, 12:33 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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, 04:11 PM   #6
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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 04:13 PM.
 
Old 06-18-2016, 04:40 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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 04:42 PM.
 
Old 06-18-2016, 04:44 PM   #8
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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



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 06:41 PM
[SOLVED] Errors executing shell script: "command not found" and "no such file or directory" eko000 Linux - Newbie 1 01-14-2011 07:54 AM
rkhunter warnings on "possible promiscuous interface" and file properties checks vinnie_vinodh Linux - Newbie 1 04-29-2009 02:44 AM
Command "mail" returns "panic: temporary file seek" kenneho Linux - Software 5 12-23-2008 03:27 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM

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

All times are GMT -5. The time now is 11:53 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
Open Source Consulting | Domain Registration