Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

What command makes a new file in terminal?

Writer Emily Wong

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.

4

3 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
2

You can either use touch:

$ touch something.txt

or > operator to redirect nothing to a file and effectively creating it:

$ > something.txt

or

$ : > something.txt

Note that last 2 commands will truncate file contents if file already exists.

1

If you mean on Linux so the command is touch.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy