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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
01-11-2006, 03:29 AM
|
#1
|
|
LQ Newbie
Registered: Jul 2005
Posts: 18
Rep:
|
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
|
|
|
|
01-11-2006, 06:56 AM
|
#2
|
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530
Rep: 
|
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.
|
|
|
|
01-11-2006, 07:25 AM
|
#3
|
|
LQ Newbie
Registered: Jul 2005
Posts: 18
Original Poster
Rep:
|
yes Thanks you !
|
|
|
|
01-11-2006, 07:24 PM
|
#4
|
|
Member
Registered: Dec 2005
Location: Greece, Xanthi
Distribution: Red Hat 9, FreeBSD 5.4
Posts: 38
Rep:
|
you can always use the locate command in linux. but first make sure you updatedb
|
|
|
|
01-11-2006, 10:09 PM
|
#5
|
|
LQ Newbie
Registered: Jul 2005
Posts: 18
Original Poster
Rep:
|
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!
|
|
|
|
01-12-2006, 08:41 AM
|
#6
|
|
Member
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153
Rep:
|
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
|
|
|
|
01-12-2006, 08:55 AM
|
#7
|
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530
Rep: 
|
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]'
|
|
|
|
01-12-2006, 11:09 AM
|
#8
|
|
LQ Newbie
Registered: Jul 2005
Posts: 18
Original Poster
Rep:
|
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:52 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|