LPI 010-150 – Browsing the Filesystem

  1. Copying Files

Let’s use LS for the current directory to list the contents of the current directory and to display where I am, I will use PWD. So to copy a file use Command with a source and a target argument for example the source which we will use in our example file one which is located in the current working directory which is homemeassine and we will copy this file one two tentdirectory. So if we list temp directory we will see that file zero one is there. To clear the screen we will use clear command. If we copy the same file, copy file one in the same location for example with file zero three in the same location then list the content of the current directory we will see that file zero one has been copied and at the same time it’s renamed to file three. If we list the content of diar one we will see it has some files. If we copy this directory Diarr one using CP command into dire zero two the command will fail because Diarr one has some files. So to copy dial one with the entire files we will use CP with or option.

So now if we list LS dire zero two we will see that Diarr one is there. So our option will copy the directory which has some files. We can copy many files in the same command using CP. For example file one, file two file zero three to anywhere for example temp directory. If we list the content of slash temp we will see that file zero one, file zero two and file zero three are there. So to run the same command and prevent CD from overwriting existing files we can use I for interactive mode option. Here it will ask if we need to override file zero one or not. If we press no it will not override one and the same. For file zero two we will press n and the same for file file three we will type in and press enter. So I option is very useful to prevent CPU comment from overwriting existing files.

  1. Soft and Hard Links

In this lesson we will learn the difference between hard links and soft links. The hard link is when we create a hard link to a file with the command LDN an extra entry is added in the directory a new file name is mapped to an existing in wood. So for example build if we create hard link for file one using lam file one then the hard link name for example hard link to file one. Now if we list the contents of the current directory we will see that file one and hard link to file one has the same inode number. The inode number is located in the file system and it has information about the files such as the permissions of the files, the owner of the files, the group owner of the files and the last modification date of the file.

When we create the hard links both files have the same inode as we mentioned here so they will always have the same permissions as we can see here and the same owner both files will have the same content. So if we cat file one then cat file hard link to file one we will see that both files have the same content. Actually, both files are equal now. Meaning you can safely remove the original file using RM command file one then press Y, then enter to remove file one. And we can see that the hard linked file will remain the same with the original content.

As we can see here, the inode contains a counter containing the number of hard links to itself. So right now we have only one hard link to this file. And before we had two links to this file. So this number defines the number of hard links to specific file. When the counter drops to zero then the inode will be free so if we remove the hard link file using RM command it means all data has been removed from the hard disk and now the inode is free. The hard link should be created in the same partition or in the same file system it means if we have file and we need to create hard link for this file so the hard link and the file should be created in the same partition. Now let’s clear the screen using clear commands the symbolic link is sometimes called soft links don’t link to anodes but create NEM two name mapping it means it will create symbolic link to the original file and it’s the same concept of the shortcuts in Windows. To create the soft link let’s create file called file one using touch command then let’s edit this file for example this is example for soft link then save the file to create soft link or symbolic link to file one.

We will use Ln S for soft link or symbolic link. Then followed by file one the source, then the symbolic link name. For example, SIM link to file one. Now if we list the content of the current directory using LS L I we will see that the symbolic link same link to file one has different inode number and here it’s referred to file one which is the source of the symbolic link. And notice here the permission on the source file. It’s different than the permission on the symbolic link.

And the permissions on the symbolic link have no meaning since the permissions of the target apply, the symbolic link can be created in different partition or in different file system. It means we can create file one in a specific partition then we can create its symbolic link in another partition. To remove the symbolic link or the hard link we will use RM command followed by the same link file. Now if we list the contents of the current directory using Ilischild I we will see that the symbolic link has been removed and its inode becomes free.

img