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:

[email protected]:~ $ 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:

[email protected]:~ $ 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.


[email protected]:~ $ 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:

[email protected]:~ $ 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:

[email protected]:~ $ passwd someone
passwd: You may not view or modify password information for someone.

But with sudo privilege it works just fine:

[email protected]:~ $ sudo passwd someone
New password:
Retype new password:
passwd: password updated successfully

See Also

Keep Learning

Follow me on Facebook, Twitter or Telegram:
I learn with Educative: Educative I'm also a fan of SetApp for macOS: SetApp for macOS
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 Articles
09 Mar 2022

Linux Mint as a Desktop OS

14 Oct 2021

Ubuntu 21.10 Impish Indri

15 Aug 2021

Python 3.10 Released

Recent Tweets