But First ...



But First ...

1 0


CommandLine

Kansas City Women in Technology's Coding & Cocktails presentation on Command Line.

On Github KansasCityWomeninTechnology / CommandLine

Intro to Command Line

Slides available at: http://kansascitywomenintechnology.github.io/CommandLine

Last Month

In January we learned about HTML & CSS. We covered:

  • HTML & CSS Basics
  • Best Practices
  • Troubleshooting

What we'll cover

  • What is the command line?
  • What is the command line used for?
  • Common Commands & Practice
Common Commands for moving around the filesystem, creating and deleting files, etc.

But First ...

Inspiring Female Developers

Katrina Owen

Exercism.io

exercism.io

  • Katrina accidently became a developer while pursuing a degree in molecular biology.
  • She is a backend web developer (ruby)
  • Created open source education at exercism.io
  • exercism allows you to work in your local dev environment, get feedback from other learners, see how others solved the exercise.

Miral Kotb

iluminate

iluminate.com

  • Miral combined her passions for dance and computers to create an entertainment experience.
  • She studied COmputer Science at Columbia University while studying dance at Barnard College.
  • Had a vision of dancers wearing costumes that illuminated wirelessly and complimented the music and coreography
  • Showed on America's Got Talent

What is the Command Line?

Text-based interface to interact with your computer

Enter input and return output

  • Windows typically uses explorer, finder in mac for a visual interaction
  • Different way to interact with computer
  • enter commands and computer responds with output

What do I use the command line for?

  • Navigate the filesystem
  • Run Programs
  • Combine Commands
  • Automate Common Tasks
  • Git
  • Scaffolding Projects
  • Deployment
  • Utilizing Vagrant Environments
  • Installing Programs
  • Filesystem refers to folders and files on your computer
  • What you typically call a folder I'll refer to as a directory
  • The filesystem is laid out in heirarchical structure - parent and child directories
  • scaffolding - quick set up of app "skeleton"
  • Vagrant - quickly set up development environments - type of machine and software - Ask if Jennifer has anything to add about it!!!
  • NOTE: Job interviews will ask about CL, most places have command line based build processes.
  • Developers often develop tools for other developers to make development easier... sometimes don't have time or skill to create full GUI environments as these are usually time consuming and require different skill set so will create command line based processes so knowing this tool will be helpful
  • Npm, bower, webpack, etc

How do I use the Command Line?

Tools:

Navigating the filesystem

Examples:

  • pwd - print working directory
  • cd - change directory
  • ls - list directory contents

Try it!

pwd

ls

cd Documents

HELP! I don't know what I'm doing!

hint: check the online man pages or type "man ls"

    • -l displays:
    • permissions,
    • number of links (number of child directories and files, includes parent and current),
    • owner name,
    • group name,
    • bytes in file,
    • date modified,
    • file name
  • what if you don't know bytes conversions?
  • Exit man pages with q, navigate with space for next page, enter for more, arrows

Shortcuts:

  • Current Directory:
  • Parent Directory:
  • Home Directory:
  • Root Directory:
  • History:
  • Previous Command:
  • Previous Command:
  • Tab completion
  • .
  • ..
  • ~
  • /
  • history
  • !!
  • home directory contains files for user
  • root directory is highest level directory
  • handy to know for relative path - these don't include the full path and assume file is on current server (ie. session.html vs http://codingandcocktails.kcwomenintech.org/sessions

File Permissions

  • chown - Change file owner
  • chmod - Permissions are set according to numbers.
    • 0 = no permissions; cannot read, write, or execute the file
    • 1 = execute only
    • 2 = write only
    • 3 = write and execute (1+2)
    • 4 = read only
    • 5 = read and execute (4+1)
    • 6 = read and write (4+2)
    • 7 = read and write and execute (4+2+1)
owner group world Read = 4, write = 2, execute = 1, others are combinations. chmod = change file modes chown example: chown newuser filename.txt user:group file

More Commands

Create a new directory

Try it!

cd ~

mkdir CodingAndCocktails

ls

make sure we have windows explorer or mac finder open!!!

Create a new file

Try it!

cd CodingAndCocktails

touch myNewFile.txt

ls

Write content to a file

Try it!

  • echo "Old Fashioned
  • Martini
  • Mai Tai
  • Whiskey Sour
  • Cosmopolitan
  • Margarita" > myCocktailList.txt
talk about exiting stuck command with ctrl-c here

Copy a file

cp sourceFile destinationFile

Try it!

cp myCocktailList.txt newCocktails.txt

ls

Rename or move a file

mv /path/to/sourceFile /path/to/destinationFile

Try renaming!

mv newCocktails.txt renameCocktails.txt

ls

Remove a file

Try it!

rm renameCocktails.txt

ls

View a file

cat to view entire file

tail -n to view the last n lines

head -n to view the first n lines

Try it!

cat myCocktailList.txt

tail -2 myCocktailList.txt

head -2 myCocktailList.txt

tail shows: Cosmopolitan, Margarita head shows: Old Fashioned, Martini

Search for a text string

grep - global regular expression print

Try it!

grep Mar myCocktailList.txt

grep shows Margarita & Martini

Search for files

find

Try it!

find . –name "*.txt" –mtime 5

Input and Output

  • Stdin:
  • Stdout (redirect):
  • Stdout (append):
  • Stderr
  • Pipe:
  • <
  • >
  • >>
  •  
  • |
  • Stdin: data going IN to a program (typically coming from keyboard)
  • Stdout (file descriptor/indicator to access file: 1): data coming OUT of a program (typically terminal that started program)
  • Stderr (2): error data coming OUT of a program (normal to be put in same as stdout 2>&1)

Try it!

grep Mar myCocktailList.txt | wc -w

echo "Bloody Mary" >> myCocktailList.txt

cat myCocktailList.txt

Additional Topics

Editing files in the command line

  • vi
  • vim
  • nano
  • emacs

Running Scheduled Tasks with Cron Jobs

added by editing the cron file

specify the schedule you want to run on and the script or command you want to run

* * * * * command to be executed
| | | | |_ day of week (0 - 6, 0 = Sunday) 
| | | |___ month (1 - 12)
| | |_____ day of month (1 - 31)   
| |_______ hour (0 - 23) 
|_________ minute (0 - 59)
Your browser does not support the video tag.

Review

  • What is the command line?
  • What the command line is used for
  • Command line tools
  • Filesystem navigation
  • Useful commands
  • Input & Output

Questions?

?

Thank You!

Keep in touch!

Join us March 12 for an Introduction to Git Github & Version Control!