In Linux to create a file in command prompt

Date:

2019-06-25 02:00:29

Views:

919

Rating:

1Like 0Dislike

Share:

Table of contents:

Each user is useful to know how to use the Terminal app (command line) in Linux to create the file. At the end of this process you can use one of the built-in text editors for OS changes in a new file.

linux new file

Where to begin?

To Linux to create a file, first open a command prompt. To do this, press “Menu”, then locate the application “Terminal”, the icon of which resembles a black square with a white symbol on it. Click on it. Usually it is located on the left pane from the window menu. You can also click the search button at the top of this window, and then entering the request “Terminal” to search for it.

Enter ls in the opened command prompt, then press Enter. The terminal opens in your home directory and the above command displays each folder in your current directory. To create a text file in Linux in one of them, you will need to change the current directory.

Choose directory

Locate the directory where you want to create a text file. Any directory name, the following ls command (e.g. “Desk”), is a place to which you can navigate.

Dial to create a file in Linux command cd. This action will take you to the name of your preferred directory. This command changes the focus to the command line the current directory to the one you call. For example, you must type cd Desktop to change the location of the command terminal to the Desktop directory.

create file linux command

If you want to create a text file in a specific folder in your chosen directory, you must specify the icon after his name, and then enter the folder name. For example, for a folder named Misc in directory ‘Documents» you must type cd Documents/Misc.

Then press Enter. This will lead to the fulfillment of your commands, and you move the target directory of the terminal from your home directory that you specified.

In Linux to create a file quickly?

Enter cat> filename.txt in the command line. Now you have to replace the “file name” in the preferred text name (for example “sample”). For example, when you create a file with the name kitty you should enter cat> kitty.txt.

Recommended

How to get out of

How to get out of "Skype" on the "Android" and not only

How to get out of "Skype" "Android"? This question bothers many users. The thing is that the messenger is not so difficult. But there are features that are only for mobile versions. To log out of Skype in this case more difficult than it seems. But i...

Kingo ROOT: how to use the program to gain administrative rights on Android

Kingo ROOT: how to use the program to gain administrative rights on Android

The Gadgets on the platform Android regained the lion's share of the market. Developers are continually perfecting the OS, trying to fit the needs of the users, but from year to year admit palpable mistake: forbid the owner to "stuffing" of his gadge...

How to get from Stormwind to Tanaris: practical tips

How to get from Stormwind to Tanaris: practical tips

World of Warcraft is an iconic MMORPG, uniting millions of players around the world. There are many locations and puzzles, secret trails and larger, but rather dangerous paths. Sooner or later, every player chose the side of the Alliance, we have to ...

Press the Enter key. This will allow you to create a new text file with the specified name in your current directory. The cursor will then appear on a blank line in the terminal.

create text file linux

This method is good for text documents and other data types. If you want to create a batch file in Linux using command line applications to work with text documents is not recommended.

Enter the text of the document

You can just enter letters and numbers, as is usually done for any other text document. To save the current line of text and go to next, press Enter. If you open the directory of the text file, you can also simply double-click it when it opens.

Press Ctrl + Z. This key command, save your work and return you to the command line terminal. This will allow you to continue typing other commands.

create batch file in linux

Enter ls-l filename.txt in terminal. Replace the file name by default, your name. This command will find your document, ensure that it is safe to create the directory.

For Example, to open a file with the name textfile, you must type ls-l textfile.txt. Notations in this code, have the lowercase letter L, not uppercase i, so be careful. Then, press the enter key. After that you have to see how it displays the time, date and the name of your file in the next line. This indicates that you have succeeded to create file in Linux terminal and save it.

Use text editing

You can quickly create an empty file in Linux or use Vim or Emacs to create and edit advanced. Now, when you are in the directory where you want to place a text document, it's time to proceed to establish it.

Application is a clone of the Vim text editors, vi for Unix. It was written based on the source port of the Stevie editor for the Amiga and first released publicly in 1991. The Vim editor designed for use both from a command line interface and as a standalone application in a graphical interface. It is free software and open source, released under the license.

