Questions tagged [basename]

For questions pertaining to basename, a utility that returns the non-directory portion of a pathname.

Filter by
Sorted by
Tagged with
4
votes
1answer
126 views

the command find not working with -name option in sh file [duplicate]

I am using the following command to retrieve the number of files which names contains sv or json in a given directory in a remote server: nbs_files=`ssh -q -i ${sshkey} ${user}@${server} "find ${...
0
votes
3answers
56 views

Filename from pathname excluding (unknown) extension

Having a pathname it is possible to extract its filename, excluding its apriori known extension, with basename: $ pathname="/home/paulo/paulo.pdf" $ printf "%s\n" "$(basename $pathname .pdf)" paulo ...
0
votes
1answer
45 views

basename execution on remote node

ssh ubuntu@$ip -n "aws s3 cp s3://bucket/$userlistlocation . --region eu-central-1 ; fbname=$(basename '$userlistlocation') ; echo "$fbname"" This above command is part of jenkins job. ...
2
votes
1answer
199 views

basename “$0” not working

I have this command: base_name="$(basename "$0")"; and I am getting this error: basename: illegal option -- b usage: basename string [suffix] basename [-a] [-s suffix] string [...]...
0
votes
2answers
62 views

only use the filename for move

I have to move some files from one folder to another, criteria set by a find and grep. When I try to move the files it breaks. The actual move it's trying is mv /somefolder/export//somefolder/storage/...
0
votes
2answers
110 views

here-document basename conflicts?

I am using EOF to generate bash scripts that run the Rscripts. In the Rscript I used basename to specify the output file name. When I use EOF to generate a list of bash scripts, I could not get ...
0
votes
2answers
358 views

How can I use an argument from xargs to evaluate another expression?

I would like to evaluate a basename expression given an argument from xargs. I tested: find . -name '*.txt' | xargs -I f cp f DIR_OUT/copied_$(basename f) which gives no file or directory because $(...
0
votes
4answers
90 views

How to debug my script?

This script name is hello for i in $(ls $*);do x=$(echo $(basename $i".md")); pandoc $i -t "latex" -o $x.pdf; done When I write this $ ./hello *bye.md This error ls: cannot access 'test': ...
0
votes
1answer
4k views

basename extra operand error [duplicate]

I have a script that will try to extract the file's base name and then I do additional work with it. Only when using this script with a file with this naming convention (including spaces and ...
1
vote
2answers
47 views

Get container directory more easily

I have a bash script here: $GOPATH/ src/ build.sh and in build.sh I have: export GOPATH="$(cd $(dirname "$BASH_SOURCE") && pwd)" is there a shorter way to get the containing dir ...
-1
votes
1answer
814 views

Using bash, resolve absolute path to relative path

Say I have this simple bash script: #!/usr/bin/env bash file="$1"; if [ -z "$file" ]; then echo "Must pass relative file path as the first argument."; fi git_root=`git rev-parse --show-...
0
votes
2answers
620 views

How to get the filename part of a path from a shell variable

A shell variable holds a path. How does one get its filename portion? In bash(1), I experimented and found that I can do it with ."${i/*\///}" where i is the name of the environment variable. Such a ...
0
votes
2answers
463 views

Find with absolute path inside a bashscript | xargs basename

I have to find recursively inside a bash script. Since I can invoke the bash script from anywhere, I am forced to use the absolute path. Sometimes the absolute path can get very long, and the output ...
4
votes
1answer
3k views

How to get the filename of a symlink destination in a shell script?

let's say the scriptname is myscript. It's a symbolic link to thescript_1.91.sh Is there a way to get the name of the link destination? An example: I want to write in a logfile cat <<EOF ####...
1
vote
2answers
88 views

Sorting out directories by searching certain file extension

Let say, I am in a directory A, under A there are many folders (B, C, D, etc.), and in each folder there is a file "*.out" and sub-folders. I want to run a script from A which will look for the text "...
0
votes
2answers
202 views

Bash for file processing [duplicate]

I am writing a bash script to move all images into a central file. I create the list of image files with: img_fil='/home/files/img_dump.txt' locate -i image | grep \.jpg > "$img_fil" locate -i ...
0
votes
2answers
2k views

