Breaking News

How to create a file using touch and cat commands

Creating a file in Linux is very simple and it will take few steps! We want to create a file on a Desktop.
I'm using a Kali Linux but don't worry, any version apart from this Kali the command can work.

  • Open your Linux Machine
  • Now Open terminal (This will be used to write a command that will create a file)

  • On Terminal, type the following command and press enter
  • cd /root/Desktop (This will change the current directory to Desktop)

  • Now type the following command while you are at Desktop and press enter.
  • Starting with touch command...
  • touch my_file (This command will create a text file called my_file, you can name it whatever you want)

  • As you can see, the text file has been created named my_file.
Now, lets do the same thing by using cat command.
  • Note: When you are using a cat command, you have to write a content of that file during a time creating process, and you can override or append by using (>) or (>>) signs. The following statements will make this clear!
  • On terminal, type the following command.
  • cat > File (This command will create a text file called File, and gives you the ability to write a content on it but if the file name is already exist, it will override/replace the existing contents because we used (>) sign. But if we would use (>>) we would append contents if already there are contents on it)

  • Finally, press Ctrl + d to exit and save the content.
  • As you can see on my Desktop (top left corner) the file named File has been created.
Please comment and share with your friends. The next post will be on how to create a file within a directory and manage them (Read, Rename and Delete Files/Directories)


    1. Replies
      1. Thank you and you are most welcome....!! Please share with your friends...!!!