Linux find jpg and sort by date

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Linux find jpg and sort by date
# 1  
Old 02-06-2018
Linux find jpg and sort by date

I want to find all jpg files and then sort them by modification date. This is where I started.

Code:
find . -type f -name "*.jpg"

I tried to pipe a sort in there but that did not seem to work. Do I need to use xargs?
# 2  
Old 02-06-2018
As you know well, all threads in this forum should start with:
What shell are you using?
What operating system are you using?

The find utility is great for finding files that were last modified in specified ranges of dates relative to the current time or to a single given other file. It is not generally good for comparing dates of selected files. If you want a list of files in last modified time order and the files are all in one directory, the simple way is with ls:
Code:
ls -t *.jpg

to get a list of files with the most recently modified file first, or:
Code:
ls -rt *.jpg

to get a list of files with the most recently modified file last.

So, for this thread, are these files all located in the current directory? Or, are they located in the current directory and various subdirectories under it? If in subdirectories, are they all at the same level or are they present in directories with varying levels under the current directory? And, how many files are we talking about here?
# 3  
Old 02-07-2018
You allude you're using linux in the thread header; so your find version might provide the -ls and / or -printf option to yield the files' modification times for sorting.
# 4  
Old 02-07-2018
Quote:
Originally Posted by Don Cragun
As you know well, all threads in this forum should start with:
What shell are you using?
What operating system are you using?

The find utility is great for finding files that were last modified in specified ranges of dates relative to the current time or to a single given other file. It is not generally good for comparing dates of selected files. If you want a list of files in last modified time order and the files are all in one directory, the simple way is with ls:
Code:
ls -t *.jpg

to get a list of files with the most recently modified file first, or:
Code:
ls -rt *.jpg

to get a list of files with the most recently modified file last.

So, for this thread, are these files all located in the current directory? Or, are they located in the current directory and various subdirectories under it? If in subdirectories, are they all at the same level or are they present in directories with varying levels under the current directory? And, how many files are we talking about here?
Fedora
Bash

I thought all Linux/Unix distro has the find command. Is that correct?

I want to search my entire computer. I was trying to keep things simple until I figured out the correct command thats why I used "." instead of "/".
# 5  
Old 02-07-2018
Quote:
Originally Posted by cokedude
Fedora
Bash

I thought all Linux/Unix distro has the find command. Is that correct?

