create file

create file

Post by Eugen » Sat, 20 Oct 2001 00:07:59



What is the simplest way to create a file of specific non-zero size just
from shell (using other programming languages, c for example, is not a
case). Filling character could be any.

Thanks
Eugene

 
 
 

create file

Post by Tony Curti » Sat, 20 Oct 2001 00:08:27


>> On Thu, 18 Oct 2001 11:07:59 -0400,

> What is the simplest way to create a file of specific
> non-zero size just from shell (using other programming
> languages, c for example, is not a case). Filling
> character could be any.

man dd

hth
t
--
Oh!  I've said too much.  Smithers, use the amnesia ray.

 
 
 

create file

Post by Joost Kremer » Sat, 20 Oct 2001 00:13:38



> What is the simplest way to create a file of specific non-zero size just
> from shell (using other programming languages, c for example, is not a
> case). Filling character could be any.

echo sometext > somefile

will create a file `somefile' with `sometext' as its contents.

HTH

--
Joost Kremers
registered Linux user #230173

 
 
 

create file

Post by Eugen » Sat, 20 Oct 2001 00:14:57


dd requires an input stream (if=). what do I use for it?


> >> On Thu, 18 Oct 2001 11:07:59 -0400,

> > What is the simplest way to create a file of specific
> > non-zero size just from shell (using other programming
> > languages, c for example, is not a case). Filling
> > character could be any.

> man dd

> hth
> t
> --
> Oh!  I've said too much.  Smithers, use the amnesia ray.

 
 
 

create file

Post by Tony Curti » Sat, 20 Oct 2001 00:17:21


[ please quote only the relevant portion of the article
you are following up, and then place your new text after
that ]

>> On Thu, 18 Oct 2001 11:14:57 -0400,

>> > What is the simplest way to create a file of specific
>> > non-zero size just from shell (using other
>> programming > languages, c for example, is not a
>> case). Filling > character could be any.

>> man dd

> dd requires an input stream (if=). what do I use for it?

/dev/zero, e.g. 64k file,

    dd if=/dev/zero of=FILENAME bs=1k count=64

Some *NIXen provide a mkfile(1).

hth
t
--
Oh!  I've said too much.  Smithers, use the amnesia ray.

 
 
 

create file

Post by Eugen » Sat, 20 Oct 2001 00:23:04


That's the solution!
Thank you Tony!

BTW: could not find mkfile(1) in RH

Eugene


> [ please quote only the relevant portion of the article
> you are following up, and then place your new text after
> that ]

> >> On Thu, 18 Oct 2001 11:14:57 -0400,

> >> > What is the simplest way to create a file of specific
> >> > non-zero size just from shell (using other
> >> programming > languages, c for example, is not a
> >> case). Filling > character could be any.

> >> man dd

> > dd requires an input stream (if=). what do I use for it?

> /dev/zero, e.g. 64k file,

>     dd if=/dev/zero of=FILENAME bs=1k count=64

> Some *NIXen provide a mkfile(1).

> hth
> t
> --
> Oh!  I've said too much.  Smithers, use the amnesia ray.

 
 
 

create file

Post by Alexander Mudr » Sat, 20 Oct 2001 01:28:16


n Thu, 18 Oct 2001 11:07:59 -0400, "Eugene"

|>What is the simplest way to create a file of specific non-zero size just
|>from shell (using other programming languages, c for example, is not a
|>case). Filling character could be any.

it's very easy:
touch myfile.notfilled

and you have it...

Bye
        Alexander

 
 
 

create file

Post by Grant Edwar » Sat, 20 Oct 2001 02:24:28



> n Thu, 18 Oct 2001 11:07:59 -0400, "Eugene"

>|>What is the simplest way to create a file of specific non-zero size just
>|>from shell (using other programming languages, c for example, is not a
>|>case). Filling character could be any.

> it's very easy:
> touch myfile.notfilled

> and you have it...

Nope.  It creates an empty file rather than one of "specific
non-zero size".

--
Grant Edwards                   grante             Yow!  Am I in GRADUATE
                                  at               SCHOOL yet?
                               visi.com            

 
 
 

create file

Post by cbbro.. » Sat, 20 Oct 2001 03:45:15



> n Thu, 18 Oct 2001 11:07:59 -0400, "Eugene"

> |>What is the simplest way to create a file of specific non-zero size just
> |>from shell (using other programming languages, c for example, is not a
> |>case). Filling character could be any.

> it's very easy:
> touch myfile.notfilled

> and you have it...

