Timeline for Replace slashes in a filename
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 18, 2018 at 17:53 | comment | added | Perkins | @JoL I'm not sure why it works on the one system myself yet. Obviously something about the environment is causing bash to defer execution of the backticks, but I haven't managed to isolate what it is. I've noticed that sometimes this one defers glob expansion as well depending on what command is being run, so possibly it's something in the bash completions or some similar setting changing the way it parses the command. If I figure it out I'll add it to the answer. | |
| Jun 18, 2018 at 17:47 | history | edited | Perkins | CC BY-SA 4.0 | eliminate error messages. |
| Jun 18, 2018 at 3:18 | comment | added | JoL | Besides that problem, something that no one has mentioned and that is present even in the xargs version is that you'll also be trying to copy directories inside /base/path. cp will complain that you can't do that unless you supply -r, but you shouldn't do that. Instead, you should supply -type f to find, so that it will only output regular files under the hierarchy. | |
| Jun 18, 2018 at 3:16 | comment | added | JoL | @Perkins "That find setup works on one of my systems" I have a hard time imagining how that could work anywhere. The only edge case I can kind of see is if your current working directory is /base/path and you just have regular files in there, no directories. However, even then you'd be copying to e.g. /base/path/__base__path__./f. That's not right. | |
| Jun 17, 2018 at 17:22 | comment | added | ilkkachu | xargs will have issues with names with whitespace, unless you use find -print0 | sed -z | xargs -0 (with at least GNU sed). Also any of those will make the copies to the current directory, which may or may not be what you want. | |
| Jun 17, 2018 at 17:18 | comment | added | ilkkachu | find -exec sh -c 'cp "$1" "$(realpath "$1" | sed s:/:__:g)"' sh {} \; should do | |
| Jun 17, 2018 at 17:10 | history | edited | Perkins | CC BY-SA 4.0 | More reliable method added. |
| Jun 17, 2018 at 3:47 | comment | added | Perkins | @JoL It worked when I tested it... I'll test it again when I get a few minutes... | |
| Jun 14, 2018 at 21:04 | comment | added | JoL | That find command will not work. The backticks will be evaluated before find and get you basically the equivalent of $PWD/{} with the slashes in $PWD replaced with double underscores. So, if you're in /home/user, this is equivalent to: find /base/path -exec cp {} __home__user__{} \; If you have a file f in /base/path, this will try to copy it to __home__user__/base/path/f. | |
| Jun 14, 2018 at 18:28 | vote | accept | David Mathers | ||
| Jun 14, 2018 at 18:10 | history | answered | Perkins | CC BY-SA 4.0 |