This is part of the tutorial of UNIX Commands.
In this part of the tutorial, I'll give an introduction of the basic commands to look around and move around in the filesystem.
A first thing we'd like to discover is where we are in our filesystem. For this purpose, you can issue a
pwd command and it'll give you the current directory where you are. As an example, I can issue the
pwd command from the point where I start, e.g.
[johndoe@computer johndoe]$ pwd /home/johndoe
The compute tells me I'm in the directory
johndoe which is part of the directory
home. Usually, all users' data is stored in the
home directory, under the directory with their login name (
/home/johndoe is called the home directory of user
johndoe). There is one higher level, the
/ directory, which is also called the root directory. There is no higher level than this root directory.
There are some small differences with the Windows operating system:
homedirectory can denote one hard drive or one partition of your hard disk, but it can also be true that the whole hard drive is used to denote the root directory. (Note: If you want to learn about how the hard drives and their partitions are mounted on your system, you should inspect the
/etc/fstabfile which gives a description of the partitions and their so called mount points)
/as compared to
\in Windows. This can be confusing at first, but you'll learn to use it correctly as time goes by.
In order to list the files in your current directory, you can issue the
ls command, e.g.
[johndoe@computer johndoe]$ ls dir1 file1 file2 file3
Note that there are 3 files in my directory, namely
file3, and 1 directory which I named
dir1. Most UNIX distributions use a color scheme so you'll be able to distinguish directories from files. In my setup (which is pretty common), directories are colored in blue, while other files are normally colored. Some other files (such as images or archived files) may even be colored differently.
We can get more information of our files by adding the
-l parameter to our
ls command, which will print out our directory contents as a list (that's where the
-l comes from, e.g.
[johndoe@computer johndoe]$ ls -l
total 4 drwxrwxr-x 2 johndoe johndoe 4096 Sep 27 19:21 dir1 -rw-rw-r-- 1 johndoe johndoe 0 Sep 27 19:18 file1 -rw-rw-r-- 1 johndoe johndoe 0 Sep 27 19:18 file2-rw-rw-r-- 1 johndoe johndoe 0 Sep 27 19:18 file3
This list gives more stats about the files in my home directory than the simple
ls command. The characters in the beginning show me the access modi of the files (I'll try to get into that in a later part). The
d character in the beginning of the line for
dir1 tells me it is a directory. The
johndoe strings tell me that
johndoe is the owner of the files. Next are the sizes of the files (by default, a directory takes up 4 kilobytes). You can clearly see all of the files are empty, as their sizes are
0. The date and time denote when the last changes to the files were made.
Upon the creation of your home directory, some extra hidden files were created that are placed in your home driectory. A hidden file in UNIX is simply a file whose name starts with a "
." character. You can show these files by adding the
-a (for "all") parameter, e.g.
[johndoe@anthony-laptop johndoe]$ ls -a
. .bash_history .bash_profile dir1 file1 file3 .kde.. .bash_logout .bashrc .emacs file2 .gtkrc .xauthGrxNix
Most of these files (and directories) contain default settings for various standard programs. There are two special directories, too. The
. directory points to the current directory, and the
.. directory points to the directory which is one step closers to the root directory.
You can combine the
-l parameters in one parameter
[johndoe@computer johndoe]$ ls -al
total 44 drwx------ 4 johndoe johndoe 4096 Sep 27 19:21 . drwxr-xr-x 5 root root 4096 Sep 27 01:54 .. -rw------- 1 johndoe johndoe 63 Sep 27 16:18 .bash_history -rw-r--r-- 1 johndoe johndoe 24 Sep 27 01:54 .bash_logout -rw-r--r-- 1 johndoe johndoe 191 Sep 27 01:54 .bash_profile -rw-r--r-- 1 johndoe johndoe 124 Sep 27 01:54 .bashrc drwxrwxr-x 2 johndoe johndoe 4096 Sep 27 19:21 dir1 -rw-r--r-- 1 johndoe johndoe 854 Sep 27 01:54 .emacs -rw-rw-r-- 1 johndoe johndoe 0 Sep 27 19:18 file1 -rw-rw-r-- 1 johndoe johndoe 0 Sep 27 19:18 file2 -rw-rw-r-- 1 johndoe johndoe 0 Sep 27 19:18 file3 -rw-r--r-- 1 johndoe johndoe 120 Sep 27 01:54 .gtkrc drwxr-xr-x 3 johndoe johndoe 4096 Sep 27 01:54 .kde-rw------- 1 johndoe johndoe 59 Sep 27 19:04 .xauthGrxNix
Note that the upper level directory
.. is owned by the root, the administrator or "superuser" of a UNIX system. This directory is restricted, and you thus cannot do anything in that directory, unless you are the root user.
In order to create a new (empty) file, you can issue the
touch command, where the parameter is the name of the file, e.g.
[johndoe@computer johndoe]$ touch newfile
[johndoe@computer johndoe]$ lsdir1 file1 file2 file3 newfile
The file named
newfile has been created, as can be seen in the file list I issued after "touching" the file. The
touch command was originally built for bringing a file up-to-date, i.e. changing its date and time of last changes to the current date and time. But if the file you want to touch does not exist, it creates a new empty file for you.