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 short | Flag Long | Description |
---|---|---|
-a | –all | Display all files, even those with names that begin with a period |
-A | –almost-all | like the -a option but doesn’t display . and .. |
-d | –directory | use this in conjunction with -l to see details of the directory itself rather than its contents |
-l | Display results in long format | |
-F | –classify | append “/” to directory names |
-h | –human-readable | In long format listing, display file sizes in human readable format rather than in bytes |
-r | –reverse | Display results in reverse order. Normally results are displayed alphabetically |
-S | Sort by file size | |
-t | Sort 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
code | explaination |
---|---|
-rw-rw-r | access rights to the file |
1 | number of files hard links |
root | username of the files’s owner |
4096 | file size in bytes |
feb 15 15:46 | date of last modification |
index.html | file 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.
command | action |
---|---|
PAGE UP or b | scroll one page up |
PAGE DOWN or SPACE | scroll one page down |
G | move to the end of the file |
1G or g | move to the beginning of the file |
/searchphrase | find new occurrence of searchphrase |
n | find next occurrence of previous search |
h | display help |
q | quit less |
Example
$ less /etc/passwd