Sponsored Content
Top Forums UNIX for Advanced & Expert Users Getting real path to directory Post 302381522 by kandrewo on Friday 18th of December 2009 02:36:33 PM
Old 12-18-2009
Your question made be think about the real reason... Hm...
I found that I don't know how to retrieve full real path in shell and it confused me. Of course, I can write something like
Code:
char * szResult = realpath(sPath.c_str(), szResolvedPath);

in C++ program and use it. But it is not a solution for each system, where our additional binary is missed. Say at my friend home Smilie

---------- Post updated at 09:36 PM ---------- Previous update was at 09:29 PM ----------

Quote:
Originally Posted by tlarkin
ls does it for me

Code:
admins-imac:~ tlarkin$ ls -al /etc
lrwxr-xr-x@ 1 root  admin  11 Sep  2 13:34 /etc -> private/etc
admins-imac:~ tlarkin$

bolded shows the parent folder. I am not using standard Unix though, I am using OS X. Might be some differences.
So the 1st way I can see is to use something like
Code:
ls -l "directoryname" | cut -f2 -d '>' | sed 's/^ //'

It isn't graceful way, don't you think so? As for me: it is usable but depends on ls standard, and possible differences between UNIX systems. Doesn't it?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

geting the real path

Hi there, Is there any way to obtain a real path from a weird path. For example : /foo/../bar/ -> /bar/ /foo/. -> /foo/ Thanks in advance Santiago (5 Replies)
Discussion started by: chebarbudo
5 Replies

2. UNIX for Dummies Questions & Answers

How to get directory name from its path?

If I the path to a directory, what command can I use to return the actual name of that directory. test=`pwd`/folder1 > $test folder1 I'd rather avoid anything with regular expressions. Any ideas? (1 Reply)
Discussion started by: ordano
1 Replies

3. Shell Programming and Scripting

Retrieve directory path from full file path through sh

Hi, I have a file abcd.txt which has contents in the form of full path file names i.e. $home> vi abcd.txt /a/b/c/r1.txt /q/w/e/r2.txt /z/x/c/r3.txt Now I want to retrieve only the directory path name for each row i.e /a/b/c/ /q/w/e/ How to get the same through shell script?... (7 Replies)
Discussion started by: royzlife
7 Replies

4. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

5. Shell Programming and Scripting

Copy real file from a shortcut preserving the time stamps and directory tree

I have directory with shorcuts of files. for example: gara@yn\short\name1 ( shortcut to gara@yn\FOLDER\OPT\GARA\1.jpg ) gara@yn\short\name2 ( shortcut to gara@yn\FOLDER\OPT\GARA\11.jpg ) gara@yn\short\name3 ( shortcut to gara@yn\MARA\URSA\2.jpg ) gara@yn\short\name4 ( shortcut to... (6 Replies)
Discussion started by: gogok_bg
6 Replies

6. Shell Programming and Scripting

Keep last directory from path

Hello, I am looking for a command that will give me the last directory name from a path ex 1 : /dir1/dir/2/dir3/ output needed dir3 ex 2 : /dir1/dir/2/dir3/dir4/ output needed dir4 (1 Reply)
Discussion started by: Aswex
1 Replies

7. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

8. UNIX for Dummies Questions & Answers

How to get real path to a file?

Hello, I need download a mp3 file from a site but I can not find the actual link. Thanks. Source codes <span title="what is" class="read"><embed type="application/x-shockwave-flash" src="au/audio.swf" width="17" height="13" align="texttop" quality="high" loop="false" menu="false"... (1 Reply)
Discussion started by: tara123
1 Replies

9. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

10. UNIX for Beginners Questions & Answers

What is the difference ../directory path and ./directory path in ksh?

What is the difference ../directory path and ./directory path in ksh? (1 Reply)
Discussion started by: TestKing
1 Replies
SYMLINKAT(2)						     Linux Programmer's Manual						      SYMLINKAT(2)

NAME
symlinkat - create a symbolic link relative to a directory file descriptor SYNOPSIS
#include <fcntl.h> /* Definition of AT_* constants */ #include <stdio.h> int symlinkat(const char *oldpath, int newdirfd, const char *newpath); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): symlinkat(): Since glibc 2.10: _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L Before glibc 2.10: _ATFILE_SOURCE DESCRIPTION
The symlinkat() system call operates in exactly the same way as symlink(2), except for the differences described in this manual page. If the pathname given in newpath is relative, then it is interpreted relative to the directory referred to by the file descriptor newdirfd (rather than relative to the current working directory of the calling process, as is done by symlink(2) for a relative pathname). If newpath is relative and newdirfd is the special value AT_FDCWD, then newpath is interpreted relative to the current working directory of the calling process (like symlink(2)). If newpath is absolute, then newdirfd is ignored. RETURN VALUE
On success, symlinkat() returns 0. On error, -1 is returned and errno is set to indicate the error. ERRORS
The same errors that occur for symlink(2) can also occur for symlinkat(). The following additional errors can occur for symlinkat(): EBADF newdirfd is not a valid file descriptor. ENOTDIR newpath is relative and newdirfd is a file descriptor referring to a file other than a directory. VERSIONS
symlinkat() was added to Linux in kernel 2.6.16. CONFORMING TO
POSIX.1-2008. NOTES
See openat(2) for an explanation of the need for symlinkat(). SEE ALSO
openat(2), symlink(2), path_resolution(7), symlink(7) COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2009-12-13 SYMLINKAT(2)
All times are GMT -4. The time now is 05:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy