Practical 10
Practical 10
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:
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).
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:
ls
Using ls -l:
ls –l
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
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
/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
pwd
The full path name of your current directory displays similar to the following:
/home/dmk