Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
0
votes
1
answers
842
views
basename complains about missing operand using unshare
If I try to create namespaces, basename complains about missing operand: sudo unshare --mount --ipc --uts --pid --fork --user /bin/bash basename: missing operand Try 'basename --help' for more information. I even tried with `bash --norc` with no luck. Why does this error occur? And how do I fix it?...
If I try to create namespaces, basename complains about missing operand:
sudo unshare --mount --ipc --uts --pid --fork --user /bin/bash
basename: missing operand
Try 'basename --help' for more information.
I even tried with
bash --norc
with no luck.
Why does this error occur? And how do I fix it?
## UPDATE 1
When I said that "I even tried with bash --norc
with no luck." I meant that I run bash --norc
and then sudo unshare....
but that it works:
sudo unshare --mount --ipc --uts --pid --fork --user /bin/bash --norc --noprofile
I wonder anyway why. Because I have basename in .bashrc only into functions, and disabling those functions it outputs the same error
sebelk
(4669 rep)
Jul 19, 2024, 12:32 AM
• Last activity: Jul 20, 2024, 02:48 PM
-2
votes
1
answers
115
views
How to trim directory from which output without basename?
For a shell script I need to call an executable by name, regardless of the path leading there; thus far I know this code reports the right name: ``` tmpprog=`which program` prog=${tmpprog%%*/} if $prog="" then echo >&2 "Main Program not found" else echo >&2 "$prog" fi ``` How can I cut the code so t...
For a shell script I need to call an executable by name, regardless of the path leading there; thus far I know this code reports the right name:
tmpprog=which program
prog=${tmpprog%%*/}
if $prog=""
then
echo >&2 "Main Program not found"
else
echo >&2 "$prog"
fi
How can I cut the code so that I may trim the path to keep the executable name and remove the path in a one liner?
Beware: basename
won't do it, since I may be working on a hybrid environment (cygwin/busybox on windoze), and sometimes the paths have spaces.
jarnowy
(200 rep)
Jan 16, 2024, 02:14 AM
• Last activity: Apr 5, 2024, 08:31 AM
0
votes
1
answers
316
views
Basename detects an extra operand if I use it with find
I try to execute basename via find like this: ``` find ./test_folder -type f -exec basename {} + ``` But I get the following error: ``` basename: extra operand './test_folder/test/file.crt' ``` Why I get this though?
I try to execute basename via find like this:
find ./test_folder -type f -exec basename {} +
But I get the following error:
basename: extra operand './test_folder/test/file.crt'
Why I get this though?
Dimitrios Desyllas
(1301 rep)
Nov 6, 2023, 07:37 PM
• Last activity: Nov 7, 2023, 07:18 AM
0
votes
2
answers
292
views
Basename in find -exec
I need use in find results full path and dir name. This not work: ``` find ./1cv8 -maxdepth 1 -type d -wholename "./1cv8/*" -exec bash -c 'echo vrunner -src "{}" -o ./builds/"${basename "{}"}"' \; ``` error: ``` bash: ${basename "./1cv8/common"}: bad substitution bash: ${basename "./1cv8/conf"}: bad...
I need use in find results full path and dir name.
This not work:
find ./1cv8 -maxdepth 1 -type d -wholename "./1cv8/*" -exec bash -c 'echo vrunner -src "{}" -o ./builds/"${basename "{}"}"' \;
error:
bash: ${basename "./1cv8/common"}: bad substitution
bash: ${basename "./1cv8/conf"}: bad substitution
bash: ${basename "./1cv8/x86_64"}: bad substitution
Please help
Dmitriy
(3 rep)
Oct 2, 2023, 10:12 AM
• Last activity: Oct 2, 2023, 12:15 PM
6
votes
3
answers
551
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 example `happy-dog.png`. All the file/filename is `happy-dog.png`, extension is `png` but how do...
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 example happy-dog.png
. All the file/filename is happy-dog.png
, extension is png
but how do you call happy-dog
?
It's not basename. Is it like titlename? Or filepart? Any ideas?
bodacydo
(322 rep)
Dec 1, 2015, 06:05 AM
• Last activity: Mar 3, 2023, 07:52 AM
9
votes
2
answers
9668
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 can I specify that more than one suffix should be stripped?
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 can I specify that more than one suffix should be stripped?
Profpatsch
(1869 rep)
May 8, 2014, 10:56 AM
• Last activity: Mar 2, 2023, 05:35 PM
2
votes
1
answers
411
views
Why do I need to use the -I parameter in `compgen -G ... | xargs basename`?
I ran into a situation where I was piping the output of `compgen -G` to `xargs basename` and could not get it to work until I added the `xargs -I` parameter as seen below. Here is a script demonstrating what I was trying to do, with explanatory comments. I have two questions, and they appear after t...
I ran into a situation where I was piping the output of
compgen -G
to xargs basename
and could not get it to work until I added the xargs -I
parameter as seen below. Here is a script demonstrating what I was trying to do, with explanatory comments. I have two questions, and they appear after the script.
# create three files for testing:
touch /tmp/my.file.1.2.txt
touch /tmp/1.my.file.2.txt
touch /tmp/1.2.my.file.txt
# create a glob and verify that it works with compgen:
glob=/tmp/*.file*.txt
compgen -G "$glob"
#output:
/tmp/1.2.my.file.txt
/tmp/1.my.file.2.txt
/tmp/my.file.1.2.txt
# try to get the basename of each file using xargs.
# I thought this would work, but it does not.
compgen -G "$glob" | xargs basename
#output:
basename: extra operand ‘/tmp/my.file.1.2.txt’
Try 'basename --help' for more information.
# eventually I discovered that this would work.
# however, I don't understand why this would work
# but the previous attempt would not, since I
# think that this command is just a more
# explicitly-specified version of the previous
# one.
compgen -G "$glob" | xargs -I{} basename {}
#output:
1.2.my.file.txt
1.my.file.2.txt
my.file.1.2.txt
Other commands work with xargs
without the -I
parameter. For example, compgen -G "$glob" | xargs ls -al
works just fine.
Question 1:
What is it about basename
in this script that requires the -I
parameter?
Question 2:
Until observing this result, I would have thought that xargs basename
and xargs -I{} basename {}
were synonyms of each other, but obviously they are not. What is the difference?
I doubt that it matters, but just in case: this is occurring on bash 5.0.17(1)-release running on Ubuntu 20.04.4 (5.13.0-35-generic).
I know there are other ways to generate this list of files, but I am concerned because I am clearly not understanding something fundamental here that I need to understand in order to avoid errors in the future.
chris
(123 rep)
Mar 21, 2022, 03:05 PM
• Last activity: Nov 27, 2022, 08:14 PM
0
votes
1
answers
933
views
Why basename don't work here
Why when I do this (I know, it's stupid) it returns the full path, not only the filename as expected? `ls -l | awk '{print $9}' | xargs -I% find ./my_dir -type f -name "%" -exec echo $(basename {}) \;` And, yes, I know, it's stupid but the goal was to cp basename{} to {} (and, in the and, I use a lo...
Why when I do this (I know, it's stupid) it returns the full path, not only the filename as expected?
ls -l | awk '{print $9}' | xargs -I% find ./my_dir -type f -name "%" -exec echo $(basename {}) \;
And, yes, I know, it's stupid but the goal was to cp basename{} to {} (and, in the and, I use a loop for i in $(ls); do find ./my_dir -type f -name $i -exec cp $i {} \;; done
)
Thanks.
Alysko
(103 rep)
Aug 2, 2022, 01:15 PM
• Last activity: Aug 3, 2022, 08:14 PM
4
votes
3
answers
1572
views
find -exec command options with basename
I have the following JPEG files : ``` $ ls -l -rw-r--r-- 1 user group 384065 janv. 21 12:10 CamScanner 01-10-2022 14.54.jpg -rw-r--r-- 1 user group 200892 janv. 10 14:55 CamScanner 01-10-2022 14.55.jpg -rw-r--r-- 1 user group 283821 janv. 21 12:10 CamScanner 01-10-2022 14.56.jpg ``` I use `$ img2pdf...
I have the following JPEG files :
$ ls -l
-rw-r--r-- 1 user group 384065 janv. 21 12:10 CamScanner 01-10-2022 14.54.jpg
-rw-r--r-- 1 user group 200892 janv. 10 14:55 CamScanner 01-10-2022 14.55.jpg
-rw-r--r-- 1 user group 283821 janv. 21 12:10 CamScanner 01-10-2022 14.56.jpg
I use $ img2pdf
to transform each image into a PDF file. To do that :
$ find . -type f -name "*.jpg" -exec img2pdf "{}" --output $(basename {} .jpg).pdf \;
Result :
$ ls -l *.pdf
-rw-r--r-- 1 user group 385060 janv. 21 13:06 CamScanner 01-10-2022 14.54.jpg.pdf
-rw-r--r-- 1 user group 201887 janv. 21 13:06 CamScanner 01-10-2022 14.55.jpg.pdf
-rw-r--r-- 1 user group 284816 janv. 21 13:06 CamScanner 01-10-2022 14.56.jpg.pdf
How can I remove the .jpg
part of the PDF filenames ? I.e., I want CamScanner 01-10-2022 14.54.pdf
and not CamScanner 01-10-2022 14.54.jpg.pdf
.
Used alone, $ basename filename .extension
prints the filename without the extension, e.g. :
$ basename CamScanner\ 01-10-2022\ 14.54.jpg .jpg
CamScanner 01-10-2022 14.54
But it seems that syntax doesn't work in my $ find
command. Any idea why ?
Note : if you replace $ img2pdf
by $ echo
it's the same, $ basename
doesn't get rid of the .jpg
part :
$ find . -type f -name "*.jpg" -exec echo $(basename {} .jpg).pdf \;
./CamScanner 01-10-2022 14.56.jpg.pdf
./CamScanner 01-10-2022 14.55.jpg.pdf
./CamScanner 01-10-2022 14.54.jpg.pdf
ChennyStar
(1969 rep)
Jan 21, 2022, 07:06 AM
• Last activity: Jan 21, 2022, 05:58 PM
0
votes
4
answers
786
views
How can I output a txt file, that has part of filename followed by path of file for all files in a folder, one line per file?
I have the following files ``` /folder/abc1.txt.gz /folder/abc2.txt.gz /folder/abc3.txt.gz ``` I would like to make a txt file with the following ``` abc1 /folder/abc1.txt.gz abc2 /folder/abc2.txt.gz abc3 /folder/abc3.txt.gz ``` I have used the following command ``` find /folder -name 'abc*.txt.gz'...
I have the following files
/folder/abc1.txt.gz
/folder/abc2.txt.gz
/folder/abc3.txt.gz
I would like to make a txt file with the following
abc1 /folder/abc1.txt.gz
abc2 /folder/abc2.txt.gz
abc3 /folder/abc3.txt.gz
I have used the following command
find /folder -name 'abc*.txt.gz' -type f -printf '%f %p\n' > out.txt
This will output:
abc1.txt.gz /folder/abc1.txt.gz
abc2.txt.gz /folder/abc2.txt.gz
abc3.txt.gz /folder/abc3.txt.gz
How can I have only the first part of the filename (without .txt.gz) folowed by the path?
christoforos giatzakis
(1 rep)
Dec 15, 2021, 11:00 AM
• Last activity: Dec 15, 2021, 06:21 PM
0
votes
2
answers
247
views
Map over file tree, preserving structure
I have a file tree that looks like: ``` $ tree src src ├── bible │   ├── index.md │   └── README.md ├── index.md └── other.md ``` I want to render every Markdown file within this file tree to HTML via `pandoc(1)` -- **preserving structure**. This new file tree should be rooted at...
I have a file tree that looks like:
$ tree src
src
├── bible
│ ├── index.md
│ └── README.md
├── index.md
└── other.md
I want to render every Markdown file within this file tree to HTML via pandoc(1)
-- **preserving structure**.
This new file tree should be rooted at out
, like so:
$ tree out
out
├── bible
│ ├── index.html
│ └── README.html
├── index.html
└── other.html
Ideally, I'd like to do this via make(1)
. This is what I have so far:
SRC_DIR=src
OUT_DIR=out
.PHONY: all
all: $(SRC_DIR)/*.md
find . -name "*.md" -exec pandoc '{}' -o '{}'.html \;
find -name "*.html" -exec bash -c 'mv {} $(OUT_DIR)/dirname {}
/basename {} .md.html
.html' \;
# mv $(SRC_DIR)/*.html $(OUT_DIR)
firefox $(OUT_DIR)/index.html
.PHONY: clean
clean:
rm $(OUT_DIR)/*.html
This fails:
$ make
find . -name "*.md" -exec pandoc '{}' -o '{}'.html \;
find . -name "*.html" -exec bash -c 'mv {} basename {} .md.html
.html' \;
mv src/*.html out
mv: cannot stat 'src/*.html': No such file or directory
make: *** [Makefile:8: all] Error 1
jmcph4
(75 rep)
Jul 16, 2021, 03:28 AM
• Last activity: Jul 16, 2021, 04:19 PM
3
votes
2
answers
596
views
How can I use basename with parallel?
I have files like this on a Linux system: 10S1_S5_L002_chrm.fasta SRR3184711_chrm.fasta SRR3987378_chrm.fasta SRR4029368_chrm.fasta SRR5204465_chrm.fasta SRR5997546_chrm.fasta 13_S7_L003_chrm.fasta SRR3184712_chrm.fasta SRR3987379_chrm.fasta SRR4029369_chrm.fasta SRR5204520_chrm.fasta SRR5997547_chr...
I have files like this on a Linux system:
10S1_S5_L002_chrm.fasta SRR3184711_chrm.fasta SRR3987378_chrm.fasta SRR4029368_chrm.fasta SRR5204465_chrm.fasta SRR5997546_chrm.fasta
13_S7_L003_chrm.fasta SRR3184712_chrm.fasta SRR3987379_chrm.fasta SRR4029369_chrm.fasta SRR5204520_chrm.fasta SRR5997547_chrm.fasta
14_S8_L003_chrm.fasta SRR3184713_chrm.fasta SRR3987380_chrm.fasta SRR4029370_chrm.fasta SRR5208699_chrm.fasta SRR5997548_chrm.fasta
17_S4_L002_chrm.fasta SRR3184714_chrm.fasta SRR3987415_chrm.fasta SRR4029371_chrm.fasta SRR5208700_chrm.fasta SRR5997549_chrm.fasta
3_S1_L001_chrm.fasta SRR3184715_chrm.fasta SRR3987433_chrm.fasta SRR4029372_chrm.fasta SRR5208701_chrm.fasta SRR5997550_chrm.fasta
4_S2_L001_chrm.fasta SRR3184716_chrm.fasta SRR3987482_chrm.fasta SRR4029373_chrm.fasta SRR5208770_chrm.fasta SRR5997551_chrm.fasta
50m_S10_L004_chrm.fasta SRR3184717_chrm.fasta SRR3987489_chrm.fasta SRR4029374_chrm.fasta SRR5208886_chrm.fasta SRR5997552_chrm.fasta
5_S3_L001_chrm.fasta SRR3184718_chrm.fasta SRR3987493_chrm.fasta SRR4029375_chrm.fasta SRR5211153_chrm.fasta SRR6050903_chrm.fasta
65m_S11_L005_chrm.fasta SRR3184719_chrm.fasta SRR3987495_chrm.fasta SRR4029376_chrm.fasta SRR5211162_chrm.fasta SRR6050905_chrm.fasta
6_S6_L002_chrm.fasta SRR3184720_chrm.fasta SRR3987647_chrm.fasta SRR4029377_chrm.fasta SRR5211163_chrm.fasta SRR6050920_chrm.fasta
70m_S12_L006_chrm.fasta SRR3184721_chrm.fasta SRR3987651_chrm.fasta SRR4029378_chrm.fasta SRR5215118_chrm.fasta SRR6050921_chrm.fasta
80m_S1_L002_chrm.fasta SRR3184722_chrm.fasta SRR3987657_chrm.fasta SRR4029379_chrm.fasta SRR5247122_chrm.fasta SRR6050958_chrm.fasta
In all there are 423
I was asked to cut them in 32 parts for an optimal parallelisation on 32 CPU
So now I have this:
10S1_S5_L002_chrm.part-10.fasta SRR3986254_chrm.part-26.fasta SRR4029372_chrm.part-22.fasta SRR5581526-1_chrm.part-20.fasta
10S1_S5_L002_chrm.part-11.fasta SRR3986254_chrm.part-27.fasta SRR4029372_chrm.part-23.fasta SRR5581526-1_chrm.part-21.fasta
10S1_S5_L002_chrm.part-12.fasta SRR3986254_chrm.part-28.fasta SRR4029372_chrm.part-24.fasta SRR5581526-1_chrm.part-22.fasta
10S1_S5_L002_chrm.part-13.fasta SRR3986254_chrm.part-29.fasta SRR4029372_chrm.part-25.fasta SRR5581526-1_chrm.part-23.fasta
10S1_S5_L002_chrm.part-14.fasta SRR3986254_chrm.part-2.fasta SRR4029372_chrm.part-26.fasta SRR5581526-1_chrm.part-24.fasta
10S1_S5_L002_chrm.part-15.fasta SRR3986254_chrm.part-30.fasta SRR4029372_chrm.part-27.fasta SRR5581526-1_chrm.part-25.fasta
10S1_S5_L002_chrm.part-16.fasta SRR3986254_chrm.part-31.fasta SRR4029372_chrm.part-28.fasta SRR5581526-1_chrm.part-26.fasta
10S1_S5_L002_chrm.part-17.fasta SRR3986254_chrm.part-32.fasta SRR4029372_chrm.part-29.fasta SRR5581526-1_chrm.part-27.fasta
10S1_S5_L002_chrm.part-18.fasta SRR3986254_chrm.part-3.fasta SRR4029372_chrm.part-2.fasta SRR5581526-1_chrm.part-28.fasta
10S1_S5_L002_chrm.part-19.fasta SRR3986254_chrm.part-4.fasta SRR4029372_chrm.part-30.fasta SRR5581526-1_chrm.part-29.fasta
10S1_S5_L002_chrm.part-1.fasta SRR3986254_chrm.part-5.fasta SRR4029372_chrm.part-3.fasta SRR5581526-1_chrm.part-2.fasta
10S1_S5_L002_chrm.part-20.fasta SRR3986254_chrm.part-6.fasta SRR4029372_chrm.part-4.fasta SRR5581526-1_chrm.part-30.fasta
10S1_S5_L002_chrm.part-21.fasta SRR3986254_chrm.part-7.fasta SRR4029372_chrm.part-5.fasta SRR5581526-1_chrm.part-31.fasta
I want to apply a command from the CRISPRCasFinder tool
The command works well when I use it alone on 1
namefile.fasta
The command also works well when I use parallel
on namefile.part*.fasta
.
But when I try to make the command more general by using basename
, nothing works. I want to use basename
to keep the name of my input files in the output folder.
I tried this on a smaller data set:
time parallel 'dossierSortie=$(basename -s .fasta {}) ; singularity exec -B $PWD /usr/local/CRISPRCasFinder-release-4.2.20/CrisprCasFinder.simg perl /usr/local/CRISPRCasFinder/CRISPRCasFinder.pl -so /usr/local/CRISPRCasFinder/sel392v2.so -cf /usr/local/CRISPRCasFinder/CasFinder-2.0.3 -drpt /usr/local/CRISPRCasFinder/supplementary_files/repeatDirection.tsv -rpts /usr/local/CRISPRCasFinder/supplementary_files/Repeat_List.csv -cas -def G --meta -out /databis/defontis/Dossier_fasta_chrm_avec_CRISPRCasFinder/Test/Result{} -in /databis/defontis/Dossier_fasta_chrm_avec_CRISPRCasFinder/Test/{}' ::: *_chrm.part*.fasta
And it did this
ERR358546_chrm.part-1.fasta SRR4029114_k141_23527.fna.bck SRR5100341_k141_10416.fna.lcp SRR5100345_k141_3703.fna.al1
ERR358546_chrm.part-2.fasta SRR4029114_k141_23527.fna.bwt SRR5100341_k141_10416.fna.llv SRR5100345_k141_3703.fna.bck
ERR358546_chrm.part-3.fasta SRR4029114_k141_23527.fna.des SRR5100341_k141_10416.fna.ois SRR5100345_k141_3703.fna.bwt
ERR358546_chrm.part-4.fasta SRR4029114_k141_23527.fna.lcp SRR5100341_k141_10416.fna.prj SRR5100345_k141_3703.fna.des
ERR358546_chrm.part-5.fasta SRR4029114_k141_23527.fna.llv SRR5100341_k141_10416.fna.sds SRR5100345_k141_3703.fna.lcp
ERR358546_chrm.part-6.fasta SRR4029114_k141_23527.fna.ois SRR5100341_k141_10416.fna.sti1 SRR5100345_k141_3703.fna.llv
ERR358546_k141_26987.fna SRR4029114_k141_23527.fna.prj SRR5100341_k141_10416.fna.suf SRR5100345_k141_3703.fna.ois
ERR358546_k141_33604.fna SRR4029114_k141_23527.fna.sds SRR5100341_k141_10416.fna.tis SRR5100345_k141_3703.fna.prj
ERR358546_k141_90631.fna SRR4029114_k141_23527.fna.sti1 SRR5100341_k141_10942.fna SRR5100345_k141_3703.fna.sds
ResultERR358546_chrm.part-3 SRR4029114_k141_23527.fna.suf SRR5100341_k141_164.fna SRR5100345_k141_3703.fna.sti1
ResultERR358546_chrm.part-4 SRR4029114_k141_23527.fna.tis SRR5100341_k141_3046.fna SRR5100345_k141_3703.fna.suf
ResultSRR4029114_chrm.part-1 SRR5100341_chrm.part-10.fasta SRR5100341_k141_3968.fna SRR5100345_k141_3703.fna.tis
ResultSRR4029114_chrm.part-4 SRR5100341_chrm.part-11.fasta SRR5100341_k141_631.fna SRR5100345_k141_4429.fna
ResultSRR5100341_chrm.part-10 SRR5100341_chrm.part-12.fasta SRR5100341_k141_6376.fna SRR5100345_k141_4832.fna
ResultSRR5100341_chrm.part-11 SRR5100341_chrm.part-13.fasta SRR5100341_k141_8699.fna SRR5100345_k141_6139.fna
ResultSRR5100341_chrm.part-3 SRR5100341_chrm.part-1.fasta SRR5100341_k141_8892.fna SRR5100345_k141_731.fna
ResultSRR5100341_chrm.part-9 SRR5100341_chrm.part-2.fasta SRR5100345_chrm.part-10.fasta SRR5100345_k141_731.fna.al1
ResultSRR5100345_chrm.part-1 SRR5100341_chrm.part-3.fasta SRR5100345_chrm.part-1.fasta SRR5100345_k141_731.fna.bck
ResultSRR5100345_chrm.part-4 SRR5100341_chrm.part-4.fasta SRR5100345_chrm.part-2.fasta SRR5100345_k141_731.fna.bwt
ResultSRR5100345_chrm.part-9 SRR5100341_chrm.part-5.fasta SRR5100345_chrm.part-3.fasta SRR5100345_k141_731.fna.des
SRR4029114_chrm.part-1.fasta SRR5100341_chrm.part-6.fasta SRR5100345_chrm.part-4.fasta SRR5100345_k141_731.fna.lcp
SRR4029114_chrm.part-2.fasta SRR5100341_chrm.part-7.fasta SRR5100345_chrm.part-5.fasta SRR5100345_k141_731.fna.llv
SRR4029114_chrm.part-3.fasta SRR5100341_chrm.part-8.fasta SRR5100345_chrm.part-6.fasta SRR5100345_k141_731.fna.ois
SRR4029114_chrm.part-4.fasta SRR5100341_chrm.part-9.fasta SRR5100345_chrm.part-7.fasta SRR5100345_k141_731.fna.prj
SRR4029114_chrm.part-5.fasta SRR5100341_k141_10416.fna SRR5100345_chrm.part-8.fasta SRR5100345_k141_731.fna.sds
SRR4029114_k141_14384.fna SRR5100341_k141_10416.fna.al1 SRR5100345_chrm.part-9.fasta SRR5100345_k141_731.fna.sti1
SRR4029114_k141_16765.fna SRR5100341_k141_10416.fna.bck SRR5100345_k141_1211.fna SRR5100345_k141_731.fna.suf
SRR4029114_k141_23527.fna SRR5100341_k141_10416.fna.bwt SRR5100345_k141_2884.fna SRR5100345_k141_731.fna.tis
SRR4029114_k141_23527.fna.al1 SRR5100341_k141_10416.fna.des SRR5100345_k141_3703.fna
The names of the folder are not okay because I want for example just ResultERR358546
and not ResultERR358546_chrm.part-2.fasta
And I don't want a result for each part but only for each ID.
Fraizu
(55 rep)
Jun 10, 2021, 09:21 AM
• Last activity: Jun 10, 2021, 01:05 PM
1
votes
3
answers
2406
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 `$(basename f)` was not evaluated correctly. I may split it two steps: copying and changin...
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 $(basename f)
was not evaluated correctly.
I may split it two steps: copying and changing the filename, but I would like to learn how to evaluate an expression with an argument from xargs
.
Change-the-world
(111 rep)
Feb 12, 2019, 07:24 AM
• Last activity: Mar 19, 2021, 12:23 AM
1
votes
1
answers
615
views
Bash: removing several patterns from file names
Normally, looping over the files I use `basename` to extract the name of the file as a separate variable: # remove .pdb extension from filename in new variable and print name of the file without it for pdb in "${storage}"/complex*.pdb ; do pdb_name=$(basename "$pdb" .pdb) echo this is "$pdb_name" wi...
Normally, looping over the files I use
basename
to extract the name of the file as a separate variable:
# remove .pdb extension from filename in new variable and print name of the file without it
for pdb in "${storage}"/complex*.pdb ; do
pdb_name=$(basename "$pdb" .pdb)
echo this is "$pdb_name" without its extension!
done
How could I remove several patterns from each file using the same basename
expression? For instance, in addition to ".pdb" I would like to omit also "complex", which is always present at the beginning of each file (here I used it as a pattern to recognize file in for LOOP).
user3470313
(213 rep)
Oct 21, 2020, 08:29 AM
• Last activity: Oct 21, 2020, 10:31 AM
4
votes
1
answers
452
views
the command find not working with -name option in sh file
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 ${path}/ -maxdepth 1 -mindepth 1 -type f -name '*sv*' -o -name '*.json' -exec basename {} \; | wc -l"`...
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 ${path}/ -maxdepth 1 -mindepth 1 -type f -name '*sv*' -o -name '*.json' -exec basename {} \; | wc -l"
This command returns only the number of .json
files, whereas files with sv
in their names exist in the ${path}
.
When I remove the -o -name '*.json'
part, the command works well, and returns the number of files containing the 'sv' in their names.
Does anyone know how can I modify the command in order to retrieve the files containing sv
in their names and the files with the extension .json
as well?
rainman
(149 rep)
Jul 5, 2020, 03:13 AM
• Last activity: Jul 6, 2020, 10:20 AM
0
votes
3
answers
303
views
Filename from pathname excluding (unknown) extension
Having a [pathname](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_267) it is possible to extract its [filename](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_170), excluding its _apriori_ known extension, with [basename](https://pubs....
Having a [pathname](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_267) it is possible to extract its [filename](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_170) , excluding its _apriori_ known extension, with [basename](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_40) :
$ pathname="/home/paulo/paulo.pdf"
$ printf "%s\n" "$(basename $pathname .pdf)"
paulo
But if the extension is not known how can this be done?
Paulo Tomé
(3832 rep)
Feb 10, 2020, 12:53 PM
• Last activity: Feb 10, 2020, 07:44 PM
29
votes
3
answers
2466
views
shellcheck is advising not to use basename: why?
I am trying out [shellcheck][1]. 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 view I see no difference $ export OPENSSL=/opt/local/bin/openssl $ basename ${OPENSSL} openssl $ echo...
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 view I see no difference
$ export OPENSSL=/opt/local/bin/openssl
$ basename ${OPENSSL}
openssl
$ echo ${OPENSSL##*/}
openssl
Since
basename
is in the POSIX specs , I don't a reason why it should be best practice. Any hint?
Matteo
(10024 rep)
Oct 9, 2013, 04:07 PM
• Last activity: Jan 26, 2020, 04:19 PM
0
votes
1
answers
143
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. userlistlocation --> where user input will be in this below format foldername/filename.csv I want to print...
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.
userlistlocation --> where user input will be in this below format foldername/filename.csv
I want to print only filename here for this purpose i am using basename. Executing manually working fine. But if i try to run this on remote machine it's executing upto file download. It's not executing basename part
File which i download will be source file for command execution.
rahuls36
(62 rep)
Dec 4, 2019, 06:17 AM
• Last activity: Dec 4, 2019, 08:43 AM
3
votes
1
answers
19937
views
basename extra operand error
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 characters - not really sure what's triggering the error), do I get the basename extra operand error. The fil...
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 characters - not really sure what's triggering the error), do I get the basename extra operand error.
The file name: JERASH - XZ 837367432.pdf
Here the script once executed generates error:
filetimestamp=$(date "+%F-%T")
timenow=$(date -u)
for file in files/input/*
do
printf "Break 1 \n"
#filename no extension:
filenamenopath=$(basename $file)
filenamenoext=${filenamenopath%.pdf}
printf "Break 2 \n"
#check if file is pdf
printf "File Name with No Path:" $filenamenopath
printf "Break 3 \n"
And here is the error:
> Break 1 basename: extra operand ‘XZ’
ksa_coder
(153 rep)
Nov 10, 2018, 03:44 AM
• Last activity: Oct 7, 2019, 05:31 AM
3
votes
1
answers
1869
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 [...] anyone know what's going on with that?
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 [...]
anyone know what's going on with that?
Alexander Mills
(10744 rep)
Aug 29, 2019, 04:47 PM
• Last activity: Aug 29, 2019, 09:45 PM
Showing page 1 of 20 total questions