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
# 8  
Old 02-07-2018
Quote:
Originally Posted by rbatte1
I think that -printf is the way to go. How do you want your date formatted for sorting?


Robin
Something like this if possible?

Code:
2018-02-02 ./file1.jpg
2018-02-02 ./file2.jpg

# 9  
Old 02-07-2018
Hmmm - my silver spoon for spoon feeding is in the dish washer momentarily. Quick, quick - let me dash out to get it for you ...
How about
Code:
find . -name "*.jpg" -printf "%TY-%Tm-%Td %p\n"

This User Gave Thanks to RudiC For This Post:
# 10  
Old 02-08-2018
If you have a version of bash or ksh that groks the globstar option:

ksh:
Code:
$ set -o | grep glob
glob                     on
globstar                 off
$ set -o globstar
$ set -o | grep glob
glob                     on
globstar                 on

bash:
Code:
$ shopt | grep glob
dotglob        	off
extglob        	on
failglob       	off
globstar       	off
globasciiranges	off
nocaseglob     	off
nullglob       	off
$ shopt -s globstar
$ shopt | grep glob
dotglob        	off
extglob        	on
failglob       	off
globstar       	on
globasciiranges	off
nocaseglob     	off
nullglob       	off

You can use:
Code:
ls -rtd **/*.jpg

This will find all instances of *.jpg under the current working directory and list them as you required. Note that I used the -d option to ls just in case somebody named a directory with a .jpg suffix.

You mention wanting to search the whole file system. If your system has the locate, or newer mlocate package installed consider this:
Code:
locate -b -e -0 '*.jpg' | xargs -0 ls -rtd

This works for my Ubuntu 16.04 release with mlocate 0.26. The -b option forces it to check against the basename of each file; -e to ignore non-existent files (possible if you deleted files since the last update of the mlocate database, which is normally done once a day).

Andrew
# 11  
Old 02-08-2018
Quote:
Originally Posted by apmcd47;303012730... ... ...
You mention wanting to search the whole file system. If your system has the [ICODE
locate[/ICODE], or newer mlocate package installed consider this:
Code:
locate -b -e -0 '*.jpg' | xargs -0 ls -rtd

This works for my Ubuntu 16.04 release with mlocate 0.26. The -b option forces it to check against the basename of each file; -e to ignore non-existent files (possible if you deleted files since the last update of the mlocate database, which is normally done once a day).

Andrew
Note that if you're trying to get a single list of files sorted by timestamps, anything that feeds the list to be processed to xargs is not going to achieve your goal. By definition, xargs will split the unsorted list of files into multiple sublists to be processed by executions of the target utility (ls -rtd in this case) and, although each execution will give you an ordered list, the concatenated lists produced by those multiple executions will not give you a list that is sorted by the last modification timestamps of all of the files in the list.
This User Gave Thanks to Don Cragun For This Post:
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