Command Line [Mac]

File Navigation

1. Show the current directory.
pwd
2. List the files in the current directory.
ls
3. List the files in the home directory.
ls ~
4. List the files including hidden files.
ls -a
5. Go up a directory.
cd ..
6. Go two directory levels up.
cd ../../
7. Change directory to dir1.
cd dir1
8. Change to home directory.
cd
9. Open the file file1.
open file1
10. Open the working directory.
open .
11. Output the contents of the file file1.
cat file1
12. Find all the files named <file> inside the directory <dir>.
find <dir> -name <file>

File and Directory Management

1. Create a new file file1.
touch file1
2. Create two new file file1 and file2.
touch file1, file2
3. Copy the file file1 and name the copied file file2.
cp file1 file2
4. Copy the file file1 to a directory dir2.
cp file1 dir2
5. Remove the file file1.
rm file1
6. Rename the file file1 to file2.
mv file1 file2
7. Create a new directory dir1.
mkdir dir1
8. Copy a directory dir1 and name the copied directory dir2.
cp -r dir1 dir2
9. Remove the empty directory dir1.
rmdir dir1
10. Remove the non empty directory dir1.
rm -rf dir1

Other Useful Commands

1. Execute the last command typed.
!!
2. Scrolls up the commands entered previously.
Up Arrow
3. Scrolls up the commands entered previously.
Down Arrow
4. Moves the cursor to the start of the line.
Ctrl + a
5. Moves the cursor to the end of the line.
Ctrl + e
6. Moves the cursor one word forward.
Option + Right Arrow
7. Moves the cursor one word backward.
Option + Left Arrow
8. Clears the screen.
Ctrl + l
9. Removes all the previous commands and their output.
clear
10. Stop or Terminate the programming from running.
Ctrl + c
11. Deletes one word using white space as delimiter.
Ctrl + w
12. Open activity monitor.
top

Useful resources to learn Command Line:

Last updated on 20 Jan 2024