Linux dirname, basename (RPM)

Source: Internet
Author: User

First, use the--HELP parameter to see it. basename command parameters are very small and easy to master.

$ basename--help

Usage examples:
$ basename/usr/bin/sort Output "sort".
$ basename./include/stdio.h. H Output "stdio".

To specify a path for basename, the basename command deletes all prefixes including the last slash ('/') character, and then displays the string.

basename command format:
basename [pathname] [suffix]
basename [string] [suffix]

Suffix is a suffix, and if suffix is specified, basename will remove suffix from pathname or string.

Additional additions:
1. [Email protected]
[Email protected] is the parameter passed
2, $#
$# the number of parameters to pass
3, $?
is a shell variable that represents the exit state of the last execution command, and generally 0 indicates success, and a non-0 value indicates no success.
$? Always represents the exit state of the shell command after the last execution, and when the function is finished, if another command is executed, then $? no longer represents the state after the function is executed, but indicates the exit state of the other command.
4, $!
Represents PID, Process ID
5, $$
Represents ppid, parent process ID

6. $ A represents the shell command itself


First, dirname directive

1. Function: Remove the file name from the given file name containing the absolute path (part of the non-directory) and return the remaining path (part of the directory)

2. Usage: dirname filename
For example, here are a few examples
(1) # Dirname/etc/sysconfig/network-scripts/ifcfg-eth0
(2) # dirname/boot/grub/grub.conf
(3) # Dirname/etc/inittab
(4) # echo ' pwd ' && dirname modprobe.conf
(5) #echo ' pwd ' && dirname sysconfig/network-scripts/
Linux System Management
Second, basename directive

1, Function: Remove the left part of the directory from the given file name containing the absolute path or remove the content of a suffix (part of the directory), then return the remainder (non-directory part)

2. Usage: basename filename [suffix]
For example, here are a few examples
(1) #basename/etc/sysconfig/network-scripts/ifcfg-eth0
(2) #basename/boot/grub/grub.conf
BT4 Hack Wireless Network
(3) #echo ' pwd ' && basename sysconfig/network-scripts/
(4) # Basename/boot/grub/grub.conf.bak. bak


Linux dirname, basename (RPM)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.