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 argumentFor 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.”
pwdExample output might look like this:
/home/alexThe 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:
lsIf the current directory contains a file named notes.txt and a directory named projects, the output could be:
notes.txt projectsList a different directory
Give ls a directory path to inspect a location other than the current directory:
ls /home/alex/projectsBecause 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_folderVerify that the directory exists by listing the current directory:
lsYou 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 HelloOutput:
HelloWhen 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, Linuxecho 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:
whoamiExample output:
alexA 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_folderConfirm the change with pwd:
pwdIf the original location was /home/alex, the result should now be:
/home/alex/my_folderA 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/projectsAfter 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
pwdA 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_folderThe 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
| Command | Purpose | Basic syntax | Example | What it affects or displays |
|---|---|---|---|---|
ls | List directory contents | ls [path] | ls | Displays files and directories; without a path, uses the current directory |
pwd | Print the current working directory | pwd | pwd | Displays the full path of the current directory |
mkdir | Create a directory | mkdir directory_name | mkdir my_folder | Creates a directory in the current location unless a path is supplied |
echo | Display text | echo text | echo "Hello, Linux" | Writes the supplied text to the terminal |
whoami | Display the active username | whoami | whoami | Displays the username associated with the current shell session |
cd | Change the current directory | cd directory_path | cd my_folder | Changes the shell's current working directory |
Commands and the current working directory
| Command | Behavior without a path or name | Behavior with an argument |
|---|---|---|
ls | Lists the current working directory | Lists the directory identified by the supplied path |
mkdir | Not valid because a directory name is required | Creates the named directory relative to the current location, or at the supplied path |
cd | Does not move to a specific named directory; use a valid directory path for targeted navigation | Changes 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
lspwd 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_namels 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/inspectecho 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
pwdprints the full path of the current working directory.lslists directory contents. With no argument, it lists the current working directory.mkdircreates a directory and requires a directory name or path.cdchanges the current working directory and requires a valid target path for specific navigation.whoamidisplays the active Linux username, not the current directory.echodisplays 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.