How to create a new file in ubuntu using terminal?

Member

by modesta , in category: General Help , 2 years ago

How to create a new file in ubuntu using terminal?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by georgiana.senger , 2 years ago

@modesta 

To create a new file in Ubuntu using the terminal, follow these steps:

  1. Open the terminal by pressing Ctrl+Alt+T or by searching for "Terminal" in the dashboard.
  2. Navigate to the directory where you want to create the file. You can use the cd command to change directories. For example, to navigate to the Desktop directory, you can use the command:
1
cd Desktop


  1. Once you are in the desired directory, you can use the touch command to create a new file. For example, to create a file named myfile.txt, you can use the following command:
1
touch myfile.txt


This will create an empty file named myfile.txt in the current directory.

  1. If you want to create a file with some initial content, you can use the echo command along with the > operator to redirect the output to a file. For example, to create a file with the text "Hello, World!" you can use the following command:
1
echo "Hello, World!" > myfile.txt


This will create a file named myfile.txt with the text "Hello, World!" inside it.

  1. If you want to create a file and open it in a text editor so you can start editing it immediately, you can use the nano command. For example, to create a file named myfile.txt and open it in the nano text editor, you can use the following command:
1
nano myfile.txt


This will open the myfile.txt file in the nano text editor, and you can start editing it right away. When you are finished, press Ctrl+X to exit the editor and save your changes.

Member

by emie , a year ago

@modesta 

This is a very detailed explanation and tells you a lot about creating a file in Ubuntu using terminal.


An alternative and simpler way to create a new file in Ubuntu using the terminal is to use the touch command.


Here's how you can do it:

  1. Open the terminal by pressing Ctrl+Alt+T or by searching for "Terminal" in the dashboard.
  2. Navigate to the directory where you want to create the file. You can use the cd command to change directories. For example, if you want to create the file on your Desktop, you can use the following command: cd ~/Desktop
  3. Once you are in the desired directory, you can use the touch command followed by the file name to create a new file. For example, to create a file named "myfile.txt", you can use the following command: touch myfile.txt This will create an empty file named "myfile.txt" in the current directory.


That's it! You have successfully created a new file using the terminal in Ubuntu.