LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-30-2004, 06:06 PM   #1
peman
LQ Newbie
 
Registered: Mar 2004
Posts: 11

Rep: Reputation: 0
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!
 
Old 03-30-2004, 06:42 PM   #2
AutOPSY
Member
 
Registered: Mar 2004
Location: US
Distribution: Redhat 9 - Linux 2.6.3
Posts: 836

Rep: Reputation: 31
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 .
 
Old 03-30-2004, 06:48 PM   #3
kooch
Member
 
Registered: Mar 2004
Location: Upstate NY
Distribution: Slackware/YDL
Posts: 77

Rep: Reputation: 15
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.
 
Old 03-30-2004, 07:00 PM   #4
jlarmour
LQ Newbie
 
Registered: Feb 2004
Location: Earth, early 21st century
Distribution: mandrake, slackware
Posts: 9

Rep: Reputation: 0
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
 
Old 03-30-2004, 07:04 PM   #5
kooch
Member
 
Registered: Mar 2004
Location: Upstate NY
Distribution: Slackware/YDL
Posts: 77

Rep: Reputation: 15
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
-----------------------------------
 
Old 03-31-2004, 06:02 AM   #6
peman
LQ Newbie
 
Registered: Mar 2004
Posts: 11

Original Poster
Rep: Reputation: 0
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!!!

Last edited by peman; 03-31-2004 at 06:06 AM.
 
Old 03-31-2004, 07:49 AM   #7
iluvatar
Member
 
Registered: Jul 2003
Location: netherlands
Distribution: debian
Posts: 403

Rep: Reputation: 30
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
 
Old 03-31-2004, 08:06 AM   #8
peman
LQ Newbie
 
Registered: Mar 2004
Posts: 11

Original Poster
Rep: Reputation: 0
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...
 
Old 03-31-2004, 08:09 AM   #9
iluvatar
Member
 
Registered: Jul 2003
Location: netherlands
Distribution: debian
Posts: 403

Rep: Reputation: 30
this command will create several empty files:

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

greetz,
-= iluvatar =-
 
Old 03-31-2004, 08:29 AM   #10
peman
LQ Newbie
 
Registered: Mar 2004
Posts: 11

Original Poster
Rep: Reputation: 0
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?
 
Old 03-31-2004, 08:38 AM   #11
iluvatar
Member
 
Registered: Jul 2003
Location: netherlands
Distribution: debian
Posts: 403

Rep: Reputation: 30
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 =-
 
Old 03-31-2004, 08:45 AM   #12
kooch
Member
 
Registered: Mar 2004
Location: Upstate NY
Distribution: Slackware/YDL
Posts: 77

Rep: Reputation: 15
peman, if you're still having difficulties understanding the scripts
take a look at this.
 
Old 05-07-2004, 10:56 AM   #13
screwthepenguin
LQ Newbie
 
Registered: May 2004
Posts: 1

Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create PDF files Chuck23 Linux - Software 6 08-10-2004 10:34 PM
How to create files from the console? warrant6767 Mandriva 2 06-30-2004 06:36 PM
Linux, Create Dirs=no, Create files=yes. Possible? tisource Linux - General 4 01-12-2004 11:05 PM
create your own ISO image files biotek1 Linux - General 4 10-27-2003 02:59 PM
How do I create PDF files? thom Linux - General 3 02-27-2002 01:17 PM


All times are GMT -5. The time now is 07:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration