Create Files and Directories in Linux

In this Linux tutorial I will discuss the command for creating new file and directories. If you want to create a new file than Touch command in Linux is used for that purpose.

$ touch new.file

This command creates a new, empty file.

If you check the file size by using the ls -l new.file command, it will show zero bytes. It might look ugly to create an empty file but it can be used to find out that whether you have file creation rights in a particular directory or not.

If you need to create a file with some text than Echo command is used for that

$ echo “My Birthday on 21st Jan 1984.” > Birthday

This command will create a file with the name Birthday with one line in it. The echo command is normally used to print the text on console but here we have save the output text in the file with the name of Birthday.

The cat command is issĀ  ued to create a multiline file in Linux

$ cat > Information.socks
This is the test multiline file
This is the test multiline file
This is the test multiline file

The above example cat command used to create file with the name of information.socks which save three lines in a file.

Creating Directories

Directories are always helpful to organize the files, if you have files spread in the home directory than you can place it on one directory or multiple directories.

The mkdir command is used to create the directory in Linux

$ mkdir documents

This will create a directory with the name of documents in which you can place your stuff.

Be Sociable, Share!

Leave a Reply