useful unix commands
A command line interface (CLI) is a text-based interface where you can input commands that interact with a computer’s operating system. A Unix shell provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting language, and is used by the operating sustem to control the execution of the system using shell scripts.
This tutorial will walk you through some Unix shell commands that will be useful to know as you progress on your coding journey. This guide is not an exhaustive list.
table of contents
how to execute a unix shell command
how to execute a unix shell command
A Unix shell command can be executed through a CLI application running a Unix shell instance, or it can be executed as part of a Unix shell script.
There are many Unix shell programs available to developers, including Bash and Z shell. To access a Unix shell on a Windows machine, follow these steps to install Git and GitBash. GitBash will be your Unix shell application. To access a Unix shell on a macOS machine, open the Terminal application. You can find the Terminal application in your Applications
folder on your computer or by searching for “Terminal” in the Spotlight Search.
Once you have opened the CLI application, type the command and press ENTER
or RETURN
to execute it. Some commands will print text as a part of their execution, and some will not. An error message will usually be printed if something has gone wrong during the program execution or if the command and its arguments were not structured properly.
A guide on how to create and run a Unix shell script is coming soon!
commands
print working directory
pwd
The pwd
command prints the absolute file path of your current location in the shell. Your current location will correspond to some folder in your computer’s file system.
print your username
whoami
The whoami
command prints your username. This can be useful to check your username when you are connected to a remote server.
list the directory contents
ls
The ls
command prints all the visible files and folders in our working directory.
ls -l
When we add the -l
flag to the ls
command, the visible files and folders will be printed in a long list format.
ls -a
When we add the -a
flag to the ls
command, the command will list all the files and folders in our working directory, including hidden files and folders.
Hidden files and folders will always have a name that begins with .
(e.g. .bash_profile
).
ls -al
When we add both the -a
and -l
flags to the ls
command, the command will list all files in our working directory, including hidden files, in a long list format.
ls DIRECTORY_PATH_HERE
We can use the ls
command to print the contents of a different directory by providing the absolute or relative path to the directory.
Additional information about paths can be found in the absolute and relative paths guide.
clear the shell window
clear
The clear
command will clear the shell window.
change the working directory
cd DIRECTORY_PATH_HERE
The cd
command will change the working directory to the directory with the given absolute or relative path.
Additional information about paths can be found in the absolute and relative paths guide.
unix shell shortcuts
resources and references
This tutorial was last updated on Thursday, May 15, 2025.