cleanpath

command module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2025 License: MIT Imports: 8 Imported by: 0

README

cleanpath

Unix command line utility to print clean file paths.

Why?

I want to generate a list of fully expanded absolute paths, even if they do not exist (yet).

Existing Tools

  • pwd(1) only prints the current path.
  • realpath(1) only prints paths which already exist.

Installation

cleanpath is a simple go program and is currently only available as source code.

Use go's go install command to download and install cleanpath in your $GOPATH/bin directory.

go install codeberg.org/japh/cleanpath@latest

Usage

cleanpath [options] [path ...]

Options
  • -h print help
  • -l expand symbolic links
  • -r do not prepend the current working directory to relative paths
  • -v print errors (default is to ignore errors)

Examples

Assume a file system with the following symbolic links:

/home -> /Users
Print the current working directory
/home/alice % cleanpath
/home/alice

This should be the same as pwd(1)

/home/alice % cleanpath -l
/Users/alice

Equivalent to realpath(1)

Print clean directory names even if they don't exist

Create an incomplete directory structure for demonstration purposes:

/home/alice % mkdir -p bar
/home/alice % mkdir -p baz/x/a
/home/alice % ln -s baz foo
/home/alice % find foo bar baz | xargs ls -ld
drwxr-xr-x@ 3 alice  users   96 Sep 29 17:20 bar
drwxr-xr-x@ 2 alice  users   64 Sep 29 17:20 bar/x
drwxr-xr-x@ 4 alice  users  128 Sep 29 17:19 baz
drwxr-xr-x@ 3 alice  users   96 Sep 29 17:20 baz/x
drwxr-xr-x@ 2 alice  users   64 Sep 29 17:19 baz/x/a
drwxr-xr-x@ 4 alice  users  128 Sep 29 17:19 baz/y
drwxr-xr-x@ 2 alice  users   64 Sep 29 17:19 baz/y/a
drwxr-xr-x@ 2 alice  users   64 Sep 29 17:19 baz/y/b
lrwxr-xr-x@ 1 alice  users    3 Sep 29 17:28 foo -> baz

Use cleanpath to produce the absolute paths of a set of directories:

/home/alice % cleanpath {foo,./bar}/{x,y}/{a,b}
/home/alice/foo/x/a
/home/alice/foo/x/b
/home/alice/foo/y/a
/home/alice/foo/y/b
/home/alice/bar/x/a
/home/alice/bar/x/b
/home/alice/bar/y/a
/home/alice/bar/y/b

Use -r to prevent the expansion of relative paths

/home/alice % cleanpath -r {foo,./bar}/{x,y}/{a,b}
foo/x/a
foo/x/b
foo/y/a
foo/y/b
./bar/x/a
./bar/x/b
./bar/y/a
./bar/y/b

Use -l to expand existing symbolic links:

/home/alice % cleanpath -l {foo,./bar}/{x,y}/{a,b}
baz/x/a
baz/x/b
baz/y/a
baz/y/b
bar/x/a
bar/x/b
bar/y/a
bar/y/b

The -v option will produce errors for non-existing paths

/home/alice % cleanpath -r -l -v {foo,./bar}/{x,y}/{a,b}
baz/x/a
foo/x/b - no such file or directory baz/x/b
baz/y/a
baz/y/b
./bar/x/a - no such file or directory bar/x/a
./bar/x/b - no such file or directory bar/x/b
./bar/y/a - no such file or directory bar/y
./bar/y/b - no such file or directory bar/y
5 errors

Note that errors mention the command line argument (e.g. ./bar/y/a) and the part of the path which caused the error (e.g. bar/y)

/home/alice % cleanpath -l -v {foo,./bar}/{x,y}/{a,b}
./cleanpath -v -l {foo,./bar}/{x,y}/{a,b}
/Users/alice/baz/x/a
foo/x/b - no such file or directory /Users/alice/baz/x/b
/Users/alice/baz/y/a
/Users/alice/baz/y/b
./bar/x/a - no such file or directory /Users/alice/bar/x/a
./bar/x/b - no such file or directory /Users/alice/bar/x/b
./bar/y/a - no such file or directory /Users/alice/bar/y
./bar/y/b - no such file or directory /Users/alice/bar/y
5 errors

Source Code

https://codeberg.org/japh/cleanpath

Author

Stephen Riehm japh-codeberg@opensauce.de

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL