Aug 132018
 

As I say often, there are many ways to skin a Linux cat.

Here are a few ways to create a new file on a Linux system.

I have tested the following commands on CentOS 7 and Linux Mint 18.

Creating a New File

1. Touch method

$ touch file_name

Example:

$ touch jennifer

$ ls
Interview-Questions       Favorite-Beer.txt             REdHat-Release-Dates.odt               Ubuntu-Tips
jennifer

2. Echo method

$ echo -n > New_file

Example:

$ echo -n > sammy
$ ls
Desktop  Documents  Downloads  Music  Pictures  Public  sammy  Templates  Videos  VirtualBox VMs

3. Echo method with some content in file

$ echo jack and jill went up the hill > new_file

Example:

$ echo jack and jill went up the hill > donald_trump
$ ls
Desktop  Documents  donald_trump  Downloads  Music  Pictures  Public  sammy  Templates  Videos  VirtualBox VMs
$ ls
Desktop  Documents  donald_trump  Downloads  Music  Pictures  Public  sammy  Templates  Videos  VirtualBox VMs
$ cat donald_trump
jack and jill went up the hill

4. Quickie Method

$ > New_File

$ > Hillary_clinton
$ ls
$        Documents     Downloads        Music     Public  Templates  VirtualBox VMs
Desktop  donald_trump  Hillary_clinton  Pictures  sammy   Videos

5. Via Nano Text Editor

$ nano new_file

Once new_file is opened, hit ctr-o (i.e., the alphabet o and NOT zero).

You can also create a new file via the Vim text editor:

6. Use the Vim Text Editor

$ vi new_file

To save your new_file, hit Esc, then type :wq the file will then be saved and you will exit vim.

Sorry, the comment form is closed at this time.