Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Using the sh shell (not bash), which command in Linux/UNIX prints out my current directory?

$ *showmewhereiam*
/sys/kernel/debug
$
share|improve this question
2  
A simple google search would have given the answer,wont it? –  Mad-scientist Jun 21 '11 at 11:12
2  
@Mad-scientist While this may be true, it defeats the purpose of a question/answer site to tell people to go to Google. 90% of our traffic is from web searches. –  slhck Jun 21 '11 at 11:19
2  
1  
Nothing is too simple for SEO! –  Kenzo Nov 18 '13 at 10:24
add comment

3 Answers 3

up vote 25 down vote accepted

Try pwd.

$ pwd
/home/<username>
share|improve this answer
    
Thanks =)) i got it =)) –  Minh Hieu Jun 21 '11 at 10:34
1  
when i first touch linux, i thought it's a command about password and /dev is something about development (source codes or something like that) –  LiuYan 刘研 Jun 22 '11 at 3:59
add comment

While the general answer is pwd, note that this may give different results depending on how you reached a given directory and whether the route included symbolic links.

For instance if you have a directory called real, and a symbolic link to that directory called virtual and you cd to the virtual directory then pwd will show that virtual directory name, even though the actual directory you are in is real.

To demonstrate:

$ mkdir real
$ ln -s real virtual
$ cd virtual
$ pwd
/home/<username>/virtual
$ readlink -f .
/home/<username>/real
share|improve this answer
add comment

As others said, pwd usually does the job well enough. However, I'd like to add an idea which has helped me out.

On all shells in common use today, you're able to customize the appearance of the command prompt. I like to customize mine so that it shows me both the name of the computer I'm on and my working directory. That way, I always know where I am. (The computer name part helps me realize if the terminal window I'm using has been used to SSH into a remote server.) For example, when I open a new terminal window on my laptop, which I call Plastico, I see this:

Plastico ~> cd Desktop/
Plastico ~/Desktop> cd ~/Sites/raygunrobot.com
Plastico ~/Sites/raygunrobot.com> cd /usr
Plastico /usr> 

You can see that it's abbreviating my home directory as ~. I find doing this for my terminal prompts is incredibly handy - I always know at a glance exactly where I am, even more so than I would by looking at a Finder window.

On tcsh, I do this by adding set prompt = 'Plastico %~%# ' to my .tcshrc file in my home directory. I've done it on ksh too by adding export PS1="Plastico $PWD $ " to my .profile file. But being a Linux user, you probably use Bash, which I don't have much experience with (I'm a weirdo like that). But it looks like I might be able to do it by adding PS1="Plastico \w $ " to my .bashrc file.

Edit: Just noticed the OP states you're interested in sh, not bash. Oh well; hope folks find this useful regardless.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.