Linux Classes
Linux Training
* Linux Classes *

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)

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


*Name:
Email:
Notify me about new comments on this page
Hide my email
*Text:
 

Ask Bob Rankin - Free Tech Support
<Send This Link to a Friend>         <Bookmark This Page>


Copyright © by Bob Rankin
All rights reserved - Redistribution is allowed only with permission.