Change PWD in Linux

Changing PWD in Linux Changing PWD in Linux?

PWD could mean three things in Linux, so first confirm what you’re trying to achieve here.

pwd - current working directory

If you just type pwd in your command line prompt, it will confirm your present current directory - the place in the filesystem hierarchy you’re currently at:

greys@server:~ $ pwd

So this above shows that I’m in my home directory, /home/greys at the moment.

You can change what pwd returns by moving into another directory using cd command:

greys@server:~ $ cd /tmp

now if we run pwd again, it will show that our current directory (pwd) is /tmp:

PWD - shell variable

Similar to the pwd command, PWD is a standard shell variable reporting your current home directory.

It’s not meant to be changed directly - supplying new value will not magically move you into new filesystem location. Rather, your current shell will track your commands and keep this variable updated to reflect where you are in the filesystem.


greys@server:~ $ echo $PWD

pwd - password for a user

If you’re looking to change a password for a given user in Linux, that’s easy! For your own user, you just type passwd , supply your current password and then provide new password, like this:

greys@server:~ $ passwd greys
Changing password for greys.
Current password:
New password:
Retype new password:
passwd: password updated successfully

You will need to have sudo privilege or be root user in order to change someone else’s password.

If you just attempt changing another user’s password, you’ll get an error:

greys@server:~ $ passwd someone
passwd: You may not view or modify password information for someone.

But with sudo privilege it works just fine:

greys@server:~ $ sudo passwd someone
New password:
Retype new password:
passwd: password updated successfully

See Also

Contact Me

Follow me on Facebook, Twitter or Telegram:
I learn with Educative: Educative
IT Consultancy
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!

Recent Tweets