Navigation commands

These commands fall into the category of navigation, as they are mostly used for navigating paths:

  • pwdThe pwd command displays the full pathname of your current working directory. It helps in determining the current syntax to be used with other commands such as cp, mv, rm , mkdir, and so on, using relative pathnames, as shown in the following screenshot:

  • lsThe ls command is used to list the directory contents of the given directory. If no directory name is given, then it lists the contents of the current directory as shown in the following screenshot:

The ls command has got many options that are often used together to produce more structured and human-readable output. The most commonly used options with ls are listed in the following table:

Option

Description

-a

Displays the filenames beginning with a (.), as any filename beginning with (.) is hidden by default

-l

Displays detailed information on contents, also known as the long-listing format

-t

Sorts the listing contents by modification time, with last modified file first

-r

Lists the contents in reverse order while sorting by filename

-h

Prints the sizes of files in human-readable format (for example, 1 K, 50 M, 3 G, and so on)

-S

Sorts the contents by file size

-i

Prints the inode number of each file in listing

-Z

Displays the security context (SELinux parameter) for each file

 

The examples of ls command usage are shown in the following screenshot:

  • cd: The cd command is used to change your working directory. We generally use relative pathnames for brevity while changing directories on the command line. However, while creating scripts, it's good practice to use absolute pathnames. The cd command has many options, some of which are described in the following table:

Option

Description

cd -

Changes directory to previous working directory

cd or cd ~

Changes directory to user's home directory

cd ~<username>

Changes directory to the specified <username> user's home directory

cd . .

Changes directory to up one level to the parent directory

 

The examples of cd command usage are shown in the following screenshot:

The (. .) represents the parent directory of your current working directory, and (.) represents your current directory in relative pathname format.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.51.157