Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-21-2006, 12:32 AM   #1
LQ Newbie
Registered: Apr 2006
Posts: 5

Rep: Reputation: 0
How to get the dirname only from pwd?

pwd returns /home/user/test . How would I use sed or something similar to strip the leading directories and leave only the current dir? "test" in this case.

Old 04-21-2006, 12:34 AM   #2
Senior Member
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
I know you can do such things with Perl quite easily (look at the File::Basename module), but I am no sed nor awk master
Old 04-21-2006, 12:43 AM   #3
LQ Newbie
Registered: Apr 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Could you perhaps be more specific? This is my first real delve into programming. Basically what I want to do is have it get the name of the dir it is being run from, and make a directory with the same name in another location.

Sorry, should have been more detailed with my background . You can safely assume I know absolutely nothing about scripting other than how to make it executable and how to run it, heheh.

Thanks again.
Old 04-21-2006, 01:22 AM   #4
LQ Newbie
Registered: Apr 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Got it, theres a prog called basename that does this.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nautilus and dirname drgilberto Programming 0 02-14-2006 02:08 PM
dirname basename; how to capture extensions from bash? carl0ski Linux - General 2 07-22-2005 07:26 AM
dirname error when installing Java JRE jrdioko Linux - Software 0 05-20-2005 05:35 PM
reset pwd to root's current pwd? ataraktos2 Linux - General 10 04-26-2005 04:13 AM
pwd Penguin666 Linux - General 1 11-19-2003 07:54 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:30 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration