LinuxQuestions.org
Review your favorite Linux distribution.
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 10-05-2012, 04:19 PM   #1
rokyo
Member
 
Registered: Oct 2012
Posts: 74

Rep: Reputation: Disabled
How do I make "ls" output the full path


Hello,

I was wondering if there is any way to make "ls" output the full path to the files it finds.

I know, there is the "find" command, which does just that. But my problem is that "find" does not output the dates on which the files where created, like "ls" does.

What I want to do is list all .JPG files in all subdirectories of my home folder which were created in Feb 2012 and which contain "IMG" in their name and write the files found into a .TXT file.

What I did so far is:

Code:
ls -hlR | grep Feb | grep 2012 | grep IMG | grep JPG >> febpix.txt
but that doesn't give the full path to the files that are found.

I also tried redirecting the contents of febpix.txt to "find" but the way I do it is not right, apparently:

Code:
ls -hlR | grep Feb | grep 2012 | grep IMG | grep JPG >> febpix.txt && cat febpix.txt | find >> febpix_fullpath.txt

Any ideas? ^^

Thank you in advance fort your advice!

rokyo
 
Old 10-05-2012, 04:39 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
Quote:
Originally Posted by rokyo View Post
I know, there is the "find" command, which does just that.
And it is preferable.


Quote:
Originally Posted by rokyo View Post
But my problem is that "find" does not output the dates on which the files where created, like "ls" does.
'man find': "-ctime", also see "-printf". Note UNIX specification says "change time", not "creation time".


Quote:
Originally Posted by rokyo View Post
What I want to do is list all .JPG files in all subdirectories of my home folder which were created in Feb 2012 and which contain "IMG" in their name and write the files found into a .TXT file.
Code:
find /home/rokyo/somefolder -type f \( -name \*IMG\* -a -iname \*.jpg \) -printf "%TY%Tm#%p\n"|awk -F'#' '/201202#/ {print $2}' >> ~/febpix.txt
 
1 members found this post helpful.
Old 10-05-2012, 04:47 PM   #3
Fred Caro
Member
 
Registered: May 2007
Posts: 999

Rep: Reputation: 166Reputation: 166
rokyo,
what do you want to be the output of 'ls -hlR' to be before you redirect it?

Fred.
 
Old 10-05-2012, 04:56 PM   #4
rokyo
Member
 
Registered: Oct 2012
Posts: 74

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Fred Caro View Post
rokyo,
what do you want to be the output of 'ls -hlR' to be before you redirect it?

Fred.
The output of ls -hlR, when run from my home directory, should be every file in every subdirectory of my /home. Which I then redirect to a couple of "grep"s to get only the jpgs which contain "IMG" in their name and which where created in Feb 2012. So far it works, too. But just not with a full path to the files.
 
Old 10-05-2012, 05:01 PM   #5
rokyo
Member
 
Registered: Oct 2012
Posts: 74

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by unSpawn View Post
And it is preferable.



'man find': "-ctime", also see "-printf". Note UNIX specification says "change time", not "creation time".



Code:
find /home/rokyo/somefolder -type f \( -name \*IMG\* -a -iname \*.jpg \) -printf "%TY%Tm#%p\n"|awk -F'#' '/201202#/ {print $2}' >> ~/febpix.txt
Thanks, this worked!
 
Old 10-07-2012, 06:53 PM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
You probably don't want ctime. That's just the last time the file's metadata changed; i.e. filename, permissions. mtime, the last time the files's contents were modified, is the closest thing *nix has traditionally had to a creation date.

There is a new crtime (creation time) field that was recently introduced and a few file systems like ext4 support it. But most system tools have yet to be updated to take advantage of it, and so it remains generally unused and unusable at this time. Give it a few more years, perhaps.
 
  


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
How do you make "/dev/dsp1" the default Audio Output Device? lothario Linux - Software 1 02-16-2011 04:01 AM
square brackets in output of "ps aux" not matching output of "ps -ejH" alirezan1 Linux - Newbie 14 07-14-2010 05:17 AM
output the path for files whose names include string "string" (case insensitive) sean_zhang Linux - Newbie 1 03-05-2008 12:59 AM
want full description of "echo num > / path/...." zameer_india Linux - Newbie 5 01-08-2005 04:10 AM
Is it possible to make a "file" that can change its output when accessed? oot Linux - General 5 05-11-2003 09:30 PM


All times are GMT -5. The time now is 04:15 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