02-17-2009
The call to getcwd() returns the path to the current directory. argv[0] contains the invocation of the current program, and can be used to infer the directory of the path to itself -- but not necessarily. If the program was invoked without any directory information and is invoked along the PATH variable, you can grab the PATH variable from the environ (getenv("PATH")) and traverse each element looking for the program itself (basename of argv[0]).
There's a function called realpath() which canonicalizes the pathname you provide to its argument. However, it's recommended NOT to use this in general, because you have to allocate memory for the return argument, but there's no way of knowing how large that memory allocation should be. (But realistically you can get away with 1k).
Unfortunately, realpath doesn't do any of the "real work" for you. You still have to traverse PATH to find the program's home directory.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi Folks,
In a Unix (ksh) script, is there a way to determine the current working directory path of another logged-in user? Of course, I can use "pwd" to find my own path. But, how do I find it for another active user?
Thanks for any input you can provide. LY (6 Replies)
Discussion started by: liteyear18
6 Replies
2. UNIX for Dummies Questions & Answers
Hi,
By default FIND command searches for matching files in all the subdirectories within the specified path.
Is there a way to restrict FIND command's search path to only the specified directory and NOT TO scan its subdirectories.
Any help would be more than appreciated.
Thanks and Regards (2 Replies)
Discussion started by: super_duper_guy
2 Replies
3. Shell Programming and Scripting
Hi guys
I'm trying to move an empty directory to the $TRASH directory. Say the directory i have is ./hello/hello1/hello2 and i'm in hello2, and i want hello2 moved.
this code:
TRASH=$home/deleted
find "$TRASH/$1" -type d -exec rmdir { } \; 2>/dev/null
mv -f $1 $TRASH 2>/dev/null
works... (2 Replies)
Discussion started by: olimiles
2 Replies
4. UNIX for Advanced & Expert Users
Looking for a command which shows the current path of other users.
Similiar to the PWD command.
Need to be able to see which part of the system the user is logged on to.
Thanks
G (1 Reply)
Discussion started by: Gandalf77
1 Replies
5. Programming
Hi,
my C++ program does some memory consuming tasks and runs several minutes.
During execution time, I want to print information on the current memory consumption and peak memory consumption of my program into a logfile.
How can I retrieve this information, i.e. which functions are available... (0 Replies)
Discussion started by: DarthVader77
0 Replies
6. UNIX for Dummies Questions & Answers
Hi all,
I need to mark a file with it's current location in the file system before being moved.
This will enable the file to be restored back to it's original location.
Can anyone provide any ideas about the best way to do this, at present i'm trying to use readlink -m to strip off the... (1 Reply)
Discussion started by: skinnygav
1 Replies
7. Shell Programming and Scripting
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
8. UNIX for Dummies Questions & Answers
In ubuntu, I want to update the title of the terminal window with the current directory path. Any ideas how this can be achieved?
---------- Post updated at 02:22 PM ---------- Previous update was at 02:08 PM ----------
Done it
---------- Post updated at 02:30 PM ---------- Previous update... (2 Replies)
Discussion started by: kristinu
2 Replies
9. Shell Programming and Scripting
Hello,
I have a c program executable which I need to run inside a shell script.
But the c program runs in a subshell because of which all the actions done by the c program is not available to the current shell.
Is there any way to execute a C program binary executable in the current shell? (4 Replies)
Discussion started by: sachinverma
4 Replies
10. UNIX for Dummies Questions & Answers
How to get the current directory Path in your prompt?
i am getting a $ mark only in my prompt?
Please help me with this (3 Replies)
Discussion started by: Abhishek0683
3 Replies
LEARN ABOUT DEBIAN
lsh-execuv
LSH-EXECUV(8) lsh manuals LSH-EXECUV(8)
NAME
lsh-execuv - program to securely execute a program as another user
SYNOPSIS
lsh-execuv [options] program [--] real-argv
DESCRIPTION
This manual page documents briefly the lsh-execuv command. This manual page was written for the Debian distribution because the original
program does not have a manual page.
lsh-execuv is a utility program for the lsh server that securely executes a program as a different user. another user.
OPTIONS
A summary of options is included below.
-u uid setuid to numeric uid before running program. Usernames are not supported, only numeric uids.
-g gid setgid to numeric gid before running program. Group names are not supported, only numeric gids.
-n user-name
User name, needed for initgroups
-i Call initgroups, requires that -n user-name be specified.
-c Clear the list of supplimentary groups.
-p Use $PATH variable to search for program.
-? Show summary of options.
SEE ALSO
lsh(1), lshd(8). The programs are documented fully by Lsh, available via the Info system.
AUTHOR
This manual page was written by Timshel Knoll <timshel@debian.org>, for the Debian GNU/Linux system (but may be used by others).
lsh-execuv Jul 05 2002 LSH-EXECUV(8)