LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do you echo the folder name your currently in (using SHELL)? (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-you-echo-the-folder-name-your-currently-in-using-shell-710147/)

Techno Guy 03-08-2009 10:20 PM

How do you echo the folder name your currently in (using SHELL)?
 
Hi,

Im trying to find out how I can show what folder im currently in shell.

I had a little go with "ls" but could only get it to show all folders, not just the one im in.

Any help with this would be great :)

alan_ri 03-08-2009 10:26 PM

You can use pwd command.

Techno Guy 03-08-2009 10:28 PM

Ah thanks alan_ri, your a legend :)

Techno Guy 03-08-2009 10:58 PM

Wait, no not quite what I wanted,

I was hoping for just the folder not the full path.

eg,
directory:

/home/users/TECHNO/

Output:
You are in the folder TECHNO

alan_ri 03-09-2009 12:52 AM

Type in the terminal:
Code:

export PS1="\W $ "
and hit <enter>.Now on the left side will be only the name of the directory you're currently working in,not the full path.I hope that this solution will be OK for you.

Techno Guy 03-09-2009 12:57 AM

No thats not what I wanted, I want to be able to have the folder name so I can use it in a echo script.


But don't worry I got a friend to help out.
This is what he/she gave to me (and it does what I wanted):
Code:

echo $PWD | sed -e "s#[^/]*/##g"
Thought id post it so anyone else ever looking as to how it's done can see :)

alan_ri 03-09-2009 01:13 AM

Sweet. :D
Well,you've showed us how it's done.

syg00 03-09-2009 02:14 AM

This might be more readable to some ...
Code:

basename $(pwd)

Techno Guy 03-09-2009 02:34 AM

Oh nice, thats much cleaner, thanks.


All times are GMT -5. The time now is 10:51 AM.