What is the Command Line Interface (CLI)?
Nearly every computer comes with a CLI
- Windows: Git Bash
- Mac/Linux: Terminal
The CLI can help you:
- navigate folders
- create/edit files, folders and programs
- run computer programs
Basics of Directories
- 'directory' is just another name for a folder
- directories on your computer are organized like a tree
- directories can be inside other directories
- we can navigate directories using the CLI
Special directories: root
- directory at the top of the tree
- contains all other directories
- represented by a slash: /
Special directories: home
- represented by a tilde: ~
- usually contains most of your personal files, pics, music, etc.
- name of the directory is usually the name you use to log into your computer
CLI Basics
- when you open up the CLI, you start in your home directory
- whatever directory you're in is called the 'working directory'
- this is also represented by the `pwd` command: print working directory
- the path to your working directory is traced from your root directory to your pwd
CLI Commands
- CLI commands follow this recipe: command flags arguments
- command - the CLI command which does the specific task
- flags - options we give to the command to trigger certain behaviors, preceded by a -
- arguments - can be what the command is going to modify, or other options for the command
Depending on the command, there can be zero or more flags and arguments
clear will clear out the commands in your current CLI window
ls lists files and folders in the current directory
ls -a lists hidden and unhidden files and folders
ls -la lists details for hidden and unhidden files and folders
cd stands for 'change directory'
- takes as an argument the directory you want to visit
- with no argument, it takes you to your home directory
- with .., it allows you to change to the directory above your pwd
mkdir stands for 'make directory'
- takes as an argument the name of the directory you want to create
touch creates an empty file
- takes as an argument the name of the file you want to create
cp stands for 'copy' and takes two arguments
- first argument: a file
- second argument: the path to where you want the file to be copied
- can also be used to copy the contents of directories with the -r flag
rm stands for 'remove'
- takes the name of a file you wish to remove as its argument
- you can remove all the files in a directory using the -r flag
mv stands for 'move'
- with mv, you can move files between directories
- you can also use it to rename files
echo will print whatever arguments you provide
- useful for printing out stored variable values
date will print the date