Command Line Crash Course¶
The command line is just a way to manually enter text commands in an application called a terminal. Instead of clicking on icons or using a graphical interface, you type commands into the terminal and receive text responses. This can be a powerful way to perform tasks, especially for tasks that don't have a graphical interface.
- To execute a command, type it in the terminal application and press
EnterorReturn. - The
Tabkey can be used for auto-completing file names or commands. Command (⌘)(orCtrl) +Ccan be used to stop a running command.- The
upanddownarrow keys allow you to cycle through your previously used commands.
IMPORTANT: The commands below are specific to MacOS and other Unix-based systems. Commands on Windows differ slightly than Unix-based systems; for a quick Windows-specific command line tutorial, see this one.
The most common commands you'll use are:
-
cat: Displays the content of a file or concatenates multiple files.- Example:
cat file.txt
- Example:
-
cd: Changes the current directory.- Example:
cd Documentsto go to the Documents directory.
- Example:
-
cp: Copies files or directories.- Example:
cp source.txt destination.txtto copy source.txt to destination.txt.
- Example:
-
ls: Lists all files and directories in the current directory.- Example:
ls
- Example:
-
man: Displays the manual page for other commands.- Example:
man lsto see the manual for thelscommand.
- Example:
-
mkdir: Creates a new directory.- Example:
mkdir NewFolderto create a new folder named "NewFolder".
- Example:
-
mv: Moves or renames files or directories.- Example:
mv oldname.txt newname.txtto rename a file.
- Example:
-
pwd: Displays the path of the current working directory.- Example:
pwd
- Example:
-
rm: Removes files or directories.- Example:
rm file.txtto remove a file named "file.txt".
- Example:
-
touch: Creates a new, empty file.- Example:
touch newfile.txt
- Example: