In this article, we will show how to easily create an empty file in Linux operating system distribution. It is created by simply execute the following command in a Command Line Interface (CLI) which is represented by a bash prompt display.
Access the bash prompt terminal in Linux operating system distribution and type the following command :
touch filename Description : touch : the command used to create an empty file filename : value parameter which is needed by the command 'touch' in order to create an empty file with the name 'filename'
For the example in real execution is given below :
First of all, check the content of the directory where the file is going to be created. It is actually needed to prove the difference between the condition before the execution of the command and the condition after it.
The content before command execution :
<pre>user@hostname:~/test-folder$ ls -al total 44 drwxrwxr-x 2 user user 4096 Sep 3 22:31 . drwxr-xr-x 115 user user 20480 Sep 15 15:54 .. -rwxr-xr-x 1 user user 52 Sep 3 21:30 my-bash-script -rw-rw-r-- 1 user user 32 Aug 27 14:38 test-file-1 -rw-rw-r-- 1 user user 32 Aug 27 14:38 test-file-2 -rw-rw-r-- 1 user user 32 Aug 27 14:39 test-file-3 user@hostname:~/test-folder$
We are creating a new file named test-file by executing the following command :
touch test-file
After executing it in the bash prompt, try to recheck the content of the directory where the file has already been created by executing the command as shown below :
user@hostname:~/test-folder$ ls -al total 44 drwxrwxr-x 2 user user 4096 Sep 15 17:20 . drwxr-xr-x 115 user user 20480 Sep 15 15:54 .. -rwxr-xr-x 1 user user 52 Sep 3 21:30 my-bash-script -rw-rw-r-- 1 user user 0 Sep 15 17:20 test-file -rw-rw-r-- 1 user user 32 Aug 27 14:38 test-file-1 -rw-rw-r-- 1 user user 32 Aug 27 14:38 test-file-2 -rw-rw-r-- 1 user user 32 Aug 27 14:39 test-file-3 user@hostname:~/test-folder$
As we can see in the above output display there is a new file named test-file created in the test-folder directory. Be very careful to execute the touch command by checking the folder’s permission. In the context of folder’s permission, before creating the file using ‘touch’ command, check the folder’s permission first to make sure that the user executing the command has a write permission inside the folder. It can also be done by typing or executing the ‘ls -al’ command in the right place as shown below :
Switch first to the home folder of user by typing the ‘cd’ command as shown below :
user@hostname:/test-folder$ cd
Type to list the content of the home folder while piping the output of the command through the ‘|’ sign and sort it with the name of the folder which is going to be searched for the permission’s info :
user@hostname:~$ ls -al | grep test-folder drwxrwxr-x 2 user user 4096 Sep 22 14:10 test-folder user@hostname:~$ Description : d : It is for marking that the test-folder is a directory the first rwx : It is a permission label of the test-folder directory for the owner whom the owner itself can read, write and execute. In the above context is 'user' the second rwx : It is a permission label of the test-folder directory for the group whom th group itself can read, write and execute. In the above context is also 'user'. r-x : It is also a permission label of the test-folder directory for other than owner and group.
As the informationi shown above, user has write permission represented with ‘w’ character in the permission label information above not only in the owner permission but also on the group permission.
One thought on “Create empty file in linux”