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
/home/greys

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.

Example:

[email protected]:~ $ echo $PWD
/home/greys

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 with Me

Follow me on Facebook and Twitter or jump into Telegram chat!:
Recommended Software
I use Brave browser, it's awesome: Brave Browser 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 Tweets