How to change directory in Red Hat Linux

Asked By 10 points N/A Posted on -
qa-featured

Hi Guys,

I am a new user in Red Hat Linux. Now I want to change my present directory.

But I do not know how can I change my present directory.

Can anybody give me any solution about this?

Please help me.

SHARE
Best Answer by srknitk
Best Answer
Best Answer
Answered By 0 points N/A #115747

How to change directory in Red Hat Linux

qa-featured

 

Do you mean home directory? (The directory where you can write files and place your personal files)
 
There are 2-3 methods to change the home directory.
 
1. To change the home directory without moving the contents in the old home directory
  • Open the terminal
  • login as root
  • execute the command 
  • #usermod -d <absolute path of new home directory> <username>
  • For ex: #usermod -d /home/user1 user3
  • in the above example user3 is the name of that user and /home/user1 is the absolute path of the new home directory
2. To change the home directory and also moving the contents in the old home directory
  • Open the terminal
  • login as root
  • execute the command
  • #usermod -md <absolute path of new home directory> <username>
3. By editing the /etc/passwd file
  1. Open the terminal
  2. login as root
  3. #vi /etc/passwd
  4. move the cursor to the line where you find the entry like the one below. (your username in place of user3 and the uid=1000 may change)
  5. user3:x:1000:1000:User3,,,:/home/user3:/bin/bash
  6. press Insert button on the keyboard and replace the /home/user3 with the new home directory you want
  7. for ex:
  8. user3:x:1000:1000:User3,,,:/home/user1:/bin/bash
  9. now save the file(press Esc and then type 😡 and press Enter) and logout and login to that user.
Answered By 0 points N/A #115748

How to change directory in Red Hat Linux

qa-featured

 

Changing directory is easy when you know where you are:
 
Determine current directory with pwd
 
pwd stands for print working directory. when you type pwd, you asked linux system to display your current location. By default , the Bash Prompt in Red Hat Enterprise Linux shows just the current directory.
 
[alman@alman yen]$ pwd
 
/home/yen
 
[alman@alman yen]$
 
the example shows that you are in the yen's directory, which is in the home directory.
 
Changing directories with cd
 
to change directory use the cd command. Typing cd by itself returns you to your home directory, moving to any other directory requires a pathname.
 
there are two types of pathname: absolute and relative.
 
Absolute path start at the top of the file system with " / " which referred as root.and then look down for the requested directory.
 
Relative path look down from your current directory . The below attachment illustrate how cd operates:
 
/
 
/directory1
 
/directory1/directory2
 
/directory1/directory2/directory3
 
if you are in directory 3 & you want to move to directory 1, you need to move up in the directory tree by execuding:
 
cd directory1
 
while you are in directory 3,if presents any error that there is no such directory .This happens because there is no directory 1 below directory 3 .
 
to move up to directory 1 , type  cd/directory1
 
this is an example of absolute path.using absolute path to change directory it needs to know and type the entire path. where using relative path allows to change directory relative to the directory you currently in. now follow the attachments. thank you.
 

Related Questions