BASENAME(1) BSD General Commands Manual BASENAME(1)NAME
basename, dirname -- return filename or directory portion of pathname
SYNOPSIS
basename string [suffix]
dirname string
DESCRIPTION
basename deletes any prefix ending with the last slash '/' character present in string, and a suffix, if given. The resulting filename is
written to the standard output. A non-existent suffix is ignored.
dirname deletes the filename portion, beginning with the last slash '/' character to the end of string, and writes the result to the standard
output.
EXIT STATUS
Both the basename and dirname utilities exit 0 on success, and >0 if an error occurs.
EXAMPLES
The following line sets the shell variable FOO to /usr/bin.
FOO=`dirname /usr/bin/trail`
SEE ALSO csh(1), sh(1), basename(3), dirname(3)STANDARDS
The basename and dirname utilities conform to IEEE Std 1003.2-1992 (``POSIX.2'').
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
I have to login to a linux machine and I need help with chmoding a directory so that I may copy read and write to it if you know what muds are and you know about logging into a shell, then you know what im talking about! well thanks! :confused: (2 Replies)
I've got one I haven't been able to figure out.
1. A shell script exists- /junk/junk1/junk2/junk3.sh
2. From within the above named shell script, I want to know the full path of the above named shell script. Even if I execute the shell script from a directory other than the one it resides in,... (5 Replies)
I tried looking for the answer online and came up with only a few semi-answers as to why file and directory names are case sensitive in Unix. Right off the bat, I'll say this doesn't bother me. But I run into tons of Windows and OpenVMS admins in my day job who go batty when they have to deal... (3 Replies)
Hello all,
Can somebody explain to me how set up a basename and dirname variable to simplify this script. I currently have a 'infile' with the contents of FTTPDataPVC_ & BaaisDSLFeed. I need to add a basename and or dirname variable so that any additions can be made through the infile and not... (1 Reply)
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 guys, last cry for help for today. I appreciate the help so far.
ok so I have a program that dumps a path into my script as a variable ($1)
This path is an example
/home/xbmc/sab_downloads/video/tv/grey's anatomy/season 3
So in order to search thetvdb.com for a show, I need to extract... (6 Replies)
Hi there,
Is there any way to obtain a real path from a weird path. For example :
/foo/../bar/ -> /bar/
/foo/. -> /foo/
Thanks in advance
Santiago (5 Replies)
Hi all,
my problem:
(little extract from my bash-script)
I want to move each file (.mov) from one directory (and many Subdirectories) to another directory (only one);
after moving i want to create hardlinks to the old directories.
Thatīs no problem, but now:
source-directories... (4 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
as output i get a directory (i don't know its name) with many files inside.
Now i need to find the directory name and change it as i need.
I can found a directory name with this command:
find -maxdepth 1 -type d | grep out
Now i'd like to assign it to a variable and change it. ... (4 Replies)
I have a script in which i want to print absolute path of the same script irrespective of path from where i run script.
I am using
test.sh:
echo "pwd : `pwd`"
echo "script name: $0"
echo "dirname: `dirname $0`"
when i run script from /my/test/dir/struct as ../test.sh the output i... (10 Replies)
Hi, okay, the following command was given to me in a script, but it's not working and there's little to no help on dirname. What is wrong with the following line? I'm just trying to save the current directory to use later in subsequent scripts.
MYAPPDIR=$(dirname $(dirname $0))
Thanks. (2 Replies)
We are using #!/bin/sh
From a command line this command returns the correct list of files (without going into any subdirectories)
find /vol.prod/saptrans/common/test/pa/* -prune -type f -print
We have a script which takes the same path as $1 (without the * )
... (2 Replies)
Hello,
I have a list of files generated like this:
find dir -type f > file_list
I want to get a list of just the unique directories. I can't create a temporary file. So the idea is to do a working equivalent to this:
cat file_list | dirname | uniq
But of course that doesn't... (4 Replies)
Hello,
I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)