LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-11-2006, 03:29 AM   #1
raf_iso
LQ Newbie
 
Registered: Jul 2005
Posts: 18

Rep: Reputation: 0
Arrow Bash script to browse directory with a custom output ?


Hello,

I need to browse a storage disk with almost 700GB of datas. There is a lot of directories.

I would like to make a script that browse all the structure and store it in a text file each night. Then I could make a little search program and it'll be much more faster than searching with the FIND command. Even store it in a mysql database.

I looked the docs about LS and TREE, but I can't get exactly what I want .

I need something like

Code:
[YYYY.MM.DD-HH:MM][SIZE][FULLPATH]
for exemple :

Code:
[2006.01.11-09:05][4096][./custom/]
[2005.12.30-18:15][23579][./custom/bruit_graph.png]
With this format it's easy to sort by last modification.

- TREE is great, but sometimes dates aren't well displayed.
- LS is nice too, but I can't find a parameter to display the fullpath for each files on one line like TREE with the recursive option.

Please can you help me ?

Thanks you for your help !

RB
 
Old 01-11-2006, 06:56 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
I think this comes quite close:
(only time is more verbose than what you're asking for)
Code:
find /your/path | xargs stat -c '[%y][%s][%n]'
See "man stat" for more possibilities.
 
Old 01-11-2006, 07:25 AM   #3
raf_iso
LQ Newbie
 
Registered: Jul 2005
Posts: 18

Original Poster
Rep: Reputation: 0
yes Thanks you !
 
Old 01-11-2006, 07:24 PM   #4
kyriakos
Member
 
Registered: Dec 2005
Location: Greece, Xanthi
Distribution: Red Hat 9, FreeBSD 5.4
Posts: 38

Rep: Reputation: 15
you can always use the locate command in linux. but first make sure you updatedb
 
Old 01-11-2006, 10:09 PM   #5
raf_iso
LQ Newbie
 
Registered: Jul 2005
Posts: 18

Original Poster
Rep: Reputation: 0
Your code is working, but refuse to run with long filnames, directores with spaces and stuff like that.

Code:
[root@fileserver _array]# find . | xargs stat -c '[%y][%s][%n]'
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
[root@fileserver _array]#
I tried to play with the xags -0 but I can't run it. May be do you know a tip or something for this problem ?

Thanks again!
 
Old 01-12-2006, 08:41 AM   #6
dustu76
Member
 
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153

Rep: Reputation: 30
My feeble attempts at perl:

Code:
#!/usr/bin/perl

# Output line format : YYYY.MM.DD-HH:MM][SIZE][FULLPATH]

use strict;
use File::Find;

die "Usage : $ARGV[0] <dir1> <dir2> ...\n"
        unless (@ARGV);

foreach my $path (@ARGV) {
        next unless -d $path;
        find(\&lmod, $path);
}

sub lmod() {
        my ($mtime, $size) = (stat($File::Find::name))[8,7];
        my ($ss, $min, $hh, $dt, $mo, $yy) = (localtime($mtime))[0,1,2,3,4,5];
        printf("[%02d.%02d.%02d-%02d:%02d][%d][%s]\n",
                ($yy += 1900), $mo++, $dt, $hh, $min, $size, $File::Find::name);
}
HTH
 
Old 01-12-2006, 08:55 AM   #7
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by raf_iso
Your code is working, but refuse to run with long filnames, directores with spaces and stuff like that
[..snip..]
I tried to play with the xags -0 but I can't run it. May be do you know a tip or something for this problem ?
You're right. The command line I posted doesn't handle correctly file/dirs with spaces, newlines, or other "strange" characters in the name.

"xargs -o stat ..." should solve the problem though, but be sure to use the "-print0" option with "find" in that case:
Code:
find /your/path -print0 | xargs -0 stat -c '[%y][%s][%n]'
 
Old 01-12-2006, 11:09 AM   #8
raf_iso
LQ Newbie
 
Registered: Jul 2005
Posts: 18

Original Poster
Rep: Reputation: 0
Wow Thanks You All !!!!!
 
  


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
grab FTP output in bash script bokini Linux - General 2 02-03-2006 02:11 PM
bash script to output only differences in two files czarherr Programming 4 11-08-2004 06:25 PM
bash:output file names from shell script to vi sickboy Linux - Newbie 6 10-14-2004 03:40 AM
Create custom user's directory with simple script dtournas Programming 2 09-09-2004 05:00 AM
Bash script: add all numbers from command output wi-Z-art Programming 2 08-06-2003 09:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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