Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new file in unix? [closed]

Tags:

unix

How do I create a new file in a different directory? If the file exists it should also create a new file.

I am using the command:

Touch workdirectory/filename.txt
like image 669
user2285422 Avatar asked Apr 17 '13 11:04

user2285422


People also ask

How do you create a new file in Unix?

If you're using a window manager, you can usually press Ctrl + Alt + T to open a new terminal window. If not, log into the system on which you want to create a file through the console. Type cat > newfilename and press ↵ Enter . Replace newfilename with whatever you'd like to call your new file.

How do you close a file in Unix?

Additionally, you can use shortcut methods. Press the [Esc] key and type Shift + Z Z to save and exit or type Shift+ Z Q to exit without saving the changes made to the file.


1 Answers

Try > workdirectory/filename.txt

This would:

  • truncate the file if it exists
  • create if it doesn't exist

You can consider it equivalent to:

rm -f workdirectory/filename.txt; touch workdirectory/filename.txt
like image 175
devnull Avatar answered Oct 20 '22 12:10

devnull