0

I use conEmu to have som kind of linux terminal in windows.

In Windows I configured a variable to open files with sublime, and I can open files with:

$subl path/filename

I have a virtualMachine and I have the same code, in local and in the virtual host, but the paths are different:

D:\work (in win)
/home/work/ (in the server)

If I do:

$ ssh work@10.10.10.10 'find . -type f -name example.txt'

I get: /home/work/public/example.txt But I can't use it to open with sublime:

subl $(ssh work@10.10.10.10 'find /home/work -type f -name example.txt') //doesn't work

So I need to have only the path from the starting point of /home/work, and have only public/example.txt (or ./public/example)

And This is the question, how can I use find to get the path from the starting point?

1
  • It sounds like you are just asking for /home/work to be stripped off? Or something more? Will Sublime understand / or does it need \ in paths? – B Layer Dec 12 '17 at 17:05
1

Since you said . is ok, you could just cd to the directory first:

(cd somedir && find . [...])

With GNU find, you can also use the %P format specifier:

find somedir -printf '%P\n'  # \0 is safer if you can interpret nulls as delim

From man find:

%P: File's name with the name of the starting-point under which it was found removed.

1
  • It's only shows example.txt, and I need the public/example.txt – oootramas Dec 12 '17 at 16:07
0

The solution was "easy", using the ~ that marks the path to the home and then we only need to use sed to remove the text from the string.

find . -type f -name file | sed "s+$(echo ~)++"

$(echo ~) put the result of echo ~ that is /home/work

And we need use the " instead of ' to tell linux that they need to look for variables in the string

I use + instead of / (more usual) to evade the problem of the paths

sed 's//home/work//' cause problems
sed 's+/home/work++' doesn't

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.