Solved

Get length of filenames in debian linux

Posted on 2009-05-14
8
384 Views
Last Modified: 2013-12-06
I want to run a find command piped to something that will give me the length of each filename, including the folders that contain it

eg:

find . | getlength

outputs:
blah/foo 8
blah/barney 11
foo/abc 7
0
Comment
Question by:Terry Woods
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 11

Accepted Solution

by:
climbgunks earned 480 total points
ID: 24392364

something like

find . | perl -pe 'chomp; $_.=" ".length()."\n"'


example output:

user@host:~/puzzle# find . | perl -pe 'chomp; $_.=" ".length()."\n"'
. 1
./decrypt.pl~ 13
./input 7
./decrypt.pl 12
./foo 5
./foo/afile 11
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 20 total points
ID: 24392427
Do you want the length without the ./ ?
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 24392472
How about :

find . -exec du {} \;
0
 
LVL 11

Assisted Solution

by:climbgunks
climbgunks earned 480 total points
ID: 24392478


ozo:  that's a good question.   In the case of   find /tmp | ...      I would assume you'd want everything counted.   Perhaps, . is a special case....

In that case, this works:

find . | perl -ne 'chomp; unless (/^.$/) {$a=substr($_,/^\.\//?2:0); print "$a ".length($a)."\n"}'

same thing w/ a real dir or list of dirs:

find /etc /tmp | perl -ne 'chomp; unless (/^.$/) {$a=substr($_,/^\.\//?2:0); print "$a ".length($a)."\n"}'


KeremE:  du prints the disk usage (in blocks)... I think the OP wants character count
--t
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 35

Author Comment

by:Terry Woods
ID: 24392533
Thanks very much for the quick response - I ended up using a slightly modified version of the first answer:

find . | perl -pe 'chomp;$_=length()." $_\n"' | sort -n > /blah/filelength.txt

to get what I needed.

It turned out I was looking for slightly the wrong value - a (Windows) DVD write was being rejected because of a 106 char limit, but that was actually referring to the filename without the path included, thankfully. I only had to rename 1 file (instead of over 900 if that wasn't the case) to fix the issue.
0
 
LVL 35

Author Closing Comment

by:Terry Woods
ID: 31581798
Thanks very much!!
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 24392546
@climbgunks:

du -b will use bytes instead so:

find . -exec du -b {} \;

prints the length as bytes :))
0
 
LVL 84

Expert Comment

by:ozo
ID: 24392607
an easier way to do
unless (/^.$/) {$a=substr($_,/^\.\//?2:0);
would be
s/^\.\///; $a=$_;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VMWARE Vcenter GUI defaults question about networks 10 86
Linux Mint 18 31 77
File and print server with Ubuntu? 7 26
VMware Workstation 12 Player 16 40
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now