LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 02-18-2013, 07:04 PM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 431
Blog Entries: 32

Rep: Reputation: 3
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 07:05 PM.
 
Old 02-18-2013, 08:10 PM   #2
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 431

Original Poster
Blog Entries: 32

Rep: Reputation: 3
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, 08:34 PM   #3
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
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-18-2013, 11:12 PM   #4
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 431

Original Poster
Blog Entries: 32

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


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

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

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