Not quite.  You answered the question "What is the simplest way to
create a file of specific _zero_ size?"

The question was about _non-zero_ size.

About the most reasonable answers would be thus, assuming
"zero-filled" is fine, and you want it 29 bytes long:

   dd if=/dev/zero of=/my/new/blank/file bs=1 count=29

That'll create the file /my/new/blank/file, containing 29 ASCII
null's.
--

http://www.cbbrowne.com/info/lsf.html
There are few personal problems which can't be solved by the suitable
application of high explosives.

 
 
 

create file

Post by Tony Curti » Sat, 20 Oct 2001 03:57:28


>> On Thu, 18 Oct 2001 18:45:15 GMT,

>> it's very easy: touch myfile.notfilled
> Not quite.  You answered the question "What is the
> simplest way to create a file of specific _zero_ size?"

Not necessarily.  The file size will be zero if the file
did not exist before.  Otherwise it'll remain the same
size as before the touch, but with updated (a|m)time.

Modulo permissions issues of course.

hth
t
--
Oh!  I've said too much.  Smithers, use the amnesia ray.

 
 
 

create file

Post by cbbro.. » Sat, 20 Oct 2001 04:49:04



> >> On Thu, 18 Oct 2001 18:45:15 GMT,

> >> it's very easy: touch myfile.notfilled

> > Not quite.  You answered the question "What is the
> > simplest way to create a file of specific _zero_ size?"

> Not necessarily.  The file size will be zero if the file
> did not exist before.  Otherwise it'll remain the same
> size as before the touch, but with updated (a|m)time.

> Modulo permissions issues of course.

Well, if the file did not exist, then you get a file of _zero_ size,
which was not what was asked for.

If the file _did_ exist, then you haven't created a file; it _might_
be of non-zero size, but there are no guarantees.  The question was
about _creating_ a file, so this doesn't respond to the question
anyways.
--

http://www.ntlug.org/~cbbrowne/advocacy.html
All generalizations are false, including this one.

 
 
 

create file

Post by LinuxBe » Sat, 20 Oct 2001 10:47:29




>> >> On Thu, 18 Oct 2001 18:45:15 GMT,

>> >> it's very easy: touch myfile.notfilled

>> > Not quite.  You answered the question "What is the
>> > simplest way to create a file of specific _zero_ size?"

>> Not necessarily.  The file size will be zero if the file
>> did not exist before.  Otherwise it'll remain the same
>> size as before the touch, but with updated (a|m)time.

>> Modulo permissions issues of course.

> Well, if the file did not exist, then you get a file of _zero_ size,
> which was not what was asked for.

> If the file _did_ exist, then you haven't created a file; it _might_
> be of non-zero size, but there are no guarantees.  The question was
> about _creating_ a file, so this doesn't respond to the question
> anyways.

To file or not to file, that is the question

--

LinuxBear

       ___  
     {~._.~}
     _( Y )_
    (:_~*~_:)
     (_)-(_)

 
 
 

create file

Post by OldUncle » Tue, 23 Oct 2001 13:36:28


It was: Thu, 18 Oct 2001 10:08:27 -0500  and with STARTLING insight,  "Tony

 to "alt.os.linux" :

-->>> On Thu, 18 Oct 2001 11:07:59 -0400,

-->
-->> What is the simplest way to create a file of specific
-->> non-zero size just from shell (using other programming
-->> languages, c for example, is not a case). Filling
-->> character could be any.
-->
-->man dd
-->
-->hth
-->t

Gotta have a script for every purpose, thought I can't say why this purpose
is proposed.....

##========script follows=================##
#!/bin/bash
##  ? PEMS 2001  freely distributable/modifyable
## credit to be given to PEMS/ts

if [ -f newfile ]; then
  rm newfile
fi

count=0;
varp=0;

if [ $1 ]; then
  echo "argument found:  $1";
  while [ $count -lt $1 ]; do
    if [ $varp -eq 48 ] && [ $count -lt $1 ]; then
      printf "1\n" >> newfile;
      varp=0;
      ((count+=2));
    else
      printf "a" >> newfile;
      ((varp+=1));
      ((count+=1));
    fi
  done
else
  while [ $count -lt 2 ]; do
    if [ $varp -eq 48 ]; then
      echo "1" >> newfile;
      varp=0;
      ((count+=1));
    else
      printf "a" >> newfile;
      ((varp+=1));
    fi
  done
fi

ls -lFa newfile
exit 0

##==usage:  either <script-name> or <script-name number>==##

