Questions tagged [basename]

The tag has no usage guidance.

0
votes
2answers
49 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
53 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
123 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
73 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': ...
-1
votes
1answer
1k 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
35 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
393 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
72 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
107 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 ...
1
vote
1answer
1k 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
82 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
119 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
744 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
113 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 ...
17
votes
4answers
17k 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
511 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
356 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
635 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
3
votes
2answers
5k 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
1k 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 ...
1
vote
2answers
4k 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: $ ...
2
votes
1answer
3k 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 ...
9
votes
6answers
14k 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
19k 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
7k 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 ...