Sponsored Content
Top Forums UNIX for Advanced & Expert Users Shell command to print full path to current home directory Post 303044734 by Chubler_XL on Monday 2nd of March 2020 09:42:12 PM
Old 03-02-2020
Do the commands realpath or readlink (with or without -f) help here at all?

Or perhaps the Cwd module from perl:
Code:
perl -MCwd -e 'print Cwd::realpath($ARGV[0])' /home/user_name

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

home directory in search path

Is it unsafe to put your own home directory (a regular user) in your search path? I am writing useful shell scripts, but don't have the permissions to put them in /usr/bin. (Korn shell) thanks (2 Replies)
Discussion started by: jpprial
2 Replies

2. Shell Programming and Scripting

want the current directory without the absolute path

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

3. Shell Programming and Scripting

Sorting by Full directory path

I have a text file with full list of files with their full path. I wanted to sort it by directory then files then subdirectory by alphabetically. When I used the sort command it doesn't give like what I want. Could somebody help me on this. Here is the ex: This is what I'm getting... (2 Replies)
Discussion started by: javidraaj
2 Replies

4. 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

5. UNIX for Dummies Questions & Answers

Present Working Directory (not the full path)

Hi, Is there a command that tells you right away the current working directory? I know the command "pwd", but that one gives the full path. if pwd gives me: /a/b/c/d/ggg/HERE I want something that will give me: HERE Thanks, Gaurab (13 Replies)
Discussion started by: gaurab
13 Replies

6. Shell Programming and Scripting

How do I get an ls -l to not show the full directory path?

Hey I'm new to the forums here, and I'm seeking help for this script that I'm writing. When I do ls -l of a directory it shows the full pathname for files in it. For example, if the directory is /internet/post/forum/ and the file is topic, it currently shows internet/post/forum/topic. What's the... (3 Replies)
Discussion started by: unity04
3 Replies

7. Shell Programming and Scripting

$0 doesn't have full directory path

I'm running AIX unix korn shell. If I echo $0, I only get the filename, it does not have the directory name also. So when I do: `dirname $0` it returns a . (meaning current directory). How get $0 to return the full path/filename? Do I need something in my .profile? Thank you. (8 Replies)
Discussion started by: sboxtops
8 Replies

8. UNIX for Dummies Questions & Answers

How to get the current directory Path?

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

9. 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

10. Linux

How to print full path name along with file extension?

Hi I have a requirement like this: /abc/a/x.txt /abc/a/y.txt /abc/b/x.gz /abc/b/y.txt I need output like this: /abc/a:*.txt /abc/b:*.txt /abc/b:*.gz I have tried find /abc -type f -name "*.*" ||awk -F . '{print $NF}' it is print only extensions without path name. Please... (5 Replies)
Discussion started by: lijjumathew
5 Replies
Cwd(3pm)						 Perl Programmers Reference Guide						  Cwd(3pm)

NAME
Cwd - get pathname of current working directory SYNOPSIS
use Cwd; my $dir = getcwd; use Cwd 'abs_path'; my $abs_path = abs_path($file); DESCRIPTION
This module provides functions for determining the pathname of the current working directory. It is recommended that getcwd (or another *cwd() function) be used in all code to ensure portability. By default, it exports the functions cwd(), getcwd(), fastcwd(), and fastgetcwd() (and, on Win32, getdcwd()) into the caller's namespace. getcwd and friends Each of these functions are called without arguments and return the absolute path of the current working directory. getcwd my $cwd = getcwd(); Returns the current working directory. Exposes the POSIX function getcwd(3) or re-implements it if it's not available. cwd my $cwd = cwd(); The cwd() is the most natural form for the current architecture. For most systems it is identical to `pwd` (but without the trailing line terminator). fastcwd my $cwd = fastcwd(); A more dangerous version of getcwd(), but potentially faster. It might conceivably chdir() you out of a directory that it can't chdir() you back into. If fastcwd encounters a problem it will return undef but will probably leave you in a different directory. For a measure of extra security, if everything appears to have worked, the fastcwd() function will check that it leaves you in the same directory that it started in. If it has changed it will "die" with the message "Unstable directory path, current directory changed unexpectedly". That should never happen. fastgetcwd my $cwd = fastgetcwd(); The fastgetcwd() function is provided as a synonym for cwd(). getdcwd my $cwd = getdcwd(); my $cwd = getdcwd('C:'); The getdcwd() function is also provided on Win32 to get the current working directory on the specified drive, since Windows maintains a separate current working directory for each drive. If no drive is specified then the current drive is assumed. This function simply calls the Microsoft C library _getdcwd() function. abs_path and friends These functions are exported only on request. They each take a single argument and return the absolute pathname for it. If no argument is given they'll use the current working directory. abs_path my $abs_path = abs_path($file); Uses the same algorithm as getcwd(). Symbolic links and relative-path components ("." and "..") are resolved to return the canonical pathname, just like realpath(3). realpath my $abs_path = realpath($file); A synonym for abs_path(). fast_abs_path my $abs_path = fast_abs_path($file); A more dangerous, but potentially faster version of abs_path. $ENV{PWD} If you ask to override your chdir() built-in function, use Cwd qw(chdir); then your PWD environment variable will be kept up to date. Note that it will only be kept up to date if all packages which use chdir import it from Cwd. NOTES
o Since the path seperators are different on some operating systems ('/' on Unix, ':' on MacPerl, etc...) we recommend you use the File::Spec modules wherever portability is a concern. o Actually, on Mac OS, the "getcwd()", "fastgetcwd()" and "fastcwd()" functions are all aliases for the "cwd()" function, which, on Mac OS, calls `pwd`. Likewise, the "abs_path()" function is an alias for "fast_abs_path()". AUTHOR
Originally by the perl5-porters. Maintained by Ken Williams <KWILLIAMS@cpan.org> COPYRIGHT
Copyright (c) 2004 by the Perl 5 Porters. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Portions of the C code in this library are copyright (c) 1994 by the Regents of the University of California. All rights reserved. The license on this code is compatible with the licensing of the rest of the distribution - please see the source code in Cwd.xs for the details. SEE ALSO
File::chdir perl v5.12.5 2012-11-03 Cwd(3pm)
All times are GMT -4. The time now is 09:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy