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! :) |
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 . |
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. |
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'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 ----------------------------------- |
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!!! |
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 |
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...
|
this command will create several empty files:
touch {file1,file2,file3,file4,file5,file6} greetz, -= iluvatar =- |
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?
|
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 =- |
peman, if you're still having difficulties understanding the scripts
take a look at this. |
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. |