Concatenate pwd and basename [closed]

I want to assign the path and file name to a variable: /path/to/myfile/file.txt For example MYFILE=$(pwd)$(basename) How can i do it ?
0
votes
2answers
176 views

can't get an “awk for loop” to work, while using basename

I have many xyz files that I want to run through awk. I just want to create a new file with an "_s" appended, for each one. Having a little trouble getting the basename syntax correct. Here is what I ...
22
votes
4answers
24k views

dirname and basename vs parameter expansion

Is there any objective reason to prefer one form to the other? Performance, reliability, portability? filename=/some/long/path/to/a_file parentdir_v1="${filename%/*}" parentdir_v2="$(dirname "$...
6
votes
3answers
519 views

How do you call the “happy-dog” part of file “happy-dog.png”?

I just realized I don't know how file is called in file.ext. The whole file.ext is called a file or filename, ext is called extension but how do you call the file part itself of file.ext? For ...
2
votes
3answers
414 views

Rename mp3 file names to a pattern

I have a list of like names likes so: /A/B/C/D/E/F/filename_album1-003.mp3 its more like album\d+ I would like to change it to something like /A/B/C/D/E/F/filename_song-3.mp3 song is just a ...
2
votes
1answer
694 views

basename doesn't work as expected

How do I make ".mkv" disappear in the target filename? $ echo a/b.mkv | xargs -I % echo ffmpeg -i "%" $(basename "%" ".mkv").mp4 ffmpeg -i a/b.mkv a/b.mkv.mp4
4
votes
2answers
9k views

use basename in find -exec?

If I just use basename {} .txt, it will work: find . -iname "*.txt" -exec basename {} .txt \; It will just print xxx instead of ./xxx.txt if I want use $(basename {} .txt) in the -exec option, it ...
1
vote
1answer
2k views

Extract file name from find command

I am trying to extract the file name and attaching to mail. But when I send mail the attachment is coming with path name and file name. Ex: dir=/home/as123/bill and filename=abc.pdf.Z and I am ...
2
votes
2answers
5k views

Problems with basename in a loop

I am new at shell script programming and I'm trying to execute a software that reads a text and perform it's POS tagging. It requires an input and an output, as can be seen in the execute example: $ ...
3
votes
2answers
4k views

Remove multiple possible suffixes

Example: I want to create a quick command to shrink images (for my filebrowser). ... FN="/tmp/some-image.jpg" gm convert "$FN" -resize 50% "$(dirname $FN)/$(basename $FN .jpg/png/gif).jpg" ... How ...
10
votes
6answers
19k views

Use basename to parse a list of paths held in a file

I'm running Mac OSX and trying to use the command line to find the number of files I have with the same name. I tried to use the following command: find ~ -type f -name "*" -print | basename | sort ...
1
vote
1answer
13k views

Basename gives extra operand error

I 'm using the following script to merge few pcap files into one using mergecap command. But when I run it it gives me a 'basename: extra operand /mnt/md0/capture/DCN/dcn_2014_02_04_00_11_47_598.pcap' ...
25
votes
3answers
2k views

shellcheck is advising not to use basename: why?

I am trying out shellcheck. I have something like that basename "${OPENSSL}" and I get the following suggestion Use parameter expansion instead, such as ${var##*/}. From the practical point of ...
2
votes
2answers
21k views

Bash shell scripting basic question regarding the syntax and basename

Consider the script below: myname=`basename $0`; for i in `ls -A` do if [ $i = $myname ] then echo "Sorry i won't rename myself" else newname=`echo $i |tr a-z A-Z` mv $i $newname fi done 1)...
2
votes
2answers
1k views

Inner function call with xargs parameters

I am trying to create a file occurent within my /tmp directory of each file containing a speicific string. The problem is that the call to basename {} does not seem to work. Neither this, neither ...
3
votes
5answers
8k views

Execute on the basename of a find command

Suppose I have a directory structure as follows test test/a test/b Now I want to execute a command, such that in the . folder I can execute a command on the basename of the files a and b. So ...