Atsushi (@atsushi)

The "hacker" screen

Looks intimidating at first

Not really lol

End Goal:

1. Not be intimidated

2. Learn basic syntax

3. Be able to navigate around the file system

How to open Terminal:
Mac

How to open Terminal:
Windows

How to open Terminal:
Windows

https://repl.it/languages/bash

Early CLI

Designed to be used  for advanced users

GUI

Designed to be used  for EVERYONE

 

So what is it do?

CLI is like directly talking to your computer

both the GUI and CLI are ways you can interact with your computer

GUI

Your OS

Choose 1 of many pre-made instructions

CLI

Your OS

Describe specific instruction you want

Why learn CLI?

Faster

More powerful, expressive and precise

Easy to automate

Many useful tool (ex. git)

KEY IDEA

Everything within the shell happens in your file system!

Username

System Name

Current Location In a file system

Your command

 

Bash Syntax

  • doSomething how toFiles
  • doSomething how sourceFile destinationFile
  • doSomething how < inputFile > outputFile
  • doSomething how | doSomething how | doSomething how > outputFile

Lingo

= folder  Directory

= beginning ofcommand

$

= comment

#

= command

$ abc

= flag

$ abc -p

Lingo

= Current Directory

./

../

=  Directory one level up

=  Directory two level up

../../

= User Home Directory (/home/atsushi)

~/

= System Home Directory

/

doSomething

pwd

print working directory

$ pwd

doSomething how

ls

list files / dirs

$ ls
$ ls -1    # Show 1 per line
# Long format list 
# (permissions, ownership, size and modification date) 
# of all files:
$ ls -la

doSomething toFiles

cd

change directory

$ cd ~
$ cd ~/Downloads

doSomething toFiles

man

manual

$ man man
$ man pwd
$ man ls

also check out https://tldr.sh

doSomething how toFiles

mkdir

make directory

$ mkdir ex_dir  # Same as ./ex_dir
$ mkdir ../ex_dir
# Create dir recursively
$ mkdir -p ex_dir/dir1

doSomething how toFiles

rmdir

remove directory

$ rmdir ex_dir  # Same as ./ex_dir
$ rmdir ../ex_dir
# Create dir recursively
$ rmdir -p ex_dir/dir1

doSomething how toFiles

touch

create new file

$ touch ye.txt  # Same as ./ye.txt

# Set the times on a file to a specific date and time:
#   touch -t YYYYMMDDHHMM.SS filename
$ touch -t 201801010930.55 ye.txt

doSomething how toFiles

echo

print

$ echo "Hello World"
# Print the variable $HOSTNAME
$ echo $HOSTNAME
# sidenote: define varibale with export
$ export TEST_BOI=10

Chaining commands

echo "xyz" > output.txt

print the text to the output file

echo "yes" && echo "no"

Pass the output of one command to another for further processing

ls -la | grep ye.txt

print "yes" and then "no"

doSomething how sourceFile destinationFile

 

mv

move file

# Move ye.txt one level up
$ mv ye.txt ../
# Rename file
$ mv ye.txt kanye.txt
# Vervose move (print result)
$ mv -v kanye.txt ~

sudo doSomething

 

sudo

do something in super user privilage

# Create file & set high privilate
$ touch ye.txt && chmod 000 ye.txt
# Try to print the content of the file
$ cat ye.txt  # ERROR
# Print file with super user privilage
$ sudo cat ye.txt

Bonus

code / atom / <editor_name>

open file / dir in your

# "code" is for Visual Studio Code
# Open 1 file
$ code ye.txt
# Open a whole directory
$ code .
# Open a whole directory in atom
$ atom .

YOU DID IT

Resources

https://code.ubyssey.ca/resources

Intro to CLI

By Atsushi Yamamoto

Intro to CLI

Intro to Command Line Interface

  • 1,277