basename

What is the best way to do string manipulation in a shell script?

I have a path as a string in a shell-script, could be absolute or relative: /usr/userName/config.cfg or ../config.cfg I want to extract the file name (part after the last /, so in this case: "config.cfg") I figure the best way to do this is with some simple regex? Is this correct? Should or should I use sed or awk instead? Shell...

bash: how to change the basename only of a list of files

Hi all, I have a lit of files (which I get from find bla -name "*.so") such as: /bla/a1.so /bla/a2.so /bla/blo/a3.so /bla/blo/a4.so /bla/blo/bli/a5.so and I want to rename them such as it becomes: /bla/liba1.so /bla/liba2.so /bla/blo/liba3.so /bla/blo/liba4.so /bla/blo/bli/liba5.so ... i.e. add the prefix 'lib' to the basename any ...

makefile: how to add a prefix to the basename ?

Hi all, I have a list of file path like that: FILE_PATH := a1.so a2.so bla/a3.so bla/a3.so bla/blo/a4.so.... I need to add a prefix to the basename in order to get: FILE_PATH_PREFIX := liba1.so liba2.so bla/liba3.so bla/liba3.so bla/blo/liba4.so.... any idea ? Cheers dave ...

PHP - Get the file extension (basename?)

Hello there! If I have a code like this: $file = basename($filename); How do i get the file extension of $file? The variabel file could contain any kind of file, like index.php or test.jpeg. ...

Extract the last directory of a pwd output

How do I extract the last directory of a pwd output? I don't want to use any knowledge of how many levels there are in the directory structure. If I wanted to use that, I could do something like: > pwd /home/kiki/dev/my_project > pwd | cut -d'/' -f5 my_project But I want to use a command that works regardless of where I am in the dire...

How to extract the name of immediate directory along with the filename?

I have a file whose complete path is like /a/b/c/d/filename.txt If I do a basename on it, I get filename.txt. But this filename is not too unique. So, it would be better if I could extract the filename as d_filename.txt i.e. {immediate directory}_{basename result} How can I achieve this result? ...

Isn't Using the basename function with $_FILES['userFile']['name'] Redundant?

According to the POST method uploads section of the PHP Manual, $_FILES['userfile']['name'] is the original name of the file on the client machine. Example #2 in that section uses the basename function with $_FILES['userfile']['name'] like the following: $uploaddir = '/var/www/uploads/'; $uploadfile = $uploaddir . basename($_FILES['user...

cakephp how to set base path

hi How do I set the root of the application? What I mean, is that when I work locally, everything is under the root of my local website (i.e www.in cake.local/). Now I made an application that will not be at the root of a website (i.e. www.outsite.com/sciences/biology/here_is_my_app). Is there a way to make absolute URL in my app p...

DOS BAT file equivalent to Unix basename command?

Is there an easy way to get to the basename (file name without extension) of a DOS file name using the DOS BAT command language? I agree: format c:\ is probably a good start, followed by a bootable Linux CD (assuming these antique machines have a CD reader - not a given). But let's pretend that we only have DOS... (That means: not Win...

Multiple basename() extensions

Hello everyone. We have: $path = "/home/httpd/html/index.php"; $file = basename($path); // $file is set to "index.php" $file = basename($path, ".php"); // $file is set to "index" $file = 'index'; // the result How can we query a multiple file extensions? Instead of $file = basename($path, ".php"); something...

I want a to compare a variable with files in a directory and output the equals

I am making a bash script where I want to find files that are equal to a variable. The equals will then be used. I want to use "mogrify" to shrink a couple of image files that have the same name as the ones i gather from a list (similar to "dpkg -l"). It is not "dpkg -l" I am using but it is similar. My problem is that it prints all the...

Basename quirks - what are they

The documentation for File::Basename says NOTE: "dirname()" and "basename()" emulate the behaviours, and quirks, of the shell and C functions of the same name. See each function's documentation for details. What are these quirks? ...

Where does the dirname/basename terminology originate?

What are the origins and reasons for the terms, dirname and basename, referring to the path with the trailing component removed, and the trailing component respectively? Is the terminology standardized, and where? Are there alternative or equivalent conventions in use to refer to the splitting of a path in this way? Update0 In partic...