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
echo dirname/filename* | xargs ls -t
As a substitute doesn't give the results desired when I exceed the buffer size. I still want the files listed in chronological order, unfortunately xargs releases the names piecemeal...does anyone have any ideas? :( (4 Replies)
can anyone help me with stripping an absolute filepath? I did a search on this topic but didnt find anything but maybe I didn't look hard. Anyway, would really appreciate it if anyone could help me. I am a new unix user so this might be a simple issue but I am stuck, don't really understand the use... (4 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)
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
I faced with some interesting behavior of basename and dirname functions from libgen.h: they changes the value of argument! Here is the declaration:
char *basename(char *);
char *dirname(char *);It makes some tiresome to use them... I am new to C and maybe I do something wrong, but to... (4 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)
Hi
I would like to extract the first portion of filename from a list of files.
The filename pattern is of the form 123456789_TEXT_TEXT_TEXT_.csv. I want to extract just the numerical portion of this filename from the list of files and then output this into another text file.
K (6 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)