Site Menu

Share

LINUX CLASSES - FILES

How Do I Navigate the File System?

Tree Climbing

You can move from one directory to another using the cd command. For example, if you are in your home directory (/home/hermie) and want to switch to the recipes directory (/home/hermie/recipes), the following command does the trick: cd recipes

To switch back to your home directory, you could type

cd /home/hermie

but there are two shortcuts you will find useful. The first is the double-dot (..) notation, as in

cd ..

This will move you one level up, to the parent directory. You can even enter something like

cd ../secrets

to move up to the parent and then go back down to a directory that is at the same level as the current one. This double-dot notation is not specific to the cd command, though. You can use it with any Linux command that needs a file name as input. You might also see the single-dot (.) notation, which means "this directory." It wouldn't make much sense to enter cd . because you'd still be in the same directory, but there are other commands (notably, the find command, described in the "Important Linux Commands" section). where it's convenient to use the single dot as shorthand for the current directory name.

Another directory navigation shortcut involves using $HOME. No matter what directory you are in, the following command will return you to your personal recipes directory:

cd $HOME/recipes

And if you want to change to another user's home directory, you can use the tilde (~) notation. In the following examples, the tilde character is shorthand for "the home directory of." You must put the name of a user on your system immediately after the tilde.

For example, cd ~sigmund means "change to sigmund's home directory;"

cd ~edbo/stuff means "change to edbo's stuff directory."

The single-dot, double-dot, and tilde notations are useful in conjunction with the cd command, but they can also be used in any Linux command where you need to enter a file or directory name.

TIP: One common mistake people make in navigating Linux directories is using a slash in front of file names when it is not needed. Suppose you have a bin directory under your home directory. If you were at /home/hermie and you entered cd /bin, you'd end up at the bin underneath the root directory--oops. (Linux understands the slash before bin as telling it to go to the root directory first and then to the bin directory just below the root.) The correct way to reach the bin directory under /home/hermie is to type from within your home directory (/home/hermie) cd bin. Don't use a leading slash unless you're sure you want to start at the top (root) of the file tree.

Previous Lesson: Directory Terminology
Next Lesson: Listing Linux Files

[ RETURN TO INDEX ]


   

Comments - most recent first
(Please feel free to answer questions posted by others!)

Harshit     (21 Mar 2012, 05:16)
cd - (cd dash)

this command is back us on that directory where we lastly typed 'pwd' command.
Jay Easy     (02 Mar 2012, 08:01)
Thanks!!
Pranava     (09 Oct 2011, 13:55)
@varda -: These commands are to be typed in the terminal. All Linux distros have a terminal.
varda     (20 Sep 2011, 17:18)
hi. i am very very much of a rooky and feel embarrassed even to ask. but where do i type cd etc. what place do i go to. is there a monitor allowing that. where do i find it
Pete     (28 Aug 2011, 00:09)
I am pretty sure the CD alone won't go home for all distributions...

I am also sure that all of them do support

CD ~

And this will take you to your home directory for sure.
Thomas     (16 Jan 2011, 01:07)
You can also just type: "cd" with no arguments to get back to your home directory.
Bob Rankin     (21 Apr 2010, 13:11)
Environment variables start with a "$" to indicate that the value of the variable should be substituted there. It seems a bit odd to have a file or directory starting with "$" but you can do it. Just be sure to escape the "$" with a backslash or put the name in single quotes. For example:

mkdir \$myfolder
mkdir '$myfolder'
Meg     (21 Apr 2010, 13:04)
Quick question (I hope): what is the significance of the $ sign in front of the directory name? It's used above with the cd command and was used previously on the Environment Variables page. I'm trying to install a model where I have to create directories with names starting with a $ sign, and I can't figure out what means. Sure, I can just follow the directions and hope for the best, but it would be nice to actually know what I'm doing. ;) Haven't been able to find the answer online. Thanks for the great site.
Arye Hartmann     (22 Mar 2010, 04:24)
Hi Bob
i need to access a disk-on-key that contains
Microsoft word/Excell files.
When i insert a disk-on-key on the usb port my (year 2000) pentium 3 computer does not seem to notice.
What is the quick one time solution ?
What is the long term/permanent solution ?
Arye


I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But don't ask me to send what you already have. :-)

NO SPAM! If you post garbage, it will be deleted, and you will be banned.
*Name:
Email:
Notify me about new comments on this page
Hide my email
*Text:
 
 


Ask Bob Rankin - Free Tech Support


Copyright by - Privacy Policy
All rights reserved - Redistribution is allowed only with permission.