Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11th January 2006, 09:25 AM
raf_iso Offline
Registered User
 
Join Date: Oct 2005
Posts: 26
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
Reply With Quote
  #2  
Old 11th January 2006, 11:13 AM
daverj Offline
Registered User
 
Join Date: Jan 2006
Location: Denver, CO USA
Posts: 670
This will do what you want. Mind you it will be slow for a 700GB filesystem, but if you are doing it overnight, you might have enough time.

#!/usr/bin/bash

DIR=/tmp
FILE=out.file

# move most current output to backup file
if [ -e ${DIR}/${FILE} ]; then
mv -f ${DIR}/${FILE}.bak
fi

# iterate over filesystem, extract desired info and format
# output to file
find . | while read line; do
m=`stat --format=%y ${line} | cut -d"." -f1`
s=`stat --format=%s ${line}`
echo "[$m][$s][${line}]" >> ${DIR}/${FILE}
done
Reply With Quote
  #3  
Old 11th January 2006, 01:21 PM
raf_iso Offline
Registered User
 
Join Date: Oct 2005
Posts: 26
WOW nice script !

I'm playing with it actually. I have a problem with filename and directory with spaces.

For example when the script found "fichier 1.txt" :

Code:
[raf@st-107168 tests]$ ./runme.sh
stat: cannot stat `./racine/fichier': No such file or directory
stat: cannot stat `1.txt': No such file or directory
Do you have something magic to resolve this ? I have also french accents and things like that, it's not very important if these non-us chars become "?"...

Oh.. and if there is something very easy to know the time ellapsed for the script it would be perfect !!! Something like [<timestamp at the end> - <timestamp at the begin>].

Thanks you !!!
RB

Last edited by raf_iso; 11th January 2006 at 01:24 PM.
Reply With Quote
  #4  
Old 11th January 2006, 01:33 PM
raf_iso Offline
Registered User
 
Join Date: Oct 2005
Posts: 26
a friend told me to try
Code:
find /your/path | xargs stat -c '[%y][%s][%n]'
and it's also working fine.
Reply With Quote
  #5  
Old 11th January 2006, 02:53 PM
ibbo's Avatar
ibbo Offline
Registered User
 
Join Date: Jun 2005
Location: Leeds
Posts: 1,264
mv "$file" "`echo $file | sed -e 's/\ /_/g'`";

where $file is something along the lines of

for file in '/home/mydir'
do
mv "$file" "`echo $file | sed -e 's/\ /_/g'`";
# more batch processing as laid out above
done



Will replace a whitespace charector in your filename with a "_".
Dont know if that is any good but it comes in handy for me when dealing with images from a MAC.

Also as noted 700GB is pretty big and will take some serious effort from your machine to churn through it all. I recomend trying updatedb and locate as a pair of tools that can index and find your files.

Ibbo
__________________
A Hangover Lasts A Day, But Our Drunken Memories Last A Lifetime
--
Linux user #349545
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCfdjyzXscddzQvlhBedAcD7qfKmHo==zx0H

Last edited by ibbo; 11th January 2006 at 02:56 PM.
Reply With Quote
  #6  
Old 12th January 2006, 04:05 AM
raf_iso Offline
Registered User
 
Join Date: Oct 2005
Posts: 26
Wink

daverj, your code is working, but the following code is really easier. Anyway, I can't run it in a directory with long filenames, 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!

Last edited by raf_iso; 12th January 2006 at 04:10 AM.
Reply With Quote
  #7  
Old 12th January 2006, 01:54 PM
KSLinuxUser Offline
Registered User
 
Join Date: Jan 2006
Posts: 4
Have you tried the locate command? If you just want to search by file name it is very handy. I don't know if it supports search by date.
Reply With Quote
  #8  
Old 12th January 2006, 03:45 PM
daverj Offline
Registered User
 
Join Date: Jan 2006
Location: Denver, CO USA
Posts: 670
raf_iso, two things:

First, the reason I did the script my particular way is because of the way you indicated how you wanted the output formatted. The standard output for stat --format=%y does not conform to the output you desired.
Second, you can easily modify my script to allow for spaces in filenames. Simply add double quotation marks around the filename variable in the stat command:

#!/usr/bin/bash

DIR=/tmp
FILE=out.file

# move most current output to backup file
if [ -e ${DIR}/${FILE} ]; then
mv -f ${DIR}/${FILE}.bak
fi

# iterate over filesystem, extract desired info and format
# output to file
find . | while read line; do
m=`stat --format=%y "${line}" | cut -d"." -f1`
s=`stat --format=%s "${line}"`
echo "[$m][$s][${line}]" >> ${DIR}/${FILE}
done

hope this helps

Last edited by daverj; 12th January 2006 at 03:48 PM.
Reply With Quote
  #9  
Old 12th January 2006, 05:13 PM
raf_iso Offline
Registered User
 
Join Date: Oct 2005
Posts: 26
Okay thanks you !! I'll try it tonight

see ya!
Reply With Quote
Reply

Tags
bash, browse, custom, directory, output, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
httpd directory browse onf F7 (ok can browse) and F8 (Forbidden, error 403) nuaing Servers & Networking 7 31st March 2008 10:14 AM
Bash script - File search output to new file ampapa Using Fedora 12 19th October 2006 01:49 AM
Convert bash script to perl script homey Programming & Packaging 1 2nd September 2006 04:24 AM
bash help: output and logging leaded Programming & Packaging 4 22nd March 2006 06:08 PM
BASH: How to redirect ping output to file? funchords Using Fedora 22 27th December 2005 03:34 AM


Current GMT-time: 10:30 (Saturday, 25-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat