Expanding file names in a script? ../blah -> /home/blah
Hello,
Is there a way to expand "the dots" in file/directory names to the proper path, so that the reference is absolute and not relative? For instance, if I use find ., all the files and directories in the resulting listing will start with ./. If I instead want to change this to the full path, is there a special command for it, or do I have do write my own script function? Cheers, Bebo |
find -printf "$PWD/%P\n"
Cheers, Tink |
Thanks Tink, but no, this doesn't work all the way. If I would invoke it like this find ../../usr/local/bin/ -printf "$PWD/%P\n", or even like this find ../../usr/local/bin/ -printf "%h/%P\n", I would get the wrong path.
|
The $PWD format he gave was to overcome the find . (current directory) problem, if you want the format of output for any other directory without the leading dot you can just give it the full path to the directory, why use .. ?
find /usr/local/bin |
your find ../../usr/local/bin/
should work like this find ../../usr/local/bin | cut -f5- -d'.' just change the value of -f5 to f7 or whatever depending on how many ../ you put in |
Yes, of course you're right, Looking_Lost. Hm... OK then, I guess I picked another bad example. So, what if I want to do the same thing from /usr/src/linux instead? Then I could issue find ../../local/bin/, and I would not get the full path either by using the -printf stuff or cut.
At the moment, it seems the way to solve this is to pick out the first part, with all the ../'s, cd to that place wherever it is, pwd, and cd back. I was hoping there would be a better way. |
I dunno, you seem to be making life hard for yourself :)
|
Yeah maybe :) What I'm trying to do is that I want to be able to check that any two files aren't the same, just by checking their paths and names.
|
Just out of curiosity: does my archiving script
work on your machine? I see that VisionZ has problems with it :} [edit] back to your problem: Have you considered using locate? It returns the full path ... [/edit] Cheers, Tink |
Hi Tink,
I tested your second script and it worked just fine. Heh, I just realized that I was writing almost exactly the same script - oops ;) It seems VisionZ has problems with the file command, so your script won't work in his cygwin environment. I had to change my first script to sidestep that. Well anyway, no I haven't tried to use locate *testing* Well, if I point it at a certain file, like locate ../../usr/local/bin/blah, then it won't return anything. Doesn't surprise me, though, since noone would need to use locate if they already knew the location of the file :) Well, if there isn't a better way than dirname - cd - pwd - cd, then that'll have to do... |
Try
locate \/usr\/local\/bin\/blah Cheers, Tink |
Well, locate works if the search string doesn't contain any dots, but returns nothing if it does.
What I'm looking for is a command or anything that will expand any stupid directory referal; even ./../../usr/local/../share. <EDIT> BTW, thanks a lot for trying to help me on this :) </EDIT> |
oops
|
Well, I battered this together in java.
Limitations: only prints out filenames and paths, can be changed easily to print out dirs resolves links to their full paths, doesn't print the link rather the thing it's pointing too ignores broken links if you can be bothered you can compile it with gcj gcj --main=listf listf.java -o listf or plain old java compiler save it as listf.java Code:
|
Wow! :D That's a very nice thingy you've got there, but it still doesn't do what I want :)
I think I'll settle for something like this: Code:
redir() Thanks a bunch guys :) |
All times are GMT -5. The time now is 03:51 PM. |