Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What command makes a new file in terminal?

Tags:

If mkdir creates a new directory, what creates a new file? for example "something.text".

I tried couple of commands mkdir (FileName) -- works fine. But I didn't know how to create a new file inside a directory. I know that I can always go to my project folder then create my new file but I want to know how to do that using terminal to increase productivity.

like image 785
Moe Avatar asked Oct 05 '16 11:10

Moe


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.

Which command Create a new file in Linux?

The easiest way to create a new file in Linux is by using the touch command. The ls command lists the contents of the current directory. Since no other directory was specified, the touch command created the file in the current directory.


1 Answers

On Linux there are mutiple options

The typical used one is touch

touch bar.txt 

However you may also use echo if you want to create and write to the file right away

The following command tells to create bar.txt and put foo inside of it

echo foo > bar.txt 

You may also use >> which appends to an existing file

The following command puts bar at the end of bar.txt, in a other words, bar will display after foo inside bar.txt

echo bar >> bar.txt 
like image 124
CTXz Avatar answered Oct 27 '22 01:10

CTXz