Thanks.
> How can I create a new text file (in my home directory lets say) in a
> bash console or as an entry in a bash script?
$ touch <filename>
$ > <filename>
JB
Thank you.
This was one of those hard things for me to find.
I tried man -k new| grep text, man -k create, man -k file | grep new, etc.
all to no avail.
Thanks.
>> $ touch <filename>
>> $ > <filename>
>
>This was one of those hard things for me to find.
>
>I tried man -k new| grep text, man -k create, man -k file | grep new,
>etc. all to no avail.
Try this manual, its a good resource for linux/unix starters.
http://www.icon.co.za/~psheer/book/index.html.gz
http://www.icon.co.za/~psheer/book/node7.html.gz#chap:basiccmd
Download and keep a local copy with a bookmark to it.
$ echo "" > newtextfile.txt
As well. If the newtextfile.txt doesn't exist it will create it and add
"" to it (i.e. nothing). Thats the bodgers way though!
One of the reasons you didn't find anything, is that in Linux a file is
classified by its contents. That means: it's not a text file until you
put text into it. It's not a .jpeg file unless you put a JPEG image into
it. An empty file thus has no type except "empty file". Linux doesn't
look at extentions.
Another nice tool: do "man file" - "file" can identify files for you by
their contents.
Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
cat >> file
Some text is in this file...
^D
--
You know how to win a victory, Hannibal, but not how to use it.
-- Maharbal
> you can always
>
> $ echo "" > newtextfile.txt
>
> As well. If the newtextfile.txt doesn't exist it will create it and add
> "" to it (i.e. nothing). Thats the bodgers way though!
There appears to be no shortage of ways to accomplish this simple task
:-)
Before I learnt about 'touch', I used 'cat /dev/null > <file>'.
However, I have found that the simplest way of creating a file is to
just use it ...
--
PeKaJe
Don't worry if you're a kleptomaniac; you can always take something for it.
> Spozza wrote:
>
>> you can always
>>
>> $ echo "" > newtextfile.txt
>>
>> As well. If the newtextfile.txt doesn't exist it will create it and add
>> "" to it (i.e. nothing). Thats the bodgers way though!
>
> There appears to be no shortage of ways to accomplish this simple task
> :-)
>
> Before I learnt about 'touch', I used 'cat /dev/null > <file>'. However, I
> have found that the simplest way of creating a file is to just use it ...
Keep in mind if the file already exists touch updates it's timestamp and
otherwise leaves it alone.
touch doesn't create a new, empty file unless the file doesn't exist.
--
i.m.
All views, opinions and alleged facts expressed by this tactless moron are
protected by the constitution of the United States of America and should be
taken as good natured and friendly unless specifically stated otherwise.
Assuming that you specify a new "text file" because you want the file to
contain text, then you can use any of these...
a) echo "Some text goes here" >new.text.file
b) cat >new.text.file <-EOF
many lines of new text
can be placed here, and
will be copied to stdout
The text is terminated by
a single line containing
the word "EOF". See the
bash manpage, "REDIRECTION"
section, "HERE Documents"
subsection for details.
EOF
c) any text editor, like vi, emacs, or pico
--
Lew Pitcher
Master Codewright and JOAT-in-training
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
--
It is often the case that the man who can't tell a lie thinks he is the best
judge of one.
-- Mark Twain, "Pudd'nhead Wilson's Calendar"