LinuxQuestions.org
Register a domain and help support LQ
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 02-18-2013, 08:04 PM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Rep: Reputation: 2
ls recursive AND last modified simultaneously


Hi, I wish to list the directories recursively and at the same time to have the order coming out as last modified:
Code:
sh-3.2# ls -ltR
script:
total 44
-rwxr-xr-x 1 root root  108 Oct 11 17:08 login.sh
-rwxr-xr-x 1 root root 3108 Aug 22 03:13 forumtorrent.sh
-rw-r--r-- 1 root root  385 Apr  7  2012 transmission.py
-rwxr-xr-x 1 root root 1241 Feb 19  2012 blogrss.pl
-rwxr-xr-x 1 root root 1260 Feb 11  2012 signin.sh
-rwxr-xr-x 1 root root  272 Dec 19  2011 blog.sh
-rwxr-xr-x 1 root root  659 Dec 13  2011 forumadd.sh
-rwxr-xr-x 1 root root  392 Dec 13  2011 ftpbackup.sh
-rwxr-xr-x 1 root root 2089 Dec 13  2011 mailtoattachment.sh
-rwxr-xr-x 1 root root 1076 Nov 23  2011 ftpupload.sh
-rwxr-xr-x 1 root root 2179 Nov 19  2011 smbclient.sh

transmission:
total 208
-rwxr--r-- 1 root root   6969 Mar 26  2012 transmission-remote-cli.pod
-rwxr--r-- 1 root root  35147 Mar  5  2012 COPYING
-rwxr--r-- 1 root root    752 Mar  5  2012 NEWS
-rwxr--r-- 1 root root   2714 Mar  5  2012 README.md
-rwxr--r-- 1 root root  10512 Mar  5  2012 screenshot.png
-rwxr-xr-x 1 root root   3749 Mar  5  2012 transmission-remote-cli.1
-rwxr-xr-x 1 root root 139161 Mar  5  2012 transmission-remote-cli.py
If this is done, then the files in two directories are separated, and this is not what I want, I want to sort them seemlessly together:
Code:
-rwxr-xr-x 1 root root  108 Oct 11 17:08 login.sh
-rwxr-xr-x 1 root root 3108 Aug 22 03:13 forumtorrent.sh
-rw-r--r-- 1 root root  385 Apr  7  2012 transmission.py
-rwxr--r-- 1 root root   6969 Mar 26  2012 transmission-remote-cli.pod
-rwxr--r-- 1 root root  35147 Mar  5  2012 COPYING
-rwxr--r-- 1 root root    752 Mar  5  2012 NEWS
-rwxr--r-- 1 root root   2714 Mar  5  2012 README.md
-rwxr--r-- 1 root root  10512 Mar  5  2012 screenshot.png
-rwxr-xr-x 1 root root   3749 Mar  5  2012 transmission-remote-cli.1
-rwxr-xr-x 1 root root 139161 Mar  5  2012 transmission-remote-cli.py
-rwxr-xr-x 1 root root 1241 Feb 19  2012 blogrss.pl
-rwxr-xr-x 1 root root 1260 Feb 11  2012 signin.sh
-rwxr-xr-x 1 root root  272 Dec 19  2011 blog.sh
-rwxr-xr-x 1 root root  659 Dec 13  2011 forumadd.sh
-rwxr-xr-x 1 root root  392 Dec 13  2011 ftpbackup.sh
-rwxr-xr-x 1 root root 2089 Dec 13  2011 mailtoattachment.sh
-rwxr-xr-x 1 root root 1076 Nov 23  2011 ftpupload.sh
-rwxr-xr-x 1 root root 2179 Nov 19  2011 smbclient.sh
Something close to this.
Thanks,
Ted

Last edited by ted_chou12; 02-18-2013 at 08:05 PM.
 
Old 02-18-2013, 09:10 PM   #2
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Original Poster
Rep: Reputation: 2
After some research and trials:
Code:
find . -type f  -printf "%T+\t%p\n" | sort | sed 's/^.*\s.\///i'
It seems a lot more trivial than I thought it would be though.
 
Old 02-18-2013, 09:34 PM   #3
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 979
Blog Entries: 2

Rep: Reputation: 235Reputation: 235Reputation: 235
Code:
#! /usr/bin/perl -w
    eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
        if 0; #$running_under_some_shell

use File::Find ();

# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name   = *File::Find::name;
*dir    = *File::Find::dir;
*prune  = *File::Find::prune;

sub wanted;

%mstamp=();
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '.');
foreach my $f (sort {$mstamp{$b} <=> $mstamp{$a}} keys %mstamp){
    system("ls", "-ld", $f);
}
exit;

sub wanted {
    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
    $atime,$mtime,$ctime,$blksize,$blocks)=();

    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
    $atime,$mtime,$ctime,$blksize,$blocks)=lstat($_);
    return unless (-f _);
    $mstamp{$name}=$mtime;
}
 
Old 02-19-2013, 12:12 AM   #4
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Original Poster
Rep: Reputation: 2
Thanks for your solution, ill post the test result when i get back.
 
  


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
Need a command to find the files modified after a date with recursive with folder musammil123 Linux - General 2 01-12-2012 01:12 AM
playing 2 files simultaneously ciopi Linux - Software 4 12-04-2005 01:43 AM
Two users on 1 PC simultaneously (with X) technobeast Linux - Newbie 1 07-10-2004 07:24 AM
How do I open a second X simultaneously? bruno buys Linux - Software 12 04-05-2004 01:37 PM
Login simultaneously juno Linux - General 2 09-26-2002 10:01 PM


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