In the last post of this series, we learned about logging in to a Linux box, creating a new non superuser account and start using that.
In this post we’ll learn how to start working with files. Creating, deleting and managing files is the reason you use a computer, right ?
Unix has a concept of directories, which is the same as a folder on Windows.
To list all the files in the current directory, use the following command:
This will give you a list of directories in what is called the wide format.
If you want to see the listing of files in the long format, which is somewhat like the “dir” command output of windows, use the following command:
$ ls -l
Now, to view the contents of a particular file, use the “cat” command:
$ cat <filename>
Now, to change into a different directory than the current one, use the following command:
$ cd ./<directory name>
Notice the “./” in front of the name. Well, lets just say you’ll learn about this a while later and keep it as it is for now.
To see the directory that you are in currently, use the following command:
the pwd command will give you what is called the full path of the current working directory. Remember the folder based hierarchy that Windows has, where all folders begin with a folder in the c: or d: or x: ? Well, Unix/Linux all folders (directories) begin from what is called the root, which is denoted by a single slash (/).
When you give the pwd command the output would be something like:
This means that the home directory is under the root (/) and under the home directory there is a directory named testuser, and under that directory is a directory named testfolder, which is where the user is currently working.
By the way, when you used the ‘ls’ command to list the contents of the directory, did you notice the first two entries in the list ? The first two entries are special. Those are the . (dot) and .. (double dot). The dot stands for the current directory and the double dot stands for the directory which is one above the current directory in the hierarchy.
So, for example, if you are in the testfolder as shown by the pwd command, and type the following:
$ cd ..
That will take you to the “testuser” directory, since testuser is one level above the testfolder directory. If, on the other hand, you just do a “cd .” (single dot), you will still be in the same directory.
That should be enough to get you all started … till my next post.