Despite the fact that the program was originally released for the Amiga, Vim was later developed as a cross-platform editor that supports many other distributions. Today it is one of the most popular applications among Linux users.

create an empty file in linux

As vi, Vim's interface is based not on menus or icons but on commands specified in a text user interface. Its graphical interface, gVim, adds itself to menus and toolbars for commonly used commands but the full functionality is still in command-line mode.

Emacs is a family of text editors that are characterized by their extensibility. The most advanced version of the application, GNU Emacs,described as an extensible, customizable, self-documenting editor.

Development of Emacs the first generation began in the mid 1970-ies, and work on improving the latest version of the GNU continues to the present.

Emacs has more than 10,000 built-in commands, and its interface allows the user to combine these commands into macros to automate work. In addition, the implementation of this software usually contain a dialect of the Lisp programming language, which provides a deep extension capabilities, allowing users and developers to write new commands and applications for the editor. Separate plugins have been written to manage email, files, contours and RSS feeds.

create file in directory linux

Emacs with vi is one of the two main traditional editors on Unix-like systems. Both apps are some of the old applications which are still widely used and continue to develop.

Using Vim for file

Enter vi filename.txt in the command line. Part vi in this command fetches the text editor Vim to be used with the program. The rest of replace filename with the name that you want to assign to a new file.

For Example, for a file with the name tamins you need to enter vi tamins.txt. If your current directory there is a document with the same name, this command will open it. If this name is unique – you can in Linux to create a file from scratch with the above program.

Press the Enter key. This will allow you to create your new file and open it in the editor Vim. You should now see a blank terminal window with the tilde ~ in each row, and the name of your text file at the bottom of the window.

Press the i key on the keyboard of your computer. This will place the document in the “Insert”, in which you can enter text as needed. You should see a submenu of the INSERT (it will appear at the bottom of the window) when you press I.

Enter the text of the document. You can just type the characters as you would typically do this for any other text document. To save the current line of text and go to next, press Enter.

After that, press the Esc key. Usually it is in the upper left corner of the keyboard of your computer. This key will put Vim into Command mode. After clicking you should see that the cursor appears at the bottom of the window.

Enter w in the terminal and press Enter. This saves your document in the form in which it is at the moment. After that, type the command line q and then hit the enter key. This will cause you to exit Vim and return you to the main interface of the terminal. Your text file is now located in the specified directory.

You can check the new text file, by typing ls at the command prompt and pressing the ↵ Enter. After that you can search by file name in the opened interface. You can also enter the command wq to save and exit from one team. After that, you can be sure that you have got to create a file in the Linux directory.

create a link to file linux

Return a file from a terminal window. As and when it is created, you must enter the command vi filename.txt to open it. This time, when you open the file, you will see all the saved changes you have made.

Using Emacs

You can also in Linux to create a file using Emacs. To do this, type the command emacs filename.txt in terminal. You must replace filename with your chosen name for the text file. Press Enter. While the name of your text file is not a duplicate of an existing similar document in your current directory, this command will open a new text file in the Emacs editor.

For Example, a file named newfile will need to enter emacs newfile.txt. If you enter an existing name the text document, this command instead opens the corresponding file.

How to work with teams?

Check out Emacs commands. This app comes with a host of powerful commands that allow you to navigate the document, search for the related or reference information, to manipulate the text and decipher your code. These teams are divided into two types: control and meta commands.

The First group is written like this: C- <letter>. For example, to execute the Control command, you need to hold the Ctrl button and simultaneously press the indicated letter key (e.g. Ctrl and A).

The Meta (or Escape) are written as follows: M- <letter> to ESC or <letter>. “M” refers to the Alt key or Esc key (depends on the model and design computer).

Command, written as C-a b (or M-a b), will require you to hold Ctrl (or Alt or Esc) when you press the first key (for example, and then release both buttons and immediately press the second key (e.g., b)).

Enter the text of the document. You can dial it in the same way as you do for any other text document. To save the current line of text and move to the next, press the enter key.

Press Ctrl + X, then S. All activity performed by you will be saved.

