Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create and open a file from terminal with a single command?

Tags:

shell

To create a file from terminal I type the following...

$ touch filename.py

To open the file I just created from terminal, I then type...

$ open filename.py

I'm curious to know if there is a terminal command that does both...create and then open (I'm super lazy).

like image 623
Eddie Avatar asked Jul 20 '12 18:07

Eddie


People also ask

How do you create a new file in Mac terminal?

In the Terminal app on your Mac, invoke a command-line editor by typing the name of the editor, followed by a space and then the name of the file you want to open. If you want to create a new file, type the editor name, followed by a space and the pathname of the file.


3 Answers

in .bashrc

lazytouch()
{
  touch $1
  open $1
}

then type

$ lazytouch anything.really
like image 108
nshy Avatar answered Oct 18 '22 04:10

nshy


This is as lazy as one can get:

$ echo "your text" > myfile.txt
like image 8
Julian Tellez Avatar answered Oct 18 '22 04:10

Julian Tellez


Simplest way to do this is

touch filename; open filename

Example

touch myfile.py; open myfile.py
like image 7
Boshika Tara Avatar answered Oct 18 '22 03:10

Boshika Tara