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
Enter
orReturn
. - The
Tab
key can be used for auto-completing file names or commands. Command (⌘)
(orCtrl
) +C
can be used to stop a running command.- The
up
anddown
arrow 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 Documents
to go to the Documents directory.
- Example:
-
cp
: Copies files or directories.- Example:
cp source.txt destination.txt
to 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 ls
to see the manual for thels
command.
- Example:
-
mkdir
: Creates a new directory.- Example:
mkdir NewFolder
to create a new folder named "NewFolder".
- Example:
-
mv
: Moves or renames files or directories.- Example:
mv oldname.txt newname.txt
to rename a file.
- Example:
-
pwd
: Displays the path of the current working directory.- Example:
pwd
- Example:
-
rm
: Removes files or directories.- Example:
rm file.txt
to remove a file named "file.txt".
- Example:
-
touch
: Creates a new, empty file.- Example:
touch newfile.txt
- Example: