CLI
1. Navigation and Exploring the system 1
pwd-Show working directory / where you are 1
ls-Listing directory contents 1
less-View file contents 2
cd-Change Directory for navigating 2
touch create a file 2
2. Manipulating files and directories 2
wildcards 2
mkdir-Creating directories 2
cp-Copy files and directories 2
mv-Move and rename files/directories 3
rm-Removing files/directories 3
3. Opening a macOS program 3
4. Nano 3
1. Navigation and Exploring the system
pwd-Show working directory / where you are
● show working directory pwd
● cd ~ takes you home
ls-Listing directory contents
● show directory contents: ls
● show directory contents including hidden files: ls -a
● show directory contents in a list: ls -l
● determine a files file type: file filename
less-View file contents
● view contents: less <filename>
● in less scroll using up and down keys or pageup and pagedown
● in less scroll to end ```G```
● in less scroll to beginning ```g```
● leave less, when at the end of the file ```q```
cd-Change Directory for navigating
● go up / change directory cd <directoryname>
● go down cd ..
● go home cd ~
touch create a file
● create a file touch filename
● create multiple files touch file1 file2 file3
2. Manipulating files and directories
wildcards
● * matches any characters
● ? matches any single character
● [characters] matches any character that is a member of the set of characters
mkdir-Creating directories
● create a directory mkdir dir
● create multiple directories mkdir dir1 dir2 dir3
cp-Copy files and directories
● copy a file: cp item1 item2
● copy a file into a directory: cp file directoryname
● copy all files from dir1 into dir2, dir 2 must already exist: cp dir1/* dir2
● copy all files from dir1 into dir2, dir2 doesn't have to exist yet: cp -r dir1 dir2
● copy a file from a directory to the current directory: cp /etc/passwd .
● notice how we use the single trailing period as a shorthand for the current working
directory
mv-Move and rename files/directories
● mv performs both moving and renaming... after execution, the original filename no longer
exists: mv item1 item2
● useful: ”-i” => prompt for user confirmation
rm-Removing files/directories
● remove a directory -> needs to be done recursively (-r): rm -r <directory name>
● remove a file: rm <filename>
● remove multiple files: rm file1 file2
● remove multiple files using wildcard e.g. when the first 4 letters are the same: rm file*
● useful: ”-i” => prompt for user confirmation
Note: be careful with rm, the cli doesn't have an undo command!!!. Be especially in combination
with wildcards like *. Using rm * will remove all files in a directory.
Whenever you use wildcards, try `ls` first to see the selection... then rm...
3. Opening a macOS program
● open a program (look for the program anywhere on the mac -> -a => open -a
"program name": `$ open -a music`
● Add -g to keep the application in the background, so you remain centered in Termina
lopen -g -a iTunes
● open a file with a certain program e.g. macdown
○ generic: open "filename" -a "program name"
○ example: open djangocheatsheet.md -a macdown
4. Nano
**TIP+ in nano ^ means CTRL!!!**
CTRL+o => save changes
CTRL+x => exit
<!--stackedit_data:
eyJoaXN0b3J5IjpbLTE1MTkzOTg3ODcsNDAyMzI2NzEwXX0=
→
5. Other
export and echo
export => shows all your environment variables that are available to your programs
echo $PATH => shows which programs are available in path
which
shows which program you are running
which python3
/usr/local/bin/python3