Getting Started With the Terminal

Table of Contents

Before Starting

The root directory is “/” and inside of “/”, you have the following folders: bin, tmp, usr, and src.

Opening Your Terminal

Important Notes

Tab auto-completion.
Arrow key functionality.

Commands

pwd — print working directory

pwd
Currently in the “/Users/alanconstantino” directory.

ls — list

ls
By typing ls, we can see all of the files and directories within the current directory.
ls [directory name]
We list all the files and folders inside of the “Desktop” directory.
ls -a
Listing hidden files with the “-a” option.

cd — change directory

cd [directory name]
cd /
“cd /” changes your current directory to your root directory.
cd ~
We are now in the home directory.
cd ..
Changed directory from “/Users/alanconstantino/Desktop” to “/Users/alanconstantino.”
cd ../../
cd ../../../
cd -
/Users/alanconstantino/Desktop/
/Users/alanconstantino/Desktop/myFolder/anotherFolder/
/Users/alanconstantino/Desktop/
/Users/alanconstantino/Desktop/myFolder/anotherFolder/

clear

clear
Clearing the terminal.

mv — move

mv [source] [destination]
one
├── myfile.txt
└── two
mv myfile.txt two
We moved “myfile.txt” to the folder “two.”
We moved “anotherfile.txt” to the “two” folder while in the root directory.
mv /somelocation/myfile.txt .
mv [old file name] [new file name]
mv myfile.txt newname.txt

cp — copy

cp [source] [destination]
cp myfile.txt /one
We copied “myfile.txt” to the “one” folder.
cp -r one two
We copy the contents of the “one” directory into the “two” directory.

open

open [file/folder]
open myfile.txt
We open a file named “myfile.txt.”
open /
We opened a new finder window at the root directory.
A finder window showing the contents of the root directory.
open .

mkdir — make directory

mkdir [directory name]
We made a directory named “mydirectory.”
We created two directories, one named “newdirectory” and another named “anotherdirectory.”

touch

touch [file name]
touch myfile.txt
We create a file named “myfile.txt.”
We create “myfile.txt” in the current directory and “anotherone.txt” in the previous directory.

rmdir — remove directory

rmdir [directory name]
We are deleting an empty directory named “emptydir.”
We failed at removing the directory “folder” because it’s not empty.

rm — remove

rm [file name]
rm myfile.txt
We removed a file named “myfile.txt.”
rm [file1] [file2] [etc]
We delete “afile.txt” and “anotherone.txt”
rm *.txt
We delete various .txt files.
[command] [options] [other paramters]

rm -r

rm -r [directory]
newfolder
├── folder1
│ └── text1.txt
├── folder2
│ └── text2.txt
└── folder3
└── text3.txt
rm -r newfolder
We delete all of the contents of the “newfolder” directory including the folder itself.

rm -f

rm -f [file/directory]

rm -rf

rm -rf [directory]
anotherfolder
└── myfolder
├── folder1
│ └── file1.txt
├── folder2
│ └── file2.txt
├── folder3
│ └── file3.txt
└── folder4
└── file4.txt
rm -rf myfolder
We remove all the contents of “myfolder” including the folder itself.

man — manual

man [command name]
man mv
The functionality for the mv command.
The options associated with the mv command.

Recap

  • pwd — prints the current working directory
pwd
  • ls — lists all the contents of the current directory
ls
  • cd — changes directory
cd [directory name]
  • clear — clears the terminal screen
clear
  • mv — moves files or folders from one place to another and can rename files or folders
mv [source] [destination]
  • cp — copies files or folders from one place to another
cp [source] [destination]
  • open — opens the file or folder with the associated program
open [file/directory]
  • mkdir — makes a new empty directory
mkdir [directory name]
  • touch — creates a new empty file with the name of your choice and can update a file’s timestamps
touch [file name]
  • rmdir — removes an empty directory
rmdir [empty directory]
  • rm — removes a file
rm [file name]
  • rm -rf — removes the folder and its contents without showing any prompts
rm -rf [directory name]
  • man — brings up the manual for the given command
man [command name]

Where to Go From Here?

  • cat — concatenates and prints files to the terminal
  • less — displays contents of a file
  • grep — searches files for a certain word or regular expression
  • ls -l — lists files in long format
  • kill — can terminate a signal or process
  • chmod — allows you to change or modify access permissions of a file or folder
  • sudo — a prefix that allows you to run commands as a superuser with root privileges
  • mkdir -p — you can create multiple directories within the same path
  • w — tells you who’s logged in and what they’re doing

--

--

--

Web developer https://github.com/AlanConstantino

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Elevate your docC Documentation in Xcode

Monitoring VMware clusters using Prometheus and Grafana

Redirect the Output of PowerShell Commands

Best Resources For Passing The AWS Developer Associate Exam

Rule Engine Pattern

State of DevOps 2019 — my own TL;DR

Deploying secure MLflow on AWS

Why trading is important?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alan Constantino

Alan Constantino

Web developer https://github.com/AlanConstantino

More from Medium

Tips and Tricks around Sitecore Certifications

Writing Clean Code

How to begin your Web developer journey? (Tech prep)

Popular Backend Frameworks in 2022: What Are They and Which One to Choose