LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Create several files? (https://www.linuxquestions.org/questions/linux-newbie-8/create-several-files-164302/)

peman 03-30-2004 05:06 PM

Create several files?
 
Hi
I need to know how to create several files in one command line?
I want to have ch01 ch02 ch03... and so on up to ch14
Is'nt the touch command?

I also want to know how to create several files with content like author or something like that.

Thanks! :)

AutOPSY 03-30-2004 05:42 PM

what ?

create a file with touch or vi or pico.

Nobody is going to hold your hand here.

I can't even believe people ask questions like this, when they just suggested themselves to use touch.

and by the way, despite the random yapping about touch, it is not to create a file it is to update the time stamp on files.

vi or another editor will "create" a file .

kooch 03-30-2004 05:48 PM

touch will create a file unless you use the -c option.

I think in order to create several files as you desire you will have to write a trivial shell script.(bash,perl,python)

Try freshmeat they might have something already written.

jlarmour 03-30-2004 06:00 PM

1. touch ch01 ch02 ch03

2. Assuming you use bash (default Linux shell)
for (( i = 1 ; i < 14 ; i++ ))
do
echo "Author: me " > ch$i
done

kooch 03-30-2004 06:04 PM

I've never done much shell scripting so I just wrote up a sample real quick. It doesn't do anything fancy no error checking.

You could easily replace the touch command with cat piped to a numbered file(as done with touch) that would allow you to put a standard heading in.

------------------------------------
#!/bin/bash

PREFIX=$1
START=$2
END=$3

while [ $START -le $END ]; do
touch "$PREFIX$START"
let START=START+1
done
-----------------------------------

peman 03-31-2004 05:02 AM

Thanks it worked with this and it solved my problem on creating several files at ones!!

1. touch ch01 ch02 ch03

2. Assuming you use bash (default Linux shell)
for (( i = 1 ; i < 14 ; i++ ))
do
echo "Author: me " > ch$i
done

i dont understand this
#!/bin/bash

PREFIX=$1
START=$2
END=$3

while [ $START -le $END ]; do
touch "$PREFIX$START"
let START=START+1
done

Thank you very much!!!

iluvatar 03-31-2004 06:49 AM

from one command line you van also use use:

touch /path/{file1,file2,file3,etc}

to put the same content in all files use:

echo "some content" >> /path/{file1,file2,file3,etc}

greetz,
iluvatar

note: I didn't test last command, but it {sh|c}ould work

peman 03-31-2004 07:06 AM

ok thanks again but whats the command without content to create several files? shouldnt it be something simplier like touch ch[0] [123456789] but up to 14 files, i am a newbie so...

iluvatar 03-31-2004 07:09 AM

this command will create several empty files:

touch {file1,file2,file3,file4,file5,file6}

greetz,
-= iluvatar =-

peman 03-31-2004 07:29 AM

Thanks but stil you have to write all the files, isnt there a simplier way? lets say you want to create 100 files then you will have to write a very long command line, then there must be a simplier way?

iluvatar 03-31-2004 07:38 AM

well in that case you could best use the script wich kooch gave:

-[script.sh]-----------------------
#!/bin/bash

PREFIX=$1
START=$2
END=$3

while [ $START -le $END ]; do
touch "$PREFIX$START"
let START=START+1
done
-----------------------------------

the $1 $2 and $3 variables are command line options. starting this script with this:

./script.sh ~/file 0 100

will create file0, file1 file2 up to file100 in your home dir

greetinz,
-= iluvatar =-

kooch 03-31-2004 07:45 AM

peman, if you're still having difficulties understanding the scripts
take a look at this.

screwthepenguin 05-07-2004 09:56 AM

Good work Autopsy
 
Autopsy, you are the reason Linux guys have such a bad rap. Didn't your mother ever tell you if you can't say anything nice, don't say anything at all? Have fun at your LAN party this weekend. Loser. And don't you know no self-respecting nerd would use 9.0. Nobody is going to hold your hand here.


All times are GMT -5. The time now is 04:40 PM.