To find the name of a directory from its path in Unix, you can use the basename
command.
For example, to find the name of the directory /home/user/documents
, you can use the following command:
basename /home/user/documents
This will output the name of the directory, documents
, without the leading path.
You can also use the dirname
command to find the name of the parent directory of a file or directory. For example, to find the name of the parent directory of the file /home/user/documents/file.txt
, you can use the following command:
dirname /home/user/documents/file.txt
This will output the name of the parent directory, documents
, without the trailing file name.
Overall, the basename
and dirname
commands are useful tools for finding the names of directories and files from their paths in Unix.