FILE AND DIRECTORIES IN LINUX

From the previous text, I introduced some of the basic commands in LINUX Operating System. From this text I’m going to introduce you some of more advanced and more important part, Files and Directories.

WHAT ARE FILES AND DIRECTORIES?

Files are the place where to store data and programs. It could be a text file, image file, etc. How ever everything is a file in LINUX. If it is not, it should be a process. Directories are also another type of file system where files are stored. Files are stored in a hierarchical structure within the LINUX system. A file should have a parent file and sometimes child files too.

WHAT IS A PATH?

One another most important things to talk about is, Path. Path is the location of a specific file stored in your computer. When dealing with files, you should have a clear idea about the path of a certain file. There are two ways how we can give the path of a file,

Absolute Path : Absolute path to a given file is the path from the root directory to that certain file. For example think about a file which is stored in a directory called new and that directory is in the Documents directory. So the absolute path for the file is,

/home/User/Documents/new/something.txt

Relative Path : Relative Path for a given file is concerned from the working directory. As an example, if the working directory is Documents for that instance, the relative path can be given as,

new/something.txt

WHAT ARE THE COMMANDS?

As now you have an idea about what is the path and how the path can be given in different ways, now we can go forward. There are so many commands related to directories and files in LINUX. Here I have given some of them in detail,

mkdir : This is the command use to create a new directory. The path, where the directory should be created, must give with the directory name.

rmdir : This will remove a directory in your file system. But one thing to be remembered is, to delete a directory it should be empty.

cp : Copy a file/ Directory from a certain place to another location. Source and the destination should be given as parameters.

mv : Move a file/ Directory from a place to another place. Source and the destination should be given as parameters. This can be used to rename as well. When doing renaming the destination will be replaced by the new name.

rm : Remove file from the file system.

touch : This is used to update the access and modification times of each file. If we gave a not existing file as the parameter, then it will create a file as well.

cat : This command can be used to concatenate files together. The concatenated result will be displayed on the terminal. Giving a single parameter will cause it to view the file.

less : This is another command to view files. But this shows it’s output on another page. So this command can be used to view larger files. To exit the new page and go to the previous page, just hit the ‘q’.

head : This will print the top lines of the file according to the given parameter. The number of lines to be displayed should be given as the parameter. The default value is 10.

tail : This will print the last lines of the file according to the given parameter. The number of lines to be displayed should be given as the parameter. The default value is 10.

wc : This will count the lines, words, letters of the file.

Those are the basic file manipulation commands in the LINUX Operating System. There are some more advanced things too. Hope to come back with another interesting text soon. Thank You!