Skip to content

Basic Commands

Let's get going. Open a terminal window. In MacOS you can hit Cmd + Space and type Terminal to open it. In Windows you can hit Win + R and type cmd to open the command prompt.

List all files in the current directory

Bash
ls
ls -al # -a shows hidden files, -l shows long format with permissions
Bash
dir

Change directories

Bash
1
2
3
cd path/to/directory
cd .. # Move up one directory
cd ~ # Move to home directory
Bash
1
2
3
cd path\to\directory
cd .. # Move up one directory
cd %HOMEPATH% # Move to home directory

What is the home directory and where is it located?

The home directory is represented by ~ in MacOS and Linux. For example, /Users/username in MacOS and /home/username in Linux. In Linux, if you are using the root user, the home directory is /root.

File and Directory Operations

Create a new directory

Bash
mkdir new_directory
Bash
mkdir new_directory

Deleting files and directories

Bash
rm file.txt # Delete a file
rm -r directory # Delete a directory and its contents
Bash
del file.txt # Delete a file
rmdir /s directory # Delete a directory and its contents

Copying files and directories

Bash
cp file.txt new_file.txt # Copy a file
cp -r directory new_directory # Copy a directory and its contents
Bash
copy file.txt new_file.txt # Copy a file
xcopy /s directory new_directory # Copy a directory and its contents

Moving files and directories

Bash
mv file.txt new_directory # Move a file
mv directory new_directory # Move a directory
Bash
move file.txt new_directory # Move a file
move directory new_directory # Move a directory

Viewing file contents

Bash
cat file.txt # View the contents of a file
Bash
type file.txt # View the contents of a file

Editing text files

Bash
nano file.txt # Edit a file in the terminal
Bash
notepad file.txt # Edit a file in Notepad

Tips

Autocomplete file names

Press Tab to autocomplete file names in the terminal.

Clear the terminal

Bash
clear
Bash
cls

You can also use Ctrl + L to clear the terminal.

Previous commands

Use the up and down arrow keys to navigate through previous commands.

Manual pages

Use the man command to view the manual pages for a command.

Bash
man ls # View the manual page for the ls command

Windows does not have a built-in manual page viewer. You can use the /? option with commands to view help.

Bash
dir /? # View help for the dir command