VMware ESXi and vSphere Cluster Management

Essential Linux Commands: ls, pwd, mkdir, echo, whoami, and cd

Learn the essential Linux shell commands ls, pwd, mkdir, echo, whoami, and cd for identifying your location, managing directories, and navigating the terminal.

Introduction to the Linux shell

Linux commands are entered in a terminal, a text-based interface for interacting with a Linux system. The commands are read and run by a shell, which is the command interpreter behind the terminal prompt.

A command is a program or shell instruction that you type at the prompt. A command can be followed by one or more arguments, which provide additional input such as a directory name, a file name, or a path.

command argument

For example, in ls my_folder, ls is the command and my_folder is an argument.

The shell always has a current working directory. This is the directory in which the shell is currently operating. When a command does not receive an explicit path, it commonly works with the current working directory.

Find your location with pwd

The pwd command prints the full path of the current working directory. The name means “print working directory.”

pwd

Example output might look like this:

/home/alex

The output tells you exactly where the shell is operating. Use pwd before creating or inspecting items when you are unsure of your location.

List files and directories with ls

The ls command displays the contents of a directory. Its output can include both files and directories.

List the current directory

Run ls without an argument to list the contents of the current working directory:

ls

If the current directory contains a file named notes.txt and a directory named projects, the output could be:

notes.txt  projects

List a different directory

Give ls a directory path to inspect a location other than the current directory:

ls /home/alex/projects

Because an explicit path was supplied, this command lists /home/alex/projects even if the shell is currently somewhere else.

Create directories with mkdir

A directory is a filesystem container that can hold files and other directories. The mkdir command creates a new directory.

A directory name is required. Without a parent path, the new directory is created in the current working directory:

mkdir my_folder

Verify that the directory exists by listing the current directory:

ls

You should see my_folder in the output. The exact order of the output can vary.

You can also provide a path. For example, mkdir /home/alex/projects attempts to create projects inside /home/alex. The supplied location must be valid, and the user must have permission to create the directory there.

Display text with echo

The echo command writes supplied text to the terminal:

echo Hello

Output:

Hello

When text contains spaces, place the complete message in quotation marks. This groups the words as one text argument and is a clear beginner-friendly convention:

echo "Hello, Linux"

Output:

Hello, Linux

echo displays text; it does not identify your user or your current directory.

Identify the active user with whoami

The whoami command displays the username associated with the current shell session:

whoami

Example output:

alex

A username is the account name of the user running the shell session. It may not match the person's full name or graphical display name.

whoami answers “Which Linux account am I using?” In contrast, pwd answers “Which directory am I currently in?”

Change directories with cd

The cd command changes the current working directory. To enter a directory located in the current directory, provide its name:

cd my_folder

Confirm the change with pwd:

pwd

If the original location was /home/alex, the result should now be:

/home/alex/my_folder

A path identifies the location of a file or directory in the filesystem. When moving to a specific location with cd, the supplied directory name or path must exist and identify a directory.

cd /home/alex/projects

After this command, the current working directory becomes /home/alex/projects if that path is valid and accessible.

Basic Linux command workflow

The following sequence checks the current location, inspects it, creates a directory, verifies it, enters it, and confirms the new location:

pwd
ls
mkdir my_folder
ls
cd my_folder
pwd

A typical session might produce output similar to this:

$ pwd
/home/alex

$ ls
notes.txt  projects

$ mkdir my_folder

$ ls
my_folder  notes.txt  projects

$ cd my_folder

$ pwd
/home/alex/my_folder

The output from mkdir and cd is often empty when the commands succeed. Use ls and pwd to verify their effects.

This workflow demonstrates an important rule: command effects depend on the current working directory unless you provide an explicit path. In this example, mkdir my_folder creates the directory in /home/alex because that was the current location at the time.

Essential Linux command reference

CommandPurposeBasic syntaxExampleWhat it affects or displays
lsList directory contentsls [path]lsDisplays files and directories; without a path, uses the current directory
pwdPrint the current working directorypwdpwdDisplays the full path of the current directory
mkdirCreate a directorymkdir directory_namemkdir my_folderCreates a directory in the current location unless a path is supplied
echoDisplay textecho textecho "Hello, Linux"Writes the supplied text to the terminal
whoamiDisplay the active usernamewhoamiwhoamiDisplays the username associated with the current shell session
cdChange the current directorycd directory_pathcd my_folderChanges the shell's current working directory

Commands and the current working directory

CommandBehavior without a path or nameBehavior with an argument
lsLists the current working directoryLists the directory identified by the supplied path
mkdirNot valid because a directory name is requiredCreates the named directory relative to the current location, or at the supplied path
cdDoes not move to a specific named directory; use a valid directory path for targeted navigationChanges to the directory identified by the supplied path

Troubleshooting common problems

The directory created with mkdir does not appear

The command may have been run from a different current working directory than expected. Run:

pwd
ls

pwd identifies the location, and ls inspects its contents.

cd does not enter the desired location

The directory name or path may be incorrect, or the target may not be a directory. Use ls to check the available names, then provide the correct directory path:

ls
cd correct_name

ls shows an unexpected directory

Running ls without a path lists the current working directory. Run pwd to check where you are, or pass the intended directory explicitly:

pwd
ls /path/to/inspect

echo displays words differently than expected

Text containing spaces should be grouped with quotation marks:

echo "example text"

whoami does not show a personal name

whoami reports the Linux account username, which can differ from a person's full or display name. Treat the result as the account identifier used by the shell.

Exam-relevant notes

  • pwd prints the full path of the current working directory.
  • ls lists directory contents. With no argument, it lists the current working directory.
  • mkdir creates a directory and requires a directory name or path.
  • cd changes the current working directory and requires a valid target path for specific navigation.
  • whoami displays the active Linux username, not the current directory.
  • echo displays supplied text; quotation marks are useful when the text contains spaces.
  • A relative command argument is interpreted from the current working directory unless an explicit path changes the target location.

For continued practice, review Essential Linux Commands and repeat the workflow from a known directory.