Navigating the Linux Filesystem
Upside-down TreesOkay, you've been reading the articles on Linux Planet on some of the nifty tricks you can do in the shell, and you're sold. But to get anything done, you have to know how to find your way around. There are no file icons to click on -- how do you find your files?
You've probably read that files on a Linux disk are structured like a tree. Well -- at least that's true if you live in backwards-land where trees grow downward. Give computer nerds some leeway -- a lot of them don't get out much to see real live trees, so maybe they weren't clear on the fact that real trees usually start at the bottom and grow upward.
Every file lives inside a directory. Directories can contain files, other directories, or any combination of the two. If you're coming from Windows or Mac, "directory" means the same as "folder". In Figure 1, directories have boxes around them; files don't.
The root directory
At the very top of the hierarchy is a special directory called the root directory, or / (a single forward slash). Remember how we're talking about an upside-down tree? The root is at the top.
Don't confuse the "root" directory with "root" meaning the super user. Two meanings for the same word.
You can see what's in the root directory using the ls command (short for "list" since it lists files and directories):
ls /You'll see a lot of directories with names like boot, dev, home, usr, and etc (yes, that's really the name of a directory). Most of these are system directories: they contain installed programs, or configuration files Linux needs to do its job. But for now, let's concentrate on the directory named home: that's where your user files are.
You can refer to any directory or file on your system by what's called its "full path", starting with / for the root directory. So if you want to find out what's in that directory called home, you can refer to it this way:
$ ls /homeThe slash before the directory name is important: it says that you want the directory called home that's right under the root directory. If you omitted the slash and just said
ls home, you'd be asking for a directory called home starting from wherever you happen to be at the moment.
Your working directory
Wait, what does that mean -- "wherever you happen to be"?
On Linux, you always have a "current working directory". When you log in, that's usually your home directory. If you're in your home directory and try to ls home, without a leading slash, you'll probably see:
$ ls home ls: cannot access home: No such file or directory
pwd command ("print working directory") will tell you
what your current directory is. To change your working directory, use
the cd ("change directory") command:
$ cd /will change your working directory to the root directory. Then if you ask for your working directory, you'll see this:
$ pwd /
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.
- 1Linux Top 3: GNOME 3.12 and New Betas for Ubuntu 14.04 and OpenMandriva Lx 2014.0
- 2Linux Top 3: Linus Lashes out, Linux 3.14 Gets PIE and Ubuntu One is Done.
- 3Linux Top 3: Ubuntu 14.04, Debian Gives Squeeze More Life and Red Hat Goes Atomic
- 4Linux Top 3: Linux 3.11, Kubuntu Goes Commercial
- 5Linux Top 3: RHEL 6.5, Debian 7.2 and EOL for Linux 3.0.x