Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a file in Linux from terminal window? [closed]

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

like image 940
raffian Avatar asked Feb 21 '12 16:02

raffian


People also ask

How do I close and save a file in Linux terminal?

More Linux resources. To save a file, you must first be in Command mode. Press Esc to enter Command mode, and then type :wq to write and quit the file. The other, quicker option is to use the keyboard shortcut ZZ to write and quit.

How do I open a closed terminal in Linux?

Now when you connect to the machine via SSH, just type screen and press Space. You will be back to your normal terminal.


2 Answers

Depending on what you want the file to contain:

  • touch /path/to/file for an empty file
  • somecommand > /path/to/file for a file containing the output of some command.

      eg: grep --help > randomtext.txt       echo "This is some text" > randomtext.txt 
  • nano /path/to/file or vi /path/to/file (or any other editor emacs,gedit etc)
    It either opens the existing one for editing or creates & opens the empty file to enter, if it doesn't exist

like image 52
Eugen Rieck Avatar answered Oct 12 '22 12:10

Eugen Rieck


Use touch

touch filename 
like image 27
Mariusz Jamro Avatar answered Oct 12 '22 14:10

Mariusz Jamro