LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 06-27-2009, 01:43 PM   #1
Jason40k
LQ Newbie
 
Registered: Jun 2009
Posts: 1

Rep: Reputation: 0
working with grip


how would i modify this function to descend all subdirectories of the named directory recursively and to find the maximum length of any filename in that hierarchy.

$ function maxfn () {
> typeset -i max thisone
> if [ ! -d "$1" -o $# = 0 ]
> then
> echo "Usage: maxfn dirname"
> return 1
> fi
>
> max=0
> for fn in $(/bin/ls $1)
> do
> thisone=${#fn}
> if [ $thisone -gt $max ]
> then
> max=$thisone
> fi
> done
> echo "Longest filename is $max characters."
> }
 
Old 06-27-2009, 02:37 PM   #2
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 60
Sometime ago I wrote a simple script to run over a directory tree recursively.
Here it is. I think you can adapt it to your problem easily.

Code:
#!/bin/bash

recursewalk(){
    for file in *
    do if [ -d $file ] 
            then echo "Descending into $file" 
            cd $file
            recursewalk
            cd ..
        fi
    done
}
recursewalk
 
  


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
Working Grip 3.3.1 settings in Ubuntu 7.10 for FLAC with working meta info robocoop Linux - Software 0 04-06-2008 04:28 PM
my grip...what do you think is best :) Mohtek General 11 10-01-2007 11:28 AM
Grip not working (Doesn't load) Rundi Linux - Software 3 03-20-2004 11:10 AM
Grip... Linux~Powered Linux - Software 4 03-08-2004 09:28 PM
Grip id3 tagging not working (or so it seems?) MasterC Linux - Software 1 02-27-2003 01:33 AM


All times are GMT -5. The time now is 12:10 PM.

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