Questions tagged [basename]

51 questions
1
vote
1 answer

Removing full path from md5 output

By default the md5 command includes the full path in the output and doesn't seem to have an option to output the basename only. Although I can get around this using a script, I wondered if there is a simple way to output without the full path using…
yvf5rcuya4
  • 59
  • 6
1
vote
0 answers

Weird behavior of basename() on Mac OS

I have a simple program to test basename() method: #include #include //#include int main (int argc , char **argv) { char *a = strdup("test();"); printf("%s", basename(a)); return 0; } clang complains but…
daisy
  • 22,498
  • 29
  • 129
  • 265
1
vote
1 answer

How to understand how this find with while loop works in Bash

How can I understand this syntax a bit better? find ~/Documents/project/updates -type d -name "Branch*[0-9]" -maxdepth 1 -mtime -2 -print |\ while read path; do dir_name=$(basename $path) function_call $dir_name done
iDev
  • 2,163
  • 10
  • 39
  • 64
1
vote
2 answers

The command basename don't work in find command

The output of: find mydir -name foo -exec echo "---$(basename {})---" \; should be ---foo---, but instead it is ---mydir/foo--- The command basename alone: basename mydir/foo echo "---$(basename mydir/foo)---" brings respective foo and…
SzB
  • 1,027
  • 10
  • 12
1
vote
1 answer

Get the name of the folder from a path with whitespace

I'm new to bash and I'd like to know how to print the last folder name from a path. mypath="/Users/ckull/Desktop/Winchester stuff/a b c/some other folder/" dir="$(basename $mypath)" echo "looking in $dir" Where dir is the last directory in the…
Ghoul Fool
  • 6,249
  • 10
  • 67
  • 125
1
vote
1 answer

Extract filename from directory in R on Linux Server

I would like to extract filename from directory in R on Linux Server. The basename function in R will only work on Windows system. In Python, there is a package called ntpath that could extract filename from directory very easily on Linux…
Jian
  • 365
  • 1
  • 6
  • 19
1
vote
0 answers

Trying to get file name and folder name with space

I'm trying to get my folder name and file name (without extension, but i figure out doing without extension). if I can get in array that will be great but I'm still working on space problem. its getting only parent folder name and file name…
Kai
  • 11
  • 2
1
vote
4 answers

Sort array of directory path strings by lowest directory (ending substring)

I want to sort this array by year: Array ( [0] => data/pictures/alice/1980 [1] => data/pictures/alice/1985 [2] => data/pictures/bob/1981 [3] => data/pictures/bob/1985 [4] => data/pictures/bob/1987 [5] =>…
pdunker
  • 263
  • 2
  • 12
0
votes
1 answer

Using basename dirname to split a file path and to run the run

I have a generic filepath- /home/aa/bb/cc/d.txt and want to script something like this- so in the script, one thing would be for it to take that /path/to/testcase/d.txt And split it into working_dir = /path/to/testcase netlist = d.txt then the…
0
votes
3 answers

basename throws error when a wildcard is specified

I want to get the filename from a file path. It works fine when one file is specified, such as: fname=$(basename -- /tmp/file1) However, if provided as an expression such as fname=$(basename -- /tmp/fi*) it throws basename: extra operand…
Maven
  • 14,587
  • 42
  • 113
  • 174
0
votes
0 answers

Combine files with same basename but different, specific set of IDs

I have over 800,000 fastq.gz files that I am trying to combine. Below is an example of my data. Each file has a basename (sample#) and a BC1 identifier…
0
votes
0 answers

How to skip over a file that does not exist when using a loop to read in multiple files at once, path or file doesn't exist

I am using a for loop to read in everyfile with a particular extension (.AFEPSI) that exists within multiple directories and their subdirectories. However, the way I wrote the code, there is one file path that gets assigned that doesn't actually…
0
votes
1 answer

How do I get ffmpeg to encode all files in one directory to another directory? My directory names and filenames all have spaces and periods in them

I am using the Terminal on a Mac. Per another question, I am doing for i in ./01.\ Original\ Recording/*.m4a; do ffmpeg -i "$i" -b:a 64k ./02.\ Compressed/"$(basename $i)"; done (as you can see, there are spaces in the directory names as well as in…
Vihung
  • 12,947
  • 16
  • 64
  • 90
0
votes
4 answers

Add file name as a new column with awk

First of all existing questions didn't solve my problem that's why I am asking again. I have two txt files temp.txt adam 12 george 15 thomas 20 and demo.txt mark 8 richard 11 james 18 I want to combine them and add a 3rd column as their…
0
votes
1 answer

"basename" command won't include multiple files

I have a problem with “basename” command as follow: In my host directory I have two samples’ fastq.gz files, named as: A29_WES_S3_R1_001.fastq.gz A29_WES_S3_R2_001.fastq.gz A30_WES_S1_R1_001.fastq.gz A30_WES_S1_R2_001.fastq.gz Now I need to…
Alireza
  • 3
  • 2