What is the maximum file length + Unix + Linux

I decided to find out by whipping up a quick bash script.

#!/bin/bash

function make_dir {
echo "creating file with " $size " characters"
touch $dir_name
if [ $? -ne 0 ]
then
 exit 1
fi
old=$dir_name
add="a"
dir_name=$dir_name$add
size=`expr $size + 1`
rm -rf $old
}

dir_name="a"
size=1
while [ $? -eq 0 ]
do
 make_dir
done

I got the following output

...creating file with  234  characters
creating file with  235  characters
creating file with  236  characters
creating file with  237  characters
creating file with  238  characters
creating file with  239  characters
creating file with  240  characters
creating file with  241  characters
creating file with  242  characters
creating file with  243  characters
creating file with  244  characters
creating file with  245  characters
creating file with  246  characters
creating file with  247  characters
creating file with  248  characters
creating file with  249  characters
creating file with  250  characters
creating file with  251  characters
creating file with  252  characters
creating file with  253  characters
creating file with  254  characters
creating file with  255  characters
creating file with  256  characters

So there ya go. Give it a try on some other platforms I would love to see if there are differences.

Advertisements

4 thoughts on “What is the maximum file length + Unix + Linux

  1. Neat! You inspired me to learn more about the history of filename lengths, and Wikipedia provided this: http://en.wikipedia.org/wiki/Comparison_of_file_systems

    This is unrelated, but I remember when I first started using a UNIX-like OS I accidentally created a file called “-r” (a hyphen and the letter R), and I couldn’t figure out how to delete it! Doing `rm -r` made rm complain about not having a filename. Finally my boss took pity on me and told me the secret: `rm ./-r`. (This was on an SGI O2 workstation running IRIX.)

    • Ha that’s cool. I just had to try it for myself I created a directory -r. I don’t understand why I can’t use a backslash to escape the minus (-) though. I used mkdir ./-r and it worked. Silly question but why does ./ work? I figured that . is the current directory but that is the extent of my explanation.
      We missed you at Open Repositories Conference this year, was pretty cool. I have some cool photos of Spain and London on my Facebook account.
      Cheers
      Tim

      • Doing `rm \-r` doesn’t work because bash (or zsh/csh/whatever) interprets it, and it only passes on the “-r” to rm. But “./-r” gets passed unmodified to rm even after bash interprets it.

        I’ve heard some people create files called “-i” in their directories so that if they accidentally do `rm *`, they get prompted. (This seems silly to me!)

        I was sad to miss OR this year! I’m glad you guys had a good time, and I’ll check out your Facebook pictures. Maybe next year!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s