0% found this document useful (0 votes)
7 views

Practical 10

Uploaded by

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

Practical 10

Uploaded by

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

Practical 9

List the contents of a directory using basic commands like ‘ls’ and
‘pwd’
In the world of technology, the command line interface remains a powerful and
essential tool for both beginners and experts. Learning the fundamentals of command line
navigation and management is a foundational skill for anyone working in IT, development, or
data science.

ls - Listing Directory Contents: The ls command is used to list the contents of a directory.
Here's a breakdown of its syntax and some common flags:

 ls: Lists files and directories in the current working directory.

 ls [path]: Lists files and directories in the specified path.

 Flags:

-l: Long format listing, showing detailed information like permissions, owner,
group, size, and modification date.

-a: Shows hidden files and directories (those starting with a dot).

-h: Human-readable sizes, useful for understanding file sizes at a glance.

Using ls -l for Detailed Directory Listing:


The ls -l command provides a comprehensive view of directory contents in a table format
with several columns. Let's break down the information displayed for each entry:

 Content Permissions: The permissions column displays a series of characters


representing read (r), write (w), and execute (x) permissions for the owner,
group, and others.

 Owner: The owner column shows the user who owns the content..

 Group Owner: The group column displays the group to which the content
belongs. Group ownership allows collaboration and shared access.
 Size in Bytes: The size column specifies the size of the content in bytes. For
directories, this size reflects the space occupied by metadata, not the sum of
sizes of files within.

 Last Modified Date/Time: This column displays the date and time when the
content was last modified.

 File/Directory Name: The final column provides the name of the file or
directory.

Examples:

Create 5 files called file1, file2, …, file5 in our current directory.

Let’s retry the ls command to see what it will do:

ls

file1 file2 file3 file4 file5

Using ls -l:

ls –l

-rw-r--r-- 1 root root 0 Feb 28 19:45 file1


-rw-r--r-- 1 root root 0 Feb 28 19:45 file2
-rw-r--r-- 1 root root 0 Feb 28 19:45 file3
-rw-r--r-- 1 root root 0 Feb 28 19:45 file4
-rw-r--r-- 1 root root 0 Feb 28 19:45 file5

To display detailed information, type the following:

ls -l chap1 .profile

This displays a long listing with detailed information about chap1 and .profile.
To list all files in the current directory, type the following:

ls –a

. .aptitude .bashrc file2 file4 .profile .ssh


.. .bash_history file1 file3 file5 .rnd .viminfo

This lists all files, including


o dot (.)
o dot dot (..)
o Other files whose names might or might not begin with a dot (.)

 To display detailed information about a directory, type the following:

ls -d -l . manual manual/chap1

This displays a long listing for the directories . and manual, and for the file manual/chap1.
Without the -d flag, this would list the files in the . and manual directories instead of the
detailed information about the directories themselves.

pwd

Print Working Directory: The pwd command reveals the current working directory, letting
you know where you are within the file system. The command will return an absolute (full)
path, which is basically a path of all the directories that starts with a forward slash (/).

Pwd displays the full path of the current working directory.


Type these characters into your terminal and press ENTER:

Pwd

/root

The /root directory is the home directory of the root (administrative) user. If you are logged
in as another user, you will instead see something like this:

Output
/home/your_username

Another example, to display your current directory, types the following:

pwd

The full path name of your current directory displays similar to the following:

/home/dmk

home is root directory and dmk is current directory.

You might also like