Questions tagged [dirname]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
2answers
48 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
vote
5answers
272 views

What can I use to get the paths of all parent directories for a given path

I'm looking for a tool that I can use from a bash script that can give me the list of parent directories for a given path. e.g. given the input foo/bar/moocow I would like to get out: foo foo/bar foo/...
-2
votes
1answer
610 views

How to get dirname from path

I have this: find . -type f -name '*_test.go' | xargs dirname but I get: usage: dirname path the output of $ find . -type f -name '*_test.go' is: ./pkg_test.go ./v3/organization/...
7
votes
2answers
3k views

dirname appears not to work with xargs

xargs and basename work together as I would expect: $ printf '%s\n' foo/index.js bar/index.js baz/index.js | xargs basename index.js index.js index.js xargs and dirname, though, appear not to work ...
1
vote
3answers
771 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 $(...
1
vote
2answers
63 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 ...
0
votes
1answer
1k 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
714 views

Apply readlink to a non-symlink file?

This code from Stack Overflow is to get the pathname to the parent directory of a script inside the script, even if the script is run via a symlink to it: if [ -L $0 ] ; then DIR=$(dirname $(...
0
votes
2answers
381 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
1answer
48 views

How can I set ENV from a path

I just installed android-sdk using Homebrew. The path is /usr/local/Caskroom/android-sdk/3859397,26.0.1. I know I can export ANDROID_HOME with that value. How can I set it dynamically using the ...
0
votes
3answers
1k views

cd 3 times to great-grandparent dir

I have this: cd $(dirname $(dirname $(dirname "$0"))) && which will cd to project root. Is there shorthand for this somehow, where I can just be like: cd 3 && # not quite, but you ...