0% found this document useful (0 votes)
26 views28 pages

Section 3

Uploaded by

aboudpandp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views28 pages

Section 3

Uploaded by

aboudpandp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Operating

system
section 3
TA. Ruba Hesham
TA. Abdelrahman Mohsen
Navigation
Navigation in Linux

Navigating the file system is crucial for Linux users.

pwd – Print Working Directory (Shows current


directory)
Key commands to learn: cd – Change Directory
ls – List Directory Contents
Understanding the File System Tree
Linux uses a hierarchical (tree) directory structure.

Directories may contain files and subdirectories.

Root directory (/) is at the top of the hierarchy.

Command: ls / lists the contents of the root


directory.
Navigation Commands
+ Print Working Directory (pwd):
To display the current working directory, we use the pwd (print working directory)
command.

When we first log in to our system (or start a terminal emulator session) our current
working directory is set to our home directory. Each user account is given its own home
directory and it is the only place a regular user is allowed to write files.
Navigation Commands
+ List Directory Contents (ls):
To list the files and directories in the current working directory

Note: we can use the ls command to list the contents of any directory, not just the
current working directory, we will explain later
Navigation Commands

+ Changing Directories (cd):


Use cd followed by the pathname to change the current directory.
A pathname is the route through the directory tree to reach the target directory.
Types of Pathnames

+ Absolute Pathname:
Begins from the root directory (represented by /)

Changes directory by specifying the full path from the root.


Types of Pathnames
+ Relative Pathname:
+ Begins from the current working directory (CWD).
+ Uses special notations:
. (dot): Refers to the current directory.
.. (dot dot): Refers to the parent directory.
+ Shell Prompt Convenience
The shell prompt often shows the name of the current directory for easy navigation.
Changing the Current Working
Directory (CWD) in Linux
+ Important Note:
• The ./ can usually be omitted in relative pathnames as it is implied.

• This behaves the same as cd ./bin.


Some Helpful Shortcuts

Shortcut Result

cd Changes the working directory to your home directory.

cd - Changes the working directory to the previous working directory.

cd username Changes the working directory to the home directory of user_name. For
example, cd ~bob will change the directory to the home directory of
user “bob.”
Exploring the
System
learn some more commands

ls – List directory contents

file – Determine file type

less – View file contents


Listing the content of a directory (ls)
ls /path specify the directory to list
ls ~ /usr List files in multiple directories
ls -l format of the output to reveal more detail
ls -lt--reverse ls command is given two options, the “l” option to produce
long format output, and the “t” option to sort the result by the
file's modification time “--reverse” to reverse the order of the
sort
ls -a List all files, include hidden files
ls -A Like –a option except it doesn’t list . And ..
Ls command
see directory contents and determine a variety of important file and
directory at tributes.
Besides the current working directory, we can specify the directory
to list
Ls command
We can even specify multiple directories. In the following example,
we list both the user's home directory (symbolized by the “~”
character) and the /usr directory.
Ls command
By adding “-l” to the command, we changed the output to the long format.
Ls command
Commands are often followed by one or more options that modify their
behavior, and further, by one or more arguments, the items upon which
the command acts. So most commands look kind of like this:
Ls command

Most commands use options which consist of a


single character preceded by a dash, for example,
“-l”. Many commands, however, including those
from the GNU Project, also support long options,
consisting of a word preceded by two dashes.
Also, many com mands allow multiple short
options to be strung together. In the following
example, the ls command is given two options,
which are the l option to produce long format
output, and the t option to sort the result by the
file's modification time.
Ls command
We'll add the long option “--reverse” to reverse the order of the sort.
Ls command
List all files, even those with names that begin with a period, which are
normally not listed (that is, hidden).
Ls command
Like the -a option above except it does not list . (current directory) and ..
(parent directory).
Common ls Options
Option Long Option Description
-a --all List all files, even those with names that begin with a period, which are normally not listed (that is,
hidden).
-A --almost-all Like the -a option above except it does not list . (current directory) and .. (parent directory).
-d --directory Ordinarily, if a directory is specified, ls will list the contents of the directory, not the directory itself.
Use this option in conjunction with the -l option to see details about the directory rather than its
contents.
-F --classify This option will append an indicator character to the end of each listed name. For example, a
forward slash (/) if the name is a directory.
-h --human-readable In long format listings, display file sizes in human readable format rather than in bytes.
-l Display results in long format.
-r --reverse Display the results in reverse order. Normally, ls displays its results in ascending alphabetical order.

-s Sort results by file size.


-t Sort by modification time.
Determining a File's Type with file
use the file command to determine a file's type.

There are many kinds of files. In fact, one of the common ideas in
Unix-like operating systems such as Linux is that “everything is a
file.” As we proceed with our lessons, we will see just how true that
statement is.
Viewing File Contents with less
The less command is a program to view text files. Throughout our Linux
system, there are many files that contain human-readable text. The less
program provides a convenient way to examine them.

Once the less program starts, we can view the contents of the file. If the
file is longer than one page, we can scroll up and down. To exit less, press
the q key. The table below lists the most common keyboard commands
used by less.
less Commands
Command Description
Page Up or b Scroll back one page
Page Down or space Scroll forward one page
Up arrow Scroll up one line
Down arrow Scroll down one line
G Move to the end of the text file
1G or g Move to the beginning of the text file
/characters Search forward to the next occurrence of characters
n Search for the next occurrence of the previous search
h Display help screen
q Quit less
less
Commands
Any questions?

You might also like