DEV Community

Aishwary Prakash
Aishwary Prakash

Posted on

DevOps Interview:Absolute path and Relative path in Linux

Image description
Absolute path:
Absolute path is the path of any files or folders with respect to root directory (/) of the file system. It is always same.
e.g.- 1. /home/user/ec2-user/samplefile.txt → notice that it’s starting from “/” means root directory.
2. /etc/passwd
hence, you can say it’s a complete path of any file or folder.

Relative path:

Relative path is the path of any file or folder with respect to current working directory. As it’s name suggests “Relative” means there is comparison with current working directory.
e.g.- lets say current directory is “/home/user/ec2-user/documents/” (to find the path of current working directory, you can use “pwd” command)

  1. ../../ec2-user/documents/doc1.txt

hence, you can say relative path is used to denote files or folders that is present in same directory as the current working directory.

Now, you have got idea about both types of path. So, let’s check the differences on different metrics.

  1. Absolute path always strarts from “/” root directory. But, relative path doesn’t.
  2. Absolute path is always same irespective to current directory. But, relative path depends on current directory.
  3. Absolute path is used to access files or folders from anywhere in system. But, relative path is used to access from current directory.
  4. Absolut path may be lengthy when there are more subdirectories. Relative path is precise and efficient.
  5. Absolute path is more explicit than relative path. It is easy to read absolute path and understand the flow.

Hope you enjoyed it!!

Top comments (3)

Collapse
 
m0n0x41d profile image
Ivan Zakutnii • Edited

The every devops interviewer be like:

  • "Can you explain why, after deleting 5TB of files, the 'df -h' command still shows that the space has not been reclaimed?"

Image description

Collapse
 
devopstune profile image
Aishwary Prakash

I would reply to interviewer like-

  1. When you delete a file, it's marked as 'deleted' but not removed from the disk immediately. If the file is being used by any process then space on disk will be used continuously.
    To check if any processes are holding onto the deleted files, you can use the 'lsof' command and if you find the processes, you need to kill them before space reclaim.
    note:
    You can also use the 'fuser' command to check if a file is being used by any process. It will show process ids of the processes using the file if the file is open. otherwise, it will not produce any result.
    e.g.- fuser

  2. It may take sometime maybe minutes or even hours for the filesystem to complete this process.

  3. If the filesystem is corrupted, it will not monitor or track the space that is being used by files.

  4. You can run filesystem check using 'fsck' command to check for inconsistencies or error.

  5. You can use 'sync' command after deleting files so that changes are reflecting on the disk.

Hope this helps.

Collapse
 
m0n0x41d profile image
Ivan Zakutnii

Yeah, sure, you're right here. But I believe that you can bury yourself with such an answer to my concrete question, giving rise to many more questions.

Answering OPS interview questions should be as concrete as possible. If they don't explicitly ask for your reasoning, focus on providing direct responses.

In my experience, most interviewers asking this question just want to hear that you know filesystems have a limited number of inodes, and some processes can still hold pointers to 'deleted' files. They will ask you about concrete commands, etc., afterward if needed.