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?

  • 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

2 Answers2

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.

Chris Down
  • 125,559
  • 25
  • 270
  • 266
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