How to create a file in Linux from terminal window

2019-01-15 23:59发布

What's the easiest way to create a file in Linux terminal?

15条回答
家丑人穷心不美
2楼-- · 2019-01-16 00:27

You can use touch command, as the others said:

touch filename

To write on file on command line, you can use echo or printf:

echo "Foo" > filename
printf "Foo" > filename

Maybe you can have problems with permissions. If you are getting the following error: bash: filename: Permission denied, you need to use sudo bash -c 'echo "Foo" > filename', as described here: https://askubuntu.com/questions/103643/cannot-echo-hello-x-txt-even-with-sudo

查看更多
Ridiculous、
3楼-- · 2019-01-16 00:28

You can use the touch command to create a new empty file.

http://linux.about.com/library/cmd/blcmdl_touch.htm

查看更多
狗以群分
4楼-- · 2019-01-16 00:29

1st method

echo -n > filename.txt

2nd method

> filename.txt

3rd method

touch filename.txt

To view the file contents

vi filename.txt
查看更多
登录 后发表回答