Listing files and directories
- ls
(list)
When you first login, your current working directory
is your home directory. Your home directory has the same name as your
user-name, for example, rahul, and it is where your personal files and
subdirectories are saved.
To find out what is in your home directory, type
# ls
The ls command lists the contents of your current
working directory.
[rahul@rahul
~]$ ls
Desktop Downloads
Music new file~ Public
Videos
Documents Maildir
new file Pictures Templates
[rahul@rahul
~]$
|
There may be no files visible in your home
directory, in which case, the UNIX prompt will be returned. Alternatively,
there may already be some files inserted by the System Administrator when your
account was created.
To
list all files in your home directory including those whose names begin with a
dot, type
#
ls -a
As you can see, ls -a lists files that are normally
hidden.
[rahul@rahul
~]$ ls -a
. .dbus .gnote Maildir .pulse
.. Desktop .gnupg .mozilla .pulse-cookie
.bash_history Documents
.gstreamer-0.10 Music .ssh
.bash_logout Downloads
.gtk-bookmarks .nautilus Templates
.bash_profile .esd_auth
.gvfs new file Videos
.bashrc .gconf .ICEauthority new file~
.viminfo
.cache .gconfd .imsettings.log Pictures
.xsession-errors
.config .gnome2 .local Public
[rahul@rahul
~]$
|
- Making Directories
#
mkdir (make directory)
We will now make a subdirectory in your home
directory to hold the files you will be creating and using in the another
article. To make a subdirectory called mydir
in your current working directory type
#
mkdir mydir
[rahul@rahul ~]$ mkdir mydir
|
To see the directory you have just created, type
#
ls
[rahul@rahul
~]$ ls
Desktop Downloads
Music new file Pictures
Templates
Documents Maildir
mydir new file~
Public Videos
[rahul@rahul
~]$
|
- Changing to a different directory
cd
(change directory)
The command cd
directory means change the current working directory to 'directory'. The
current working directory may be thought of as the directory you are in, i.e.
your current position in the file-system tree.
To change to the directory you have just made, type
#
cd mydir
[rahul@rahul
~]$ cd mydir
[rahul@rahul
mydir]$ ls
[rahul@rahul
mydir]$
|
Type ls
to see the contents (which should be empty)
- The directories . and ..
Still in the mydir directory, type
#
ls –a
[rahul@rahul
mydir]$ ls
[rahul@rahul
mydir]$ ls -a
. ..
|
As you can see, in the mydir directory (and in all
other directories), there are two special directories
called (.) and (..)
The
current directory (.)
In UNIX, (.) means the current directory, so typing
#
cd .
[rahul@rahul
mydir]$ cd .
|
NOTE:
there is a space between cd and the dot
means stay where you are (the mydir directory).
This may not seem very useful at first, but using
(.) as the name of the current directory will save a lot of typing, as we shall
see later.
The
parent directory (..)
(..) means the parent of the current directory, so
typing
#
cd ..
[rahul@rahul
mydir]$ cd ..
[rahul@rahul
~]$
|
will take you one directory up the hierarchy (back
to your home directory). Try it now.
Note:
typing cd with no argument always returns you to your home directory. This is
very useful if you are lost in the file system.
- pwd (print working directory)
Path names enable you to work out where you are in
relation to the whole file-system. For example, to find out the absolute
pathname of your home-directory, type cd
to get back to your home-directory and then type
#
pwd
The full pathname will look something like this -
[rahul@rahul
~]$ pwd
/home/rahul/mydir/dlinux
|
which means that dlinux (your home directory) is in
the sub-directory mydir (the group directory),which in turn is located in the
its sub-directory, which is in the home sub-directory, which is in the
top-level root directory called " /
" .
If you Like post then share and comment please And
if you have any suggestion for me do comment .
Post a Comment