Page 144 - DCAP106_OPERATING_SYSTEM_TOOLS
P. 144
Unit 8: Shell Commands
Notes
Examples:
ls: This command list files in current directory
ls -l: It lists files in “long” format
ls -l --color: It shows colourized output
cat filename: It shows contents of a file
cat -n filename: It shows contents of a file, with line numbers
Let us discuss some in detail. Let us consider two commands pwd and ls.
z z The pwd Command: The command ;pwd’ stands for present working directory. This
command shows the name and location of the current directory, which is the directory
(also known as a folder on some operating systems) in which the user is currently working.
To use this, type the word pwd at the keyboard and then press the ENTER key:
pwd
If the terminal window or console has just been opened, then the monitor screen will
show /home followed by another forward slash and then the name of the user’s home
directory. Remenber that the user’s home directory is usually the same as the user name.
Example: If the user has a user name of miky, the line would say /home/miky.
This is because a user begins working at the command line in its home directory, home
directories are located in the directory named /home, and a user’s home directory usually
has the same name as the user name.
z z The ls Command: Another most basic and frequently used commands on Unix-like
operating systems is ls. This command is equivalent to DIR on MS-DOS systems. Also,
it lists the contents of a directory. When used just by itself, it offers a list of the names of
the objects (that is, files, directories and links) in the current directory, i.e.,
ls
You can see that various names are listed, but no additional information is provided about
them. This is often sufficient. However, in most of the cases it is desired to get additional
information about each directory object. Getting such information can be easily attained
by using ls together with one or more of its options. We can define an option as a letter (or
in some cases a word) that follows the command after a space and that tells the command
how to behave. We can use various options together, and they are usually preceded directly
by a hyphen (without any intervening space). The options available can vary as per the
specific command.
Example: The -a option tells ls to show all objects in the directory, inclusive
of hidden files or hidden directories. Hidden objects are those whose names are normally
not visible either in the command line or when examining the contents of a directory in a
GUI. Their names are preceded directly by a period, such as .file1. Thus to see the names
of all objects in the current directory, the following command should be typed in and then
the ENTER key pressed:
ls -a
Many commands have several options, and ls is no exception. But, only some of them are
often used. Another generally used option for ls is –l. This option provides a long listing, i.e.,
it provides much information about each object in addition to just its name. This additional
information includes the type of object (e.g., file, directory or link), its permissions (i.e.,
who has access to it for reading, writing and/or executing), its owner (which is by default
the same as its creator), and the date and time of creation.
LOVELY PROFESSIONAL UNIVERSITY 137