BASENAME(1) BSD General Commands Manual BASENAME(1)NAME
basename, dirname -- return filename or directory portion of pathname
SYNOPSIS
basename string [suffix]
basename [-a] [-s suffix] string [...]
dirname string
DESCRIPTION
The basename utility deletes any prefix ending with the last slash '/' character present in string (after first stripping trailing slashes),
and a suffix, if given. The suffix is not stripped if it is identical to the remaining characters in string. The resulting filename is
written to the standard output. A non-existent suffix is ignored. If -a is specified, then every argument is treated as a string as if
basename were invoked with just one argument. If -s is specified, then the suffix is taken as its argument, and all other arguments are
treated as a string.
The dirname utility deletes the filename portion, beginning with the last slash '/' character to the end of string (after first stripping
trailing slashes), and writes the result to the standard output.
EXAMPLES
The following line sets the shell variable FOO to /usr/bin.
FOO=`dirname /usr/bin/trail`
DIAGNOSTICS
The basename and dirname utilities exit 0 on success, and >0 if an error occurs.
SEE ALSO csh(1), sh(1)STANDARDS
The basename and dirname utilities are expected to be IEEE Std 1003.2 (``POSIX.2'') compatible.
BSD April 18, 1994 BSD
Check Out this Related Man Page
BASENAME(1) BSD General Commands Manual BASENAME(1)NAME
basename, dirname -- return filename or directory portion of pathname
SYNOPSIS
basename string [suffix]
basename [-a] [-s suffix] string [...]
dirname string
DESCRIPTION
The basename utility deletes any prefix ending with the last slash '/' character present in string (after first stripping trailing slashes),
and a suffix, if given. The suffix is not stripped if it is identical to the remaining characters in string. The resulting filename is
written to the standard output. A non-existent suffix is ignored. If -a is specified, then every argument is treated as a string as if
basename were invoked with just one argument. If -s is specified, then the suffix is taken as its argument, and all other arguments are
treated as a string.
The dirname utility deletes the filename portion, beginning with the last slash '/' character to the end of string (after first stripping
trailing slashes), and writes the result to the standard output.
EXAMPLES
The following line sets the shell variable FOO to /usr/bin.
FOO=`dirname /usr/bin/trail`
DIAGNOSTICS
The basename and dirname utilities exit 0 on success, and >0 if an error occurs.
SEE ALSO csh(1), sh(1)STANDARDS
The basename and dirname utilities are expected to be IEEE Std 1003.2 (``POSIX.2'') compatible.
BSD April 18, 1994 BSD
How to extract a portion of a string from a full string using unix.
For example:
Say source string is = "req92374923.log"
I want only the numeric portion of the string say "92374923" how to do that in Unix. (2 Replies)
Could someone please tell me what {} mean when they surround a variable?
For instance,
$FILE = 'basename $1' //what is passed into this script
$BANK = 'dirname $1'
$INFILE = ${FILE}.${BANK}.$$
What does $INFILE contain after this assignment?
Please let me know
Thanks
G (4 Replies)
I need to get the full path of a file minus the hostname... anyone have an easy way to do this?
What I have is:
//ourhostname/ourfullpath/filename
What I need is:
/ourfullpath/filename
hostname evaluates to 'ourhostname'
dirname evaluates to '//ourhostname/ourfullpath'
basename... (2 Replies)
Hi,
Can someone help me with this small piece of code.
DIRNAME=$(dirname $0)
BASENAME=$(basename $0)
DATA="${DIRNAME}/${BASENAME}.data"
&& . $DATA
whats is meant by && . $DATA here...
Regards,
Abhishek (2 Replies)
Hello
I have simple script that will accept as arg string like this :
".../foo/blah/,.../.../foo1/,.../blah"
now perl automatically removes the slashes "/" , I can't escape the slashes in the input I have to control on it
so how can I force perl to not touch this slashes?
Thanks ... (5 Replies)
Hi guys if i do
a=`basename -e -s /home/j/john/*`
du -k -h $a | sort -nr | head -10
why when i run the script does it work but also say usage basename string
any ideas thanks (9 Replies)
Hi
Can somebody please help me know how do i match the basename using a regular expression using posix standard in shell script
suppose i want to match
/u01/Sybase/data/master.dbf the result should be master.dbf as i want to match everything after the last /
regards (8 Replies)
I know you can remove trialing slashes using:
#echo "/tmp/one/two/three////" | sed "s,/$,,"
/tmp/one/two/three///
But I want to know how to make it remove all trialing flashes in the front, and in the start, so the end result is:
tmp/one/two/three
Anyone have any idea how to do this... (6 Replies)
I have a long string that looks something like this....
<string>http://abc.com/40/20/zzz061-3472/dP3rXLpPPV2KC846nJ4VXpH7jt4b3LJgkL/tarfile_date.tar</string>
I need to but the tar file name. So I need to put between "/" and ".tar</string>". My desired result should be "tarfile_date". (7 Replies)
i write a batch file , here is the content.
dirname='date +%Y-%m-%d'
mkdir dirname
but it doen's work, it just create a folder named date and +%Y-%m-%d.
i have tried run the command seperately in the bash prompt. after the first
sentence executed , i use $dirname to watch the value of... (4 Replies)
Hi,
I would like to add a suffix to a file name but maintain the suffix length to 5 digits.
For eg,
output > 1st_file.00001, 2nd_file.00002...10th_file.00010....100th_file.00100
Can anyone please advise me on how to go about it?
Platform: SunOS mps201a 5.9 Generic_118558-39 sun4u... (7 Replies)
I want to extract the filename from a string.
This is how I have the rawdata ina file
/home/sid/ftp/testing/abc.txt
/home/sid/ftp/tested/testing/def.txt
/home/sid/sftp/date/misc/hij.txt
i want a script which would provide me an output like this
Directory ... (10 Replies)
In COBOL, a hyphen can be used in a field name and in a specific program some field names would be identical to others except a suffix was added--sometimes a suffix to a suffix was used. For example, assume I am looking for AAA, AAA-BBB, and AAA-BBB-CCC and don't want to look at AAA-BBB-CCC... (7 Replies)
This is a two part request for an assistance.
I am not sure how retrieve value from basename command - line 270 -so in can be output as variable CLI_COMMAND - line 250 in whiptail input box.
As coded I can input from keyboard ( stdin?) into input box using redirection.
I can... (2 Replies)