When you first open your terminal you will arrive at home directory. Each user has his own home directory. Let’s take a look how you can move up and down the file system tree.

pwd

To check where are you at any given moment you can print current working directory.

$ pwd
output: /root/home/christopher

cd

To navigate through the file system tree, you can use change directory command followed by the relative or absolute path to another directory. Relative path starts from your current working directory while absolute path starts from the root directory. You can recognize absolute path by the leading slash in the path name.

  • .” – Refers to your current working directory
  • ..” – Refers to the parent directory of your current working directory

Examples

  • absolute path
$ cd /usr/bin
  • relative path
$ cd my-projects$ cd ./my-projects
  • go to parent directory of your current working directory
$ cd ..
  • go back to previous directory
$ cd -
  • go to home directory
$ cd $ cd ~
  • go to user’s ( bob ) home directory
$ cd ~bob

ls

You can check out the contents of any given directory with list command followed by the path to the directory. If no path is specified contents of current working directory will be listed.

Flag shortFlag LongDescription
-a–allDisplay all files, even those with names that begin with a period
-A–almost-alllike the -a option but doesn’t display . and ..
-d–directoryuse this in conjunction with -l to see details of the directory itself rather than its contents
-lDisplay results in long format
-F–classifyappend “/” to directory names
-h–human-readableIn long format listing, display file sizes in human readable format rather than in bytes
-r–reverseDisplay results in reverse order. Normally results are displayed alphabetically
-SSort by file size
-tSort by modification time

Examples

  • List contents of home directory and current working directory
$ ls ~ .
 >>> -rw-rw-r--   1 root root   4096 feb 15 15:46 index.html

Let’s take a look on the ls -l output

codeexplaination
-rw-rw-raccess rights to the file
1number of files hard links
rootusername of the files’s owner
4096file size in bytes
feb 15 15:46date of last modification
index.htmlfile name

file

In Linux file name is not required to reflect its content. This means it’s normal for a file to not have an extension. To find out what kind of file we are dealing with we can use file command.

$ file favicon
>>> ./favicon PNG image data, 185 x 220, 8-bit/color RGBA, non-interlaced

less

Less is a program and a command for viewing text files.

commandaction
PAGE UP or bscroll one page up
PAGE DOWN or SPACEscroll one page down
Gmove to the end of the file
1G or gmove to the beginning of the file
/searchphrasefind new occurrence of searchphrase
nfind next occurrence of previous search
hdisplay help
qquit less

Example

$ less /etc/passwd