Different ways to create a file in Linux ?

Today we will look at a very basic article to know various ways to create a file in linux.

Lets see the various commands below.

1. Touch command

[root@ngelinux ]# touch file1.txt
[root@ngelinux ]# ls -l file1.txt
-rw-r--r--. 1 root root 0 Apr 4 14:12 file1.txt
[root@ngelinux ]# date
Thu Apr 4 14:12:44 EDT 2019
[root@ngelinux ]#

 

2. Cat command

[root@ngelinux ]# cat > file2.txt
Welcome to NGELinux.com. This is sample file2.txt
^C
[root@ngelinux ]# cat file2.txt
Welcome to NGELinux.com. This is sample file2.txt
[root@ngelinux ]#

 

3. Echo command

[root@ngelinux ]# echo "Welcome to NGELinux.com. This is sample file3.txt created by echo command" > file3.txt
[root@ngelinux ]# cat file3.txt
Welcome to NGELinux.com. This is sample file3.txt created by echo command
[root@ngelinux ]#

 

4. Printf command

[root@ngelinux ]# printf "file4.txt created by printf command" >> file4.txt
[root@ngelinux ]# cat file4.txt
file4.txt created by printf command[root@ngelinux ]#

 

5. Nano text editor

[root@ngelinux ]# nano file5.txt
[root@ngelinux ]# cat file5.txt
This is file5.txt created using nano editor
[root@ngelinux ]#
Press Ctrl+O, then return and then Ctrl+X to save and exit from nano editor.

 

6. Vi or VIM(Vi IMproved) text editor

[root@ngelinux ]# vi file6.txt
[root@ngelinux ]# cat file6.txt
File created using VI
[root@ngelinux ]#

Press i to enter into insert mode and write.
Press “:wq” to write and quit from the editor.

Leave a Reply

avatar
  Subscribe  
Notify of