Re: Shell scripts: determining filename length

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/7/05, Brian D. McGrew <brian@xxxxxxxxxxxxx> wrote:
> Good morning.
> 
> I'm working on some shell scripts that process directories full of times
> shared by Samba and used by Windows people.  We all know that Windows
> people have a habit of really, really, really, long filenames.
> 
> In a shell script, inside a `for f in *` loop, how can I go about
> finding how long a filename is ... And then truncate the name, keeping
> the three letter extension, to less than 64 characters?

In bash you can do something like the following

for f in *; do
    if [ ${#f} -ge 64 ]; then
        munging filename left as exercise but look at
        ${parameter:offset:length} in the bash man
        page for a handy shell way to snip a variable
    fi
done

John

-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux