Command Line Essentials: Navigating the Filesystem

Table of Content, Text and Pipeline

The filesystem contains files and directories. Files contain data and directories contain files and other directories. There is one single special directory – the root directory – that is inside no other directory. It is the root, where everything starts. Now give three commands:

essentials@kvaser:~$ cd /
essentials@kvaser:/$ pwd
/
essentials@kvaser:/$ ls
bin   dev  home  lost+found  mnt  proc  sbin     srv  tmp  var
boot  etc  lib   media       opt  root  selinux  sys  usr

cd: change directory (the / is the root)
pwd: print working directory
ls: list files and folders

Now, we will list the contents of the root directory and get a little more information:


essentials@kvaser:/$ ls -l
total 109
drwxr-xr-x  2 root root  4096 Feb 18 06:51 bin
drwxr-xr-x  3 root root  1024 Feb 18 07:03 boot
drwxr-xr-x 13 root root  2880 Feb 18 07:06 dev
drwxr-xr-x 78 root root  4096 Feb 28 22:11 etc
drwxr-xr-x  8 root root  4096 Feb 28 21:39 home
drwxr-xr-x 10 root root  8192 Feb 18 06:51 lib
drwxr-xr-x  2 root root 49152 Feb  2 21:01 lost+found
drwxr-xr-x  3 root root  4096 Feb 17 21:39 media
drwxr-xr-x  2 root root  4096 Jan 16 21:45 mnt
drwxr-xr-x  2 root root  4096 Feb  2 21:27 opt
dr-xr-xr-x 83 root root     0 Jan  1  1970 proc
drwxr-xr-x  4 root root  4096 Feb  3 21:04 root
drwxr-xr-x  2 root root  4096 Feb 18 06:52 sbin
drwxr-xr-x  2 root root  4096 Sep 16  2008 selinux
drwxr-xr-x  2 root root  4096 Feb  2 21:27 srv
drwxr-xr-x 11 root root     0 Jan  1  1970 sys
drwxrwxrwt  3 root root  4096 Feb 28 22:17 tmp
drwxr-xr-x 10 root root  4096 Feb  2 21:27 usr
drwxr-xr-x 14 root root  4096 Feb  2 22:38 var

The “d” first in the line means “directory”. Ignore the rest of the columns for now. Lets list the contents of the folder bin:

essentials@kvaser:/$ ls -l bin
total 4996
-rwxr-xr-x 1 root root 790844 Apr 10  2010 bash
-rwxr-xr-x 1 root root 502968 Nov 15 16:46 busybox
-rwxr-xr-x 1 root root  38996 Apr 28  2010 cat
-rwxr-xr-x 1 root root  51244 Apr 28  2010 chgrp
  (many lines)
-rwxr-xr-x 1 root root   2015 Jan 20  2010 zforce
-rwxr-xr-x 1 root root   5597 Jan 20  2010 zgrep
-rwxr-xr-x 1 root root   1733 Jan 20  2010 zless
-rwxr-xr-x 1 root root   2416 Jan 20  2010 zmore
-rwxr-xr-x 1 root root   4952 Jan 20  2010 znew

Here, the number before the date is the size of the file, in bytes.
The “x” means “executable” – that is a program. Confusingly, also directories are considered executable here.

Spend some time exploring your filesystem with cd, pwd, ls, for example:

essentials@kvaser:/$ cd etc/
essentials@kvaser:/etc$ pwd
/etc
essentials@kvaser:/etc$ cd ..
essentials@kvaser:/$ pwd
/
essentials@kvaser:/$ cd usr/bin/
essentials@kvaser:/usr/bin$ pwd
/usr/bin
essentials@kvaser:/usr/bin$ cd ..
essentials@kvaser:/usr$ ls
bin  games  include  lib  local  sbin  share  src
essentials@kvaser:/usr$ 

Do play around more!

All those files and folders are not for you to modify. If you want to make your own folders and fill them with files, first go home:

essentials@kvaser:/$ cd
essentials@kvaser:~$ mkdir MyFirstFolder
essentials@kvaser:~$ touch MyFirstFile
essentials@kvaser:~$ ls -l
total 4
-rw-r--r-- 1 essentials essentials    0 Feb 28 22:39 MyFirstFile
drwxr-xr-x 2 essentials essentials 4096 Feb 28 22:39 MyFirstFolder
essentials@kvaser:~$ pwd
/home/essentials

Several things to note here…
cd without arguments takes you home
touch creates an empty file (size = zero bytes), not executable
ls -l outputs essentials, the user (and group) who owns the file. There is a special user (and group) named root who owns most other files in the filesystem. The root user is a completely different thing than the root directory.

You can clean up again:

essentials@kvaser:~$ rm MyFirstFile 
essentials@kvaser:~$ rmdir MyFirstFolder/
essentials@kvaser:~$ ls
essentials@kvaser:~$ 

If you run cygwin (under Windows) you can try

$ cd /cygdrive/c

which takes you to your Windows c-drive.

Finally, end your session:

essentials@kvaser:~$ exit
exit
  1. Command Line Essentials: Introduction | TechFindings - pingback on 2011/02/28 at 22:50

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trackbacks and Pingbacks: