Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Get length of filenames in debian linux

Posted on 2009-05-14
8
391 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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
 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
High Bandwidth Usage 6 75
centos linux 65 155
windows 7 starter missing password 21 89
error while installing php56 in redhat enterprise linux 20 50
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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.

789 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