The syntax of dirname command is
dirname NAME
The dirname command removes the trailing / component from the NAME and prints the remaining portion. If the NAME does not contain / component then it prints '.' (means current directory).
Dirname command is useful when dealing with directory paths in unix or linux operating systems. Some examples on dirname command are shown below:
Dirname Command Examples:
1. Remove the file name from absolute path.
Let say my directory path is /usr/local/bin/add.sh. Now i want to remove /add.sh and display only /usr/local/bin, then we can use the dirname command.
> dirname /usr/local/bin/add.sh
/usr/local/bin
2. dirname sum.pl
Here you can see that the NAME does not contain the / component. In this case the dirname produces '.' as the output.
> dirname sum.pl
.
0 comments:
Post a Comment