Then, run pressing the buttons Ctrl + X and then Ctrl + C. This will allow you to exit the text editor Emacs and return you to your directory in Terminal. Now your text document will be saved under your chosen name in the directory. To create a link to a Linux file, you will need to enter in the terminal command with his name.

Re-open the text file. Forjust type emacs filename.txt at the command prompt. While you are in the same directory, the above command will open your text file in Emacs, then you can continue edit at its discretion.

Tips

The Vim is usually available in any version of Linux, and Emacs is more complex editor that is installed to a more recent OS distributions. However novice it may be easier to use this program.

You can invoke the help screen Emacs by pressing Ctrl + H, then releasing both buttons and pressing T. In the menu “help” will display more command keys, and other editor functions that can help you in creating and writing the file.

Warning

If you do not save the document before you close it, the warning may not be displayed, especially in the Vim editor. So always save a document before closing it.


Article in other languages:

AR: https://tostpost.com/ar/computers/18032-in-linux-to-create-a-file-in-command-prompt.html

BE: https://tostpost.com/be/kamputary/34591-yak-u-linux-stvaryc-fayl-u-kamandnym-radku.html

DE: https://tostpost.com/de/computer/34284-wie-in-linux-eine-datei-in-der-befehlszeile.html

ES: https://tostpost.com/es/equipos/34146-como-en-linux-para-crear-el-archivo-en-el-s-mbolo-del-sistema.html

HI: https://tostpost.com/hi/computers/19680-in-linux-to-create-a-file-in-command-prompt.html

JA: https://tostpost.com/ja/computers/17688-linux-controlelr.html

KK: https://tostpost.com/kk/komp-yuterler/34899-ret-nde-linux-ru-fayldy-komandaly-zholynda.html

PL: https://tostpost.com/pl/komputery/35951-jak-w-linux-utworzy-plik-w-wierszu-polecenia.html

PT: https://tostpost.com/pt/computadores/35753-como-no-linux-para-criar-um-arquivo-em-um-prompt-de-comando.html

TR: https://tostpost.com/tr/bilgisayarlar/31324-nas-l-linux-bir-dosya-olu-turmak-i-in-komut-sat-r-nda.html

UK: https://tostpost.com/uk/komp-yuteri/35129-yak-v-linux-stvoriti-fayl-u-komandnomu-ryadku.html

ZH: https://tostpost.com/zh/computers/6009-linux.html






Alin Trodden - author of the article, editor
"Hi, I'm Alin Trodden. I write texts, read books, and look for impressions. And I'm not bad at telling you about it. I am always happy to participate in interesting projects."

Comments (0)

This article has no comment, be the first!

Add comment

Related News

Emoji is a way to Express feelings or to confuse the interviewee?

Emoji is a way to Express feelings or to confuse the interviewee?

With the development of social networks there are many ways to help you quickly and concisely Express your emotions. In addition, many words have acquired their abbreviated forms - "ATP”, “BB”, “NT&rdq...

How to install

How to install "GTA: San Andreas" from various sources?

the Installation of computer games is one of the most difficult moments, because not always everything goes according to plan - sometimes errors occur, the computer may freeze, or the game is installed, and then will not start. So...

What you need to know about the ranking of Dota 2?

What you need to know about the ranking of Dota 2?

ESports each year is becoming closer to the masses, thus in some countries it is even a real sport. Perhaps every student and adult dreams of becoming a professional player, because to get money and play – it's a real Paradi...

How to delete a file on a remote computer and how to restore it?

How to delete a file on a remote computer and how to restore it?

Surely everyone there were times when he mistakenly removed the wrong file. Many are beginning to panic from not knowing how to recover deleted computer files, whether they are in the recycle bin or completely deleted. However, th...

Nvidia GeForce GTX 470: specifications, overview

Nvidia GeForce GTX 470: specifications, overview

NVIDIA is engaged in quite a long time, detailed architecture development to keep the high competitiveness of the produced products. Thus, in the majority of cases, approximately two years is spent by the company to move from one ...

How to improve video quality in the software player

How to improve video quality in the software player

Computing power of modern computers increase with each new model. Partly already even eliminated as unnecessary the need to "acceleration" of their components. However, as is often the case, upgrading the software compon...