UNIX operating system provides many command line tools and text editors for creating a text file. You can use vi (emacs or joe), a terminal-based text editor for Unix, available under the GPL. It is designed to be easy to use. In short, you can use any one of the following tool:
- Unix cat command
- echo or printf command
- vi text editor
- emacs text editor
- joe text editor
- Any other console based text editor
Method #1: Creating a file using echo command
Open the Terminal and then type the following command to create a file called demo.txt, enter:
echo 'The only winning move is not to play.' > demo.txt
printf 'The only winning move is not to play.\n' > demo.txt
OR create a file with two lines in demo-1.txt file:
printf 'The only winning move is not to play.\n Source: WarGames movie\n' > demo-1.txt
To examine the contents of the file you have just created is to type the following command at shell prompt:
Method #2: Creating a file using cat command
In this example, create a file named quotes.txt and enter one line of text in it, type the following at the shell prompt:
cat > quotes.txt
You need to press the [Enter] or [Return] key. Finally type the text:
There are some who question the relevance of space activities in a developing nation. To us, there is no ambiguity of purpose.
Again, press the [Enter] or [Return] key. To stop and save file entry by typing Control+d on a line by itself i.e Press and hold down the Control key and type d. On your screen you will see as follows:
cat > quotes.txt
There are some who question the relevance of space activities in a developing nation.
To us, there is no ambiguity of purpose.
Method #3: Create a text file using vi / vim text editor
vi / vim is a text editor. To create a file called text.txt, type:
$ vi bar.txt
Press i to insert new text. To save the file and leave vi, type ESC+:+x (press ESC key, type : followed by x and [enter] key).
How do I edit a file just created?
You need to use a text editor such as vi or emacs:
Grab mastering the VI editor pdf file for more information on how to use a text editor (see below for link).
- Learn more about vi here : Download mastering the VI editor pdf version.
- See man pages: ksh(1)
🐧 7 comments so far... add one ↓
|Category||List of Unix and Linux commands|
|Firewall||Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04|
|Network Utilities||dig • host • ip • nmap|
|OpenVPN||CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04|
|Package Manager||apk • apt|
|Processes Management||bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time|
|Searching||grep • whereis • which|
|User Information||groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w|
|WireGuard VPN||Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04|