So, copy the script to a file, say, "makfileofsize".
Then set the executable bit:  chmod 0744 makefileofsize

To run,
1.  just enter "makefileofsize" to create a 100 byte file called newfile
2. enter "makefileofsize 400" to make a file of size 400 bytes, or any
    other number for any other size given file size limits of system.

The file "newfile" will be the size as indicated above, but for every 50
bytes, noe will be a "line feed" character; this allows formatting the
data.  You could easily modify the script to allow input of filenames as
command line arguments.  I think the loops within loops make this script a
bit slow for sizes above about 5000bytes.  Any scripting experts care to
improve its performance?  *_-       /ts

--

"If you can just get your mind together
 Then come on across to me...."  Jimi

 
 
 

create file

Post by Eugen » Tue, 23 Oct 2001 22:55:07


Your script are awesome!
But see "one-string" solution (using dd) from Tony Curtis (this thread).

Regards
Eugene


> It was: Thu, 18 Oct 2001 10:08:27 -0500  and with STARTLING insight,
"Tony

>  to "alt.os.linux" :

> -->>> On Thu, 18 Oct 2001 11:07:59 -0400,

> -->
> -->> What is the simplest way to create a file of specific
> -->> non-zero size just from shell (using other programming
> -->> languages, c for example, is not a case). Filling
> -->> character could be any.
> -->
> -->man dd
> -->
> -->hth
> -->t

> Gotta have a script for every purpose, thought I can't say why this
purpose
> is proposed.....

> ##========script follows=================##
> #!/bin/bash
> ##  ? PEMS 2001  freely distributable/modifyable
> ## credit to be given to PEMS/ts

> if [ -f newfile ]; then
>   rm newfile
> fi

> count=0;
> varp=0;

> if [ $1 ]; then
>   echo "argument found:  $1";
>   while [ $count -lt $1 ]; do
>     if [ $varp -eq 48 ] && [ $count -lt $1 ]; then
>       printf "1\n" >> newfile;
>       varp=0;
>       ((count+=2));
>     else
>       printf "a" >> newfile;
>       ((varp+=1));
>       ((count+=1));
>     fi
>   done
> else
>   while [ $count -lt 2 ]; do
>     if [ $varp -eq 48 ]; then
>       echo "1" >> newfile;
>       varp=0;
>       ((count+=1));
>     else
>       printf "a" >> newfile;
>       ((varp+=1));
>     fi
>   done
> fi

> ls -lFa newfile
> exit 0

> ##==usage:  either <script-name> or <script-name number>==##

> So, copy the script to a file, say, "makfileofsize".
> Then set the executable bit:  chmod 0744 makefileofsize

> To run,
> 1.  just enter "makefileofsize" to create a 100 byte file called newfile
> 2. enter "makefileofsize 400" to make a file of size 400 bytes, or any
>     other number for any other size given file size limits of system.

> The file "newfile" will be the size as indicated above, but for every 50
> bytes, noe will be a "line feed" character; this allows formatting the
> data.  You could easily modify the script to allow input of filenames as
> command line arguments.  I think the loops within loops make this script a
> bit slow for sizes above about 5000bytes.  Any scripting experts care to
> improve its performance?  *_-       /ts

> --

> "If you can just get your mind together
>  Then come on across to me...."  Jimi

 
 
 

1. cannot create file in mounted file system

Hello,

I have SunOS 5.5 in two Sparc-20 boxes. In box one I have done as root:
mkdir /x/y
'ls -ld /x/y' yields: drwxr-xr-x 2 root root <size/date> /x/y
share /x/y
'share' yields: - /x/y rw ""
In box two I have done as root:
mkdir /x/y
'ls -ld /x/y' yields: drwxr-sr-x 2 root sys <size/date> /x/y
mount host1:/x/y /x/y
'mount' yields: /x/y on host1:/x/y read/write/setuid/proto=udp/remote ..
cd /x/y
'touch z' yields: touch: a: Permission denied

How do I allow creating of file(s) in a mounted file system ?
--
Regards,

Marek Grinberg

|------------------------------------------------|


| web:  http://www.msc.se                        |
|------------------------------------------------|

2. HP-UX Development Environment

3. file format for dbm created files

4. SVGALIB

5. mail to file : unable to create file

6. re-install

7. How to create files with a timestamp in the file name?

8. More File Parsing

9. cannot unlink file or create files

10. created file permissions on group

11. trigger create file

12. How to get Users to create files with another group as owner??

13. Solaris 2.5 door interface - how to create .file???