Skip to content
X

Basic Terminal Commands

Here you will learn the terminal commands engineers use every day. You do not need to memorize everything at once. Learn them little by little as you use them.

CommandMeaningMain Use
pwdShow current locationpwd
lsList files and foldersls, ls -la
cdChange directoriescd Documents, cd .., cd ~
mkdirCreate a foldermkdir my-project
touchCreate a filetouch index.html
rmDelete files or foldersrm file.txt, rm -rf folder/
cpCopy files or folderscp a.txt b.txt
mvMove or rename files or foldersmv old.txt new.txt
catShow file contentscat README.md
open .Open the current folder in Finderopen .
clearClear the screenclear or Ctrl + L

Short for Print Working Directory. It shows the path of the folder you are currently working in.

pwd

The output looks like this:

/Users/username

It is the first command to run when you get lost.


Short for List. It shows the contents of the current folder.

ls

Add the -la option to show hidden files and detailed information.

ls -la
total 48
drwxr-xr-x   8 username  staff   256 Mar 21 10:00 .
drwxr-xr-x  12 username  staff   384 Mar 20 09:00 ..
-rw-r--r--   1 username  staff  1234 Mar 21 10:00 README.md
drwxr-xr-x   5 username  staff   160 Mar 21 10:00 src

Files and folders that start with . are hidden files. They do not appear in normal ls output, but you can see them with -la.


Short for Change Directory. Use it to switch the folder you are working in.

# Move to your home folder
cd ~

# Move to the Documents folder
cd Documents

# Move up one folder
cd ..

# Move up two folders
cd ../..

# Move by specifying the full path
cd /Users/username/Documents/my-project

Tip: While typing a folder name after cd, press Tab to auto-complete it.


Short for Make Directory. It creates a new folder.

mkdir my-project

Use the -p option to create missing parent folders at the same time.

mkdir -p my-project/src/components

Creates an empty file.

touch index.html
touch README.md
touch .env

Short for Remove. It deletes files.

# Delete a file
rm old-file.txt

Use the -rf option to delete a folder and everything inside it.

rm -rf old-folder/

Warning: Files deleted with rm -rf do not go to the Trash. They are deleted immediately and permanently. Always check the target before running it. Never run rm -rf / or rm -rf ~/.


Short for Copy.

# Copy a file
cp README.md README.md.backup

# Copy a folder (`-r` is required)
cp -r src/ src-backup/

Short for Move. It is used for both moving and renaming.

# Move a file to another folder
mv index.html src/index.html

# Rename a file
mv old-name.txt new-name.txt

Short for Concatenate. It prints the contents of a file in the terminal.

cat README.md
cat package.json

Opens the current folder in Finder, which is useful when switching between the terminal and the GUI.

open .

You can also open a specific file with its default app:

open index.html

Clears the terminal screen. It only hides old commands; it does not delete your work.

clear

You can also use Ctrl + L for the same effect.


If you type part of a command or file name and press Tab, the terminal auto-completes it.

cd Doc[Tab]
# -> completes to cd Documents/

If multiple candidates exist, press Tab again to see the list.

Use the Up and Down Arrow Keys to Access History

Section titled “Use the Up and Down Arrow Keys to Access History”

Pressing shows the last command you ran. It saves you from retyping commands you want to repeat.

↑  # one command back
↑  # two commands back
↓  # one command forward

Practice: Create a Project Folder and Files

Section titled “Practice: Create a Project Folder and Files”

Follow these steps to create a project folder with commands.

# 1. Move to your home folder
cd ~

# 2. Check where you are
pwd
# -> /Users/username

# 3. Move to the Documents folder
cd Documents

# 4. Create a project folder
mkdir my-first-project

# 5. Move into the folder you created
cd my-first-project

# 6. Check the folder contents (it should be empty)
ls

# 7. Create files
touch index.html
touch README.md

# 8. Confirm the files were created
ls
# -> index.html  README.md

# 9. Write text into README.md
echo "# My First Project" > README.md

# 10. Check the contents
cat README.md
# -> # My First Project

# 11. Open it in Finder
open .

The folder does not exist or the name is misspelled.

# Bad: typo
cd Docuemnts

# Good: use Tab completion
cd Doc[Tab]

You do not have permission to access that file or folder. You may be trying to operate on a system file. In normal learning work, staying inside your home folder (~/) usually avoids this error.

Press Ctrl + C to stop the current command. Use it when the terminal appears frozen.

Check your current location with pwd, then return to the home folder with cd ~ and move to the correct folder again.


Next: Homebrew Installation