How to get directory name from its path?


 
Thread Tools Search this Thread
# 1  
Old 02-12-2009
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

> [command] $test
folder1

I'd rather avoid anything with regular expressions. Any ideas?
# 2  
Old 02-12-2009
Code:
$ test=`pwd/folder1
$ basename $test
folder1

basename will return everything after the last forward slash.
dirname will return everything up to the last forward slash.
 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Extract directory name from the full directory path in UNIX using shell scripting IshuGupta UNIX for Dummies Questions & Answers 5 06-03-2014 08:15 PM
Keep last directory from path Aswex Shell Programming and Scripting 1 11-12-2013 10:03 AM
How to get the current directory Path? Abhishek0683 UNIX for Dummies Questions & Answers 3 06-30-2013 01:14 PM
How to select First two directory in from path name? yadavricky Shell Programming and Scripting 10 11-12-2012 11:33 AM
How to get last directory path in script vel4ever Shell Programming and Scripting 6 07-10-2012 02:26 PM
"find . -printf" without prepended "." path? Getting path to current working directory? pstein Shell Programming and Scripting 1 10-02-2011 08:23 AM
Extracting Directory From Path Drayol Shell Programming and Scripting 3 04-15-2011 10:05 PM
Retrieve directory path from full file path through sh royzlife Shell Programming and Scripting 7 09-21-2010 08:28 AM
Print directory name along with their path jadoo_c2 Shell Programming and Scripting 5 07-19-2010 04:54 AM
change directory path rsivasan HP-UX 3 06-27-2010 01:43 PM
Help with directory path parsing brianjbrady Shell Programming and Scripting 8 02-16-2010 12:58 PM
Getting real path to directory kandrewo UNIX for Advanced & Expert Users 7 12-18-2009 03:05 PM
Variable directory name in path glev2005 Shell Programming and Scripting 2 09-18-2009 10:17 AM
Verify the directory path sollins Shell Programming and Scripting 1 12-08-2008 02:07 AM
Determining directory path cwalsek Shell Programming and Scripting 2 07-19-2007 09:04 AM