I want to search my entire computer. I was trying to keep things simple until I figured out the correct command thats why I used "." instead of "/".
All UNIX, Linux, and BSD systems come with a find utility. But some versions of find have additional primaries that are not specified by the standards and are not available on all systems (such as those mentioned by RudiC in post #3).

On Linux systems, you could use one of those extensions to have find print a timestamp and the pathname of the file and sort the output produced by find on the timestamp field to get what you want.

On other systems, you might be able to use a -exec command {} + primary to get similar results. The command you would need to execute to get that data would vary from system to system.
# 6  
Old 02-07-2018
I think that -printf is the way to go. How do you want your date formatted for sorting?

I try to avoid saying this, but because there are lots, have a look at the man page for find to see the -printf options, such as %T@ which should give you epoch time and %p for the file name, similar to this:-
Code:
$ find . -printf '%T@ %p\n' |sort -n
1468598452.8015045550 ./unix.267273
1469099367.4486924810 ./file
1469100780.3309757180 ./input_file
1469805378.8660758160 ./267560.awk
1472213536.2868345460 ./count_binary_ones_length
1473928430.3601179200 ./in_file
1473928450.3837659940 ./exlcude
1486047098.9868200550 ./nic-thread-starter
1486111917.7097520520 ./270776/third.sh
1486111950.7201366120 ./270776/first.sh
1486111961.6289332250 ./270776/second.sh
1486112897.4140065720 ./270776
1486468608.9861686310 ./grep_spaces_test
1497523515.7209519850 ./272988/query.txt
1497524690.3125581780 ./272988/list.txt
1497524690.6745528860 ./272988
1503566805.5129076610 ./273839
1506421269.4751714080 ./filename
1507629323.3051139490 ./code
1508408914.3578552190 ./long.xml
1509709907.2805843090 ./list1
1509709920.6723868540 ./list2
1510826780.6306387540 ./runasroot.sh
1515412336.1583844750 ./as7951.in
1515414517.2548585810 ./dc.bash
1515499084.4714352250 ./status.html
1515504964.6037726290 ./xx00
1517325854.0620988160 ./276758.in
1517325854.1210979050 .


Does that help? Maybe you need another format, but you then have to consider sort options. Of course, it depends on which OS and version you are running for the various flags for find.


Robin
# 7  
Old 02-07-2018
Another way to go might be the stat command, of which various versions exist across OS'. Linux version:
Code:
stat -c"%y %n" fi*
2018-02-02 14:22:22.143035263 +0100 file
2018-02-02 14:13:40.000000000 +0100 file~
2018-02-06 18:51:45.850714122 +0100 file1
2018-02-06 18:48:31.000000000 +0100 file1~

or
Code:
stat -c"%Y %n" fi*
1517577742 file
1517577220 file~
1517939505 file1
1517939311 file1~

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

2. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

3. Shell Programming and Scripting

Sort by name and date

nawk '$1=="Date" {d=$(NF-2);next} $1=="Queue" {q=$NF;next} $1=="Forms"{print q, $NF, d}' OFS='|' printfile.log I have this script working. Please let me know how to sort by Queue and then Date. (4 Replies)
Discussion started by: Daniel Gate
4 Replies

4. Shell Programming and Scripting

Having trouble with find rename jpg command

Hi, I have a large series of directories and subdirectories with many jpgs in them. I need to do two things: 1. Create a copy of each jpg found within it's own subdirectory 2. Rename this copied jpg such that apple.jpg becomes apple_m.jpg I have tried to run the following commands in... (1 Reply)
Discussion started by: atharvan13
1 Replies

5. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

6. Shell Programming and Scripting

sort the date

Hi All, Please help me to sort the date field which is in the format 2012-02-03 16:09:37.388... Platform: Red Hat linux Thanks in advance (2 Replies)
Discussion started by: jesu
2 Replies

7. Shell Programming and Scripting

Rename all ".JPG" files to ".jpg" under all subfolders...

Hi, Dear all: One question ! ^_^ I'm using bash under Ubuntu 9.10. My question is not to rename all ".JPG" files to ".jpg" in a single folder, but to rename all ".JPG" files to ".jpg" in all subfolders. To rename all ".JPG" to ".jpg" in a single folder, for x in *.JPG; do mv "$x"... (7 Replies)
Discussion started by: jiapei100
7 Replies

8. Shell Programming and Scripting

find jpg's mkdir script help

I am having a problem getting this to work right. The script needs to search through directories and subdirectories. If a jpg is found then create a folder in that directory, so on and so forth. Here is what I have so far but it doesn't work right. Help please #!/bin/bash for d in `find ./... (1 Reply)
Discussion started by: jedhypes
1 Replies

9. Shell Programming and Scripting

how to sort by the date

Hello World~ Please Help Me(BASH) input: dde,2007.8.25,891 dde,2007.8.23,356 dfe,2007.10.12,341 cba,2005.12.5,342 I wanna know how to sort by the date(2005.12.5) output: cba,2005.12.5,342 dde,2007.8.23,356 dde,2007.8.25,891 dfe,2007.10.12,341 Thanks in advance (3 Replies)
Discussion started by: lifegeek
3 Replies

10. Shell Programming and Scripting

Sort by Date

I'm looking to edit a file which contains various data including date.(ddmmyyyy) I want to sort by date and then count the number of different dates found Any ideas how to acheive this Thanks in advance. (2 Replies)
Discussion started by: Mudshark
2 Replies
Login or Register to Ask a Question