SlideShare ist ein Scribd-Unternehmen logo
1 von 70
Downloaden Sie, um offline zu lesen
COMMAND LINE FOR
THE BEGINNER
USING THE COMMAND LINE IN DEVELOPING
FOR THE WEB
Created by Jim Birch
jimbir.ch/cmd
@thejimbirch
Xeno Media, Inc.
DEVELOPERS BE ALL LIKE...
Source
WHAT IS THE
COMMAND LINE?
A command-line interface ... is a
means of interacting with a
computer program where the user
(or client) issues commands to the
program in the form of successive
lines of text (command lines). -
Wikipedia
OFTEN REFERRED TO AS CLI
C - Command
L - Line
I - Interface
WHERE IS THIS COMMAND LINE?
Linux - Built in
Mac - Terminal built in or additional apps like
available.
Windows - , or the brand new
iTerm
Cygwin Bash on Ubuntu on
Windows
Chromebook - Apps that provide limited functionality
WHAT DOES THE TERMINAL LOOK LIKE?
CUSTOMIZE MOST TERMINAL APPS
THE COMMANDS
ANATOMY OF A COMMAND
$ command -flag argument/operand
command - The action we want to happen
flag (optional) - Options for the command
operand (optional) - What is acted upon
Most of the time you find commands written, they will be
prefaced with a $
COMMON COMMANDS
cd - Change Directory
$ cd /path/to/folder
$ cd ../../../to move up the tree.
cp - Copy
$ cp wp-config-sample.php wp-config.php
grep - globally search a regular expression and print
$ grep term filetosearchin.txt
ls - List
$ ls -la(l = long format, a = all files, even hidden)
mkdir - Make Directory
$ mkdir directoryname
COMMON COMMANDS
mv - Move
$ mv wp-config.php ../
pwd - Print Working Directory
$ pwd
rm - Remove
$ rm -rf whatyouwantremoved
(r = recursive, f = force)
sudo - Superuser Do
$ sudo anycommand
(Use sudo if you need administrative access to run the command.)
touch - Touch
$ touch newfilename.txt
COMMON COMMANDS
If you enter a screen that has a page of information, like a
help screen:
Use your arrow keys to navigate up and down.
Type qto exit.
FLAGS
For most cases I have found, flags that are full words use two
dashes, flags that are acronyms use one dash.
--all
-a
ESCAPING
If you ever need to cancel a command:
Hold the Control key and C
ARCHIVING AND UNARCHIVING
Archive and compress; extract files
and folders quickly and easily right
from the command line.
ZIP AND UNZIP
To compress a folder using zip:
zip -r zip-file-name.zip path/to/folder
zip -r zip-file-name.zip file1 file2
file3
To extract:
unzip zip-file-name.zip
TAR AND UNTAR
To compress a folder using tar:
tar -zcvf tar-file-name.tar.gz
path/to/folder
To extract:
tar -zxvf tar-file-name.tar.gz
NANO AND VI EDITORS
nano and vi are text editors
available in terminal so you can edit
files without needing any other
programs.
NANO
nano file.txt to open a file
Control + (letter) for commands
Control + G for help
VI (OR VIM - "VI IMPROVED")
vi file.txt to open a file
:help for commands
:i to insert
:w to save
:q to exit
YOU HAVE SURVIVED THE BEGINNER LEVEL!
Source
SKIP TO END
CONNECTING TO SERVERS BY SSH
Connect to other servers, like your
staging and production
environments and run commands
as you would on your local
command line.
CREATING SSH KEYS
Check for existing keys
$ ls -al ~/.ssh
Create a new key
ssh-keygen -t rsa -C
"yourname@domain.com"
-t = Key Type, -C = Comment
Enter file in which to save the key
(/Users/Jim/.ssh/id_rsa):
/Users/Jim/.ssh/clientname
PUTTING YOUR KEY ON THE SERVER
UI Interfaces like CPanel and Plesk
Apache - Add your key to /%USER%/.etc/authorized_keys
nginx - Install openssh and add your key to
/%USER%/.ssh/authorized_keys
CONNECTING TO SERVER
ssh username@domain.name
Enter your password
SET UP AN SSH ALIAS
nano ~/.ssh/config
Host hostname
User usernameatserver
HostName (IP Address or domain.name)
Port 22
IdentityFile ~/.ssh/id_rsa
Then, connect with
ssh hostname
TO DISCONNECT FROM A SERVER:
Type exit
MYSQL
Manage MySQL databases from the
command line, including importing
and exporting.
CONNECTING TO MYSQL
mysql -u username -p
You will be prompted for password.
* Note: You want to avoid using the password inline, as it
would be available in logs
IMPORTING A DATABASE
mysql -u username -p < database.sql
EXPORTING A DATABASE
mysqldump -u username -p > database.sql
ONCE YOU HAVE CONNECTED TO MYSQL, YOU
CAN RUN ANY SQL COMMAND
CREATE TABLE newtablename (id INT NOT NULL
PRIMARY KEY AUTO_INCREMENT,
name_of_table VARCHAR(30),
sub_title VARCHAR(20),
yes_or_no CHAR(1),
date_of_thing DATE);
WP-CLI
WP-CLI is a set of command-line
tools for managing WordPress
installations. You can update
plugins, set up multisite installs and
much more, without using a web
browser. - wp-cli.org
COMMON WP-CLI COMMANDS
http://wp-cli.org/commands/
wp media regenerate
Regenerates all thumbnails
wp post list
List all the posts of a site
wp user delete 123 --reassign=567
Delete a user, and assign their posts to another.
wp plugin install hello-dolly
Installs Hello Dolly Plugin
COMMON WP-CLI COMMANDS
wp help
Lists all commands and help
wp core update
Updates Wordpress core
wp theme list
Lists all themes in the site
wp package
http://wp-cli.org/commands/package/
DRUSH
Drush is a command line shell and
Unix scripting interface for Drupal. -
drush.org
ALIASES
In computing, alias is a command in
various command line interpreters
(shells) ... which enables a
replacement of a word by another
string. - Wikipedia
ANATOMY OF AN ALIAS
name="command"
name - The name of the alias
command - The action we want to happen
WHERE TO PUT ALIASES
MAC OS
Temporary - alias name="command"
Permanent - nano ~/.bash_profile
WHERE TO PUT ALIASES
UBUNTU
Temporary - alias name="command"
Permanent - nano ~/.bash_aliases
WHERE TO PUT ALIASES
WINDOWS
Temporary - DOSKEY name="command"
Permanent - A lot more complicated!
COMMON USE CASES FOR ALIASES
Navigate to common folders
alias htdocs="cd /var/www/public_html"
alias backdropcms="cd
/Users/Jim/jim.local/backdropcms.org"
Run Common Tasks
alias restart='sudo apachectl restart'
COMMON USE CASES FOR ALIASES
Open Common Files
alias bashprofile='sudo nano
/Users/Jim/.bash_profile'
alias sshconfig='nano ~/.ssh/config'
Open Applications
alias github='open -a Firefox
https://github.com/thejimbirch?
tab=repositories'
COMMON USE CASES FOR ALIASES
Complex Example
Accepts a url, opens chrome in 5 different sized browsers
1
2
3
4
5
6
7
8
9
10
hosted with ❤ by
# My Chrome developer profile is in the `Profile 1` directory, make sure to update with yours.
# Best on an ultra wide monitor.
function rwdurl() {
open -n -g -a "Google Chrome" --args --new-window --profile-directory=Profile 1 --app="data:text/html,<html><body><script>win
open -n -g -a "Google Chrome" --args --new-window --profile-directory=Profile 1 --app="data:text/html,<html><body><script>win
open -n -g -a "Google Chrome" --args --new-window --profile-directory=Profile 1 --app="data:text/html,<html><body><script>win
open -n -g -a "Google Chrome" --args --new-window --profile-directory=Profile 1 --app="data:text/html,<html><body><script>win
open -n -g -a "Google Chrome" --args --new-window --profile-directory=Profile 1 --app="data:text/html,<html><body><script>win
}
view rawrwdurl GitHub
SEE ALSO
ln -s /path/to/file /path/to/symlink
Example: htdocs > /var/www/public_html
Symbolic link (Symlinks)
SEE ALSO
Bash Scripts
1
2
3
4
5
6
7
8
hosted with ❤ by
fullpath=`pwd`
if [[ $fullpath =~
/Users/Jim/Sites/.* ]]; then
IFS='/' array=($fullpath)
open "http://${array[4]}.xenostaging.com"
else
echo You are not in a webroot.
fi
view rawssite bash script GitHub
SEE ALSO
BASH-IT
Bash-it is a collection of community Bash commands and
scripts. (And a shameless ripoff of oh-my-zsh :smiley:)
Includes autocompletion, themes, aliases, custom functions,
a few stolen pieces from Steve Losh, and more.
https://github.com/Bash-it/bash-it
SECURE COPY PROTOCOL (SCP)
Secure copy or SCP is a means of
securely transferring computer files
between a local host and a remote
host or between two remote hosts.
It is based on the Secure Shell (SSH)
protocol. - Wikipedia
COPY FILE FROM LOCAL TO SERVER
scp example.txt username@server:myfile.txt
COPY ALL FILES IN REMOTE SITE TO LOCAL
(FOLDER YOU ARE IN)
scp serveralias:/var/www/public_html/wp-uploads/* .
COPY FILES FROM ONE SERVER TO ANOTHER
scp serveralias:/var/www/public_html/wp-
content/files/file1.zip
secondserveralias:/var/www/public_html/wp-
content/files/file1.zip
YOU HAVE SURPASSED THE INTERMEDIATE
LEVEL WITH EASE!
Source
SKIP TO END
GIT FOR VERSION CONTROL
Git is a widely used source code
management system for so ware
development. It is a distributed
revision control system with an
emphasis on speed, data integrity,
and support for distributed, non-
linear workflows. - Wikipedia
GIT IN PLAIN ENGLISH
Git gives us a canonical/main source of the code of the
project.
Multiple versions can be checked out, and merged back
in.
History of commits/different versions can be saved.
Easily sync multiple servers, Development, Staging,
Productions.
REALLY GREAT GIT TUTORIAL
https://git-scm.com/docs/gittutorial
COMMON GIT COMMANDS
git clone repo.url
Clones a repository to your computer
git fetch
Gets updated code from repository
git merge origin/master
Merges code from repository, master branch
git pull
Fetch and merge in one step!
git checkout -b branchname
Makes a new branch
COMMON GIT COMMANDS
git diff filename
Shows the changes you have made to the file
git add -A
Adds all files to "staging area"
git commit
Moves from "staging area" to a commit
git push origin master
Pushes local master branch to origin master
git log
Lists history of commits
AUTOMATION/TASK RUNNERS LIKE
GRUNT AND GULP
FUTURE DEVELOPMENT WILL BE POWERED
BY JAVASCRIPT
Node.js® is a JavaScript runtime built that runs
NPM (Node Package Manager), the largest ecosystem of
open source libraries in the world
I use Node.js® to install NPM to install Grunt which installs...
TOOLS FOR OUR JAVASCRIPT FILES:
jshint - Detect errors and potential problems in your
JavaScript code.
jscs - Linter/formatter for programmatically enforcing
your style guide.
uglify - Minify files with UglifyJS
concat - Concatenate (merge) files into one.
TOOLS FOR OUR CSS FILES:
grunt-contrib-less, grunt-sass - Compile LESS/SASS files to
CSS
csslint - Checks syntax checking and applys a set of rules
that look for problematic patterns or signs of inefficiency.
cssmin - Minimizes CSS files
csscomb - Formats and sorts style sheets to make them
organized and consistent.
SO MANY USES:
imagemin - Minify images seamlessly.
copy - automate the copying of files or directories.
Thousands more... [ ] [ ]Grunt Plugins Gulp Plugins
WATCH!
Once these tasks have been assembled in a Gruntfile.js file,
you can run the following command to implement these
tasks on any changes:
grunt watch
Any JS/CSS/LESS/SASS files changed will be checked and
organized!
Images put in the folder I am watching will be minified.
Any errors will be reported immediately!
DEPENDENCY/PACKAGE MANAGERS
LIKE COMPOSER
Composer helps you declare,
manage and install dependencies of
PHP projects, ensuring you have the
right stack everywhere.
- Composer on Github
AN OVERARCHING MAINTAINER OF YOUR
WEBSITE AND IT'S NEEDS
A composer.json file defines all of the things your website
needs. These are called dependencies.
This would include Wordpress itself, plugins, and themes. It
could also include outside libraries like jQuery, Bootstrap,
Foundation, and more.
AN OVERARCHING MAINTAINER OF YOUR
WEBSITE AND IT'S NEEDS
A composer.json file defines all of the things your website
needs. These are called dependencies.
This would include Wordpress/Drupal core,
plugins/modules, and themes. It could also include outside
libraries like jQuery, Bootstrap, Foundation, Masonry, and
more.
REBUILD THIS PROJECT IN A MOMENT'S
NOTICE
If all dependencies are defined in a composer.json file,
composer installcould be run to install the site
anywhere.
All you would need to do then is setup the database and
move the files.
SUMMARY
BEGINNER
Command Line Basics
Commands and Flags
Archiving and Unarchiving
Command Line Editors
SUMMARY
INTERMEDIATE
Connecting to Servers with SSH
MySQL
WP-CLI / Drush
Aliases
Secure Copy Protocol - SCP
SUMMARY
ADVANCED
Git for Version Control
Automation/task runners like Grunt and Gulp
Dependency/Package Managers like Composer
NOW YOU CAN BE ALL LIKE...
Source
THE END
CONTINUING THE CONVERSATION:
Created by Jim Birch
jimbir.ch/cmd
@thejimbirch
Xeno Media, Inc.

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Install and configure linux
Install and configure linuxInstall and configure linux
Install and configure linux
 
ppt on cmd cammand
ppt on cmd cammandppt on cmd cammand
ppt on cmd cammand
 
Apache ppt
Apache pptApache ppt
Apache ppt
 
Powershell Demo Presentation
Powershell Demo PresentationPowershell Demo Presentation
Powershell Demo Presentation
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Vi editor
Vi editorVi editor
Vi editor
 
Virtual Machine
Virtual MachineVirtual Machine
Virtual Machine
 
Introduction to Linux basic
Introduction to Linux basicIntroduction to Linux basic
Introduction to Linux basic
 
Introduction to Ubuntu
Introduction to UbuntuIntroduction to Ubuntu
Introduction to Ubuntu
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Linux Troubleshooting
Linux TroubleshootingLinux Troubleshooting
Linux Troubleshooting
 
Shell Script Linux
Shell Script LinuxShell Script Linux
Shell Script Linux
 
Managing files and folder in windows 10
Managing files and folder in windows 10Managing files and folder in windows 10
Managing files and folder in windows 10
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Types Of Software
Types Of SoftwareTypes Of Software
Types Of Software
 
Linux Presentation
Linux PresentationLinux Presentation
Linux Presentation
 
Linux Introduction (Commands)
Linux Introduction (Commands)Linux Introduction (Commands)
Linux Introduction (Commands)
 
Linux basics
Linux basicsLinux basics
Linux basics
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
Red hat ppt
Red hat pptRed hat ppt
Red hat ppt
 

Andere mochten auch

14 working with the command line interface
14 working with the command line interface14 working with the command line interface
14 working with the command line interfacehafizhanif86
 
WEKA:The Command Line Interface
WEKA:The Command Line InterfaceWEKA:The Command Line Interface
WEKA:The Command Line Interfaceweka Content
 
Human computer interaction
Human computer interactionHuman computer interaction
Human computer interactionMayuresh Singh
 
Human Computer Interaction-Basics
Human Computer Interaction-BasicsHuman Computer Interaction-Basics
Human Computer Interaction-BasicsMuhammad Asif
 
Human-Computer Interaction
Human-Computer InteractionHuman-Computer Interaction
Human-Computer InteractionTarek Amr
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1PRN USM
 
Graphical User Interface
Graphical User Interface Graphical User Interface
Graphical User Interface Bivek Pakuwal
 
Introduction to HCI
Introduction to HCI Introduction to HCI
Introduction to HCI Deskala
 
Lecture 1: Human-Computer Interaction Introduction (2014)
Lecture 1: Human-Computer Interaction Introduction (2014)Lecture 1: Human-Computer Interaction Introduction (2014)
Lecture 1: Human-Computer Interaction Introduction (2014)Lora Aroyo
 
WEKA: The Command Line Interface
WEKA: The Command Line InterfaceWEKA: The Command Line Interface
WEKA: The Command Line InterfaceDataminingTools Inc
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)Bilal Amjad
 
human computer interface
human computer interfacehuman computer interface
human computer interfaceSantosh Kumar
 
Human computer interaction
Human  computer interactionHuman  computer interaction
Human computer interactionAyusha Patnaik
 

Andere mochten auch (15)

14 working with the command line interface
14 working with the command line interface14 working with the command line interface
14 working with the command line interface
 
WEKA:The Command Line Interface
WEKA:The Command Line InterfaceWEKA:The Command Line Interface
WEKA:The Command Line Interface
 
Command Line Interface
Command Line InterfaceCommand Line Interface
Command Line Interface
 
Human computer interaction
Human computer interactionHuman computer interaction
Human computer interaction
 
Human Computer Interaction-Basics
Human Computer Interaction-BasicsHuman Computer Interaction-Basics
Human Computer Interaction-Basics
 
Human-Computer Interaction
Human-Computer InteractionHuman-Computer Interaction
Human-Computer Interaction
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
 
Graphical User Interface
Graphical User Interface Graphical User Interface
Graphical User Interface
 
HCI Presentation
HCI PresentationHCI Presentation
HCI Presentation
 
Introduction to HCI
Introduction to HCI Introduction to HCI
Introduction to HCI
 
Lecture 1: Human-Computer Interaction Introduction (2014)
Lecture 1: Human-Computer Interaction Introduction (2014)Lecture 1: Human-Computer Interaction Introduction (2014)
Lecture 1: Human-Computer Interaction Introduction (2014)
 
WEKA: The Command Line Interface
WEKA: The Command Line InterfaceWEKA: The Command Line Interface
WEKA: The Command Line Interface
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)
 
human computer interface
human computer interfacehuman computer interface
human computer interface
 
Human computer interaction
Human  computer interactionHuman  computer interaction
Human computer interaction
 

Ähnlich wie Command line for the beginner - Using the command line in developing for the web

Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0venkatakrishnan k
 
Aucklug slides - desktop tips and tricks
Aucklug slides - desktop tips and tricksAucklug slides - desktop tips and tricks
Aucklug slides - desktop tips and tricksGlen Ogilvie
 
Red Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift MessengerRed Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift MessengerJustin Bui
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014biicode
 
Linuxppt
LinuxpptLinuxppt
LinuxpptReka
 
lamp technology
lamp technologylamp technology
lamp technologyDeepa
 
Deepa ppt about lamp technology
Deepa ppt about lamp technologyDeepa ppt about lamp technology
Deepa ppt about lamp technologyDeepa
 
Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020CloudHero
 
Introduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command lineIntroduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command lineBehzod Saidov
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3kognate
 
Open Source Virtualization Hacks
Open Source Virtualization HacksOpen Source Virtualization Hacks
Open Source Virtualization HacksNiel Bornstein
 

Ähnlich wie Command line for the beginner - Using the command line in developing for the web (20)

Linux
LinuxLinux
Linux
 
Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
 
Linuxs1
Linuxs1Linuxs1
Linuxs1
 
Unix Administration 2
Unix Administration 2Unix Administration 2
Unix Administration 2
 
Apache Web Server Setup 2
Apache Web Server Setup 2Apache Web Server Setup 2
Apache Web Server Setup 2
 
Aucklug slides - desktop tips and tricks
Aucklug slides - desktop tips and tricksAucklug slides - desktop tips and tricks
Aucklug slides - desktop tips and tricks
 
Red Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift MessengerRed Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift Messenger
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
lamp technology
lamp technologylamp technology
lamp technology
 
Deepa ppt about lamp technology
Deepa ppt about lamp technologyDeepa ppt about lamp technology
Deepa ppt about lamp technology
 
Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020
 
Introduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command lineIntroduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command line
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3
 
Open Source Virtualization Hacks
Open Source Virtualization HacksOpen Source Virtualization Hacks
Open Source Virtualization Hacks
 
Sandy Report
Sandy ReportSandy Report
Sandy Report
 
Sandy Report
Sandy ReportSandy Report
Sandy Report
 

Kürzlich hochgeladen

IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119APNIC
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxmibuzondetrabajo
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxNIMMANAGANTI RAMAKRISHNA
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
Cybersecurity Threats and Cybersecurity Best Practices
Cybersecurity Threats and Cybersecurity Best PracticesCybersecurity Threats and Cybersecurity Best Practices
Cybersecurity Threats and Cybersecurity Best PracticesLumiverse Solutions Pvt Ltd
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxAndrieCagasanAkio
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxMario
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 

Kürzlich hochgeladen (9)

IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptx
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptx
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
Cybersecurity Threats and Cybersecurity Best Practices
Cybersecurity Threats and Cybersecurity Best PracticesCybersecurity Threats and Cybersecurity Best Practices
Cybersecurity Threats and Cybersecurity Best Practices
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptx
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptx
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 

Command line for the beginner - Using the command line in developing for the web

  • 1. COMMAND LINE FOR THE BEGINNER USING THE COMMAND LINE IN DEVELOPING FOR THE WEB Created by Jim Birch jimbir.ch/cmd @thejimbirch Xeno Media, Inc.
  • 2. DEVELOPERS BE ALL LIKE... Source
  • 3. WHAT IS THE COMMAND LINE? A command-line interface ... is a means of interacting with a computer program where the user (or client) issues commands to the program in the form of successive lines of text (command lines). - Wikipedia
  • 4. OFTEN REFERRED TO AS CLI C - Command L - Line I - Interface
  • 5. WHERE IS THIS COMMAND LINE? Linux - Built in Mac - Terminal built in or additional apps like available. Windows - , or the brand new iTerm Cygwin Bash on Ubuntu on Windows Chromebook - Apps that provide limited functionality
  • 6. WHAT DOES THE TERMINAL LOOK LIKE?
  • 9. ANATOMY OF A COMMAND $ command -flag argument/operand command - The action we want to happen flag (optional) - Options for the command operand (optional) - What is acted upon Most of the time you find commands written, they will be prefaced with a $
  • 10. COMMON COMMANDS cd - Change Directory $ cd /path/to/folder $ cd ../../../to move up the tree. cp - Copy $ cp wp-config-sample.php wp-config.php grep - globally search a regular expression and print $ grep term filetosearchin.txt ls - List $ ls -la(l = long format, a = all files, even hidden) mkdir - Make Directory $ mkdir directoryname
  • 11. COMMON COMMANDS mv - Move $ mv wp-config.php ../ pwd - Print Working Directory $ pwd rm - Remove $ rm -rf whatyouwantremoved (r = recursive, f = force) sudo - Superuser Do $ sudo anycommand (Use sudo if you need administrative access to run the command.) touch - Touch $ touch newfilename.txt
  • 12. COMMON COMMANDS If you enter a screen that has a page of information, like a help screen: Use your arrow keys to navigate up and down. Type qto exit.
  • 13. FLAGS For most cases I have found, flags that are full words use two dashes, flags that are acronyms use one dash. --all -a
  • 14. ESCAPING If you ever need to cancel a command: Hold the Control key and C
  • 15. ARCHIVING AND UNARCHIVING Archive and compress; extract files and folders quickly and easily right from the command line.
  • 16. ZIP AND UNZIP To compress a folder using zip: zip -r zip-file-name.zip path/to/folder zip -r zip-file-name.zip file1 file2 file3 To extract: unzip zip-file-name.zip
  • 17. TAR AND UNTAR To compress a folder using tar: tar -zcvf tar-file-name.tar.gz path/to/folder To extract: tar -zxvf tar-file-name.tar.gz
  • 18. NANO AND VI EDITORS nano and vi are text editors available in terminal so you can edit files without needing any other programs.
  • 19. NANO nano file.txt to open a file Control + (letter) for commands Control + G for help
  • 20. VI (OR VIM - "VI IMPROVED") vi file.txt to open a file :help for commands :i to insert :w to save :q to exit
  • 21.
  • 22. YOU HAVE SURVIVED THE BEGINNER LEVEL! Source SKIP TO END
  • 23. CONNECTING TO SERVERS BY SSH Connect to other servers, like your staging and production environments and run commands as you would on your local command line.
  • 24. CREATING SSH KEYS Check for existing keys $ ls -al ~/.ssh Create a new key ssh-keygen -t rsa -C "yourname@domain.com" -t = Key Type, -C = Comment Enter file in which to save the key (/Users/Jim/.ssh/id_rsa): /Users/Jim/.ssh/clientname
  • 25. PUTTING YOUR KEY ON THE SERVER UI Interfaces like CPanel and Plesk Apache - Add your key to /%USER%/.etc/authorized_keys nginx - Install openssh and add your key to /%USER%/.ssh/authorized_keys
  • 26. CONNECTING TO SERVER ssh username@domain.name Enter your password SET UP AN SSH ALIAS nano ~/.ssh/config Host hostname User usernameatserver HostName (IP Address or domain.name) Port 22 IdentityFile ~/.ssh/id_rsa Then, connect with ssh hostname
  • 27. TO DISCONNECT FROM A SERVER: Type exit
  • 28. MYSQL Manage MySQL databases from the command line, including importing and exporting.
  • 29. CONNECTING TO MYSQL mysql -u username -p You will be prompted for password. * Note: You want to avoid using the password inline, as it would be available in logs
  • 30. IMPORTING A DATABASE mysql -u username -p < database.sql
  • 31. EXPORTING A DATABASE mysqldump -u username -p > database.sql
  • 32. ONCE YOU HAVE CONNECTED TO MYSQL, YOU CAN RUN ANY SQL COMMAND CREATE TABLE newtablename (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, name_of_table VARCHAR(30), sub_title VARCHAR(20), yes_or_no CHAR(1), date_of_thing DATE);
  • 33. WP-CLI WP-CLI is a set of command-line tools for managing WordPress installations. You can update plugins, set up multisite installs and much more, without using a web browser. - wp-cli.org
  • 34. COMMON WP-CLI COMMANDS http://wp-cli.org/commands/ wp media regenerate Regenerates all thumbnails wp post list List all the posts of a site wp user delete 123 --reassign=567 Delete a user, and assign their posts to another. wp plugin install hello-dolly Installs Hello Dolly Plugin
  • 35. COMMON WP-CLI COMMANDS wp help Lists all commands and help wp core update Updates Wordpress core wp theme list Lists all themes in the site wp package http://wp-cli.org/commands/package/
  • 36. DRUSH Drush is a command line shell and Unix scripting interface for Drupal. - drush.org
  • 37. ALIASES In computing, alias is a command in various command line interpreters (shells) ... which enables a replacement of a word by another string. - Wikipedia
  • 38. ANATOMY OF AN ALIAS name="command" name - The name of the alias command - The action we want to happen
  • 39. WHERE TO PUT ALIASES MAC OS Temporary - alias name="command" Permanent - nano ~/.bash_profile
  • 40. WHERE TO PUT ALIASES UBUNTU Temporary - alias name="command" Permanent - nano ~/.bash_aliases
  • 41. WHERE TO PUT ALIASES WINDOWS Temporary - DOSKEY name="command" Permanent - A lot more complicated!
  • 42. COMMON USE CASES FOR ALIASES Navigate to common folders alias htdocs="cd /var/www/public_html" alias backdropcms="cd /Users/Jim/jim.local/backdropcms.org" Run Common Tasks alias restart='sudo apachectl restart'
  • 43. COMMON USE CASES FOR ALIASES Open Common Files alias bashprofile='sudo nano /Users/Jim/.bash_profile' alias sshconfig='nano ~/.ssh/config' Open Applications alias github='open -a Firefox https://github.com/thejimbirch? tab=repositories'
  • 44. COMMON USE CASES FOR ALIASES Complex Example Accepts a url, opens chrome in 5 different sized browsers 1 2 3 4 5 6 7 8 9 10 hosted with ❤ by # My Chrome developer profile is in the `Profile 1` directory, make sure to update with yours. # Best on an ultra wide monitor. function rwdurl() { open -n -g -a "Google Chrome" --args --new-window --profile-directory=Profile 1 --app="data:text/html,<html><body><script>win open -n -g -a "Google Chrome" --args --new-window --profile-directory=Profile 1 --app="data:text/html,<html><body><script>win open -n -g -a "Google Chrome" --args --new-window --profile-directory=Profile 1 --app="data:text/html,<html><body><script>win open -n -g -a "Google Chrome" --args --new-window --profile-directory=Profile 1 --app="data:text/html,<html><body><script>win open -n -g -a "Google Chrome" --args --new-window --profile-directory=Profile 1 --app="data:text/html,<html><body><script>win } view rawrwdurl GitHub
  • 45. SEE ALSO ln -s /path/to/file /path/to/symlink Example: htdocs > /var/www/public_html Symbolic link (Symlinks)
  • 46. SEE ALSO Bash Scripts 1 2 3 4 5 6 7 8 hosted with ❤ by fullpath=`pwd` if [[ $fullpath =~ /Users/Jim/Sites/.* ]]; then IFS='/' array=($fullpath) open "http://${array[4]}.xenostaging.com" else echo You are not in a webroot. fi view rawssite bash script GitHub
  • 47. SEE ALSO BASH-IT Bash-it is a collection of community Bash commands and scripts. (And a shameless ripoff of oh-my-zsh :smiley:) Includes autocompletion, themes, aliases, custom functions, a few stolen pieces from Steve Losh, and more. https://github.com/Bash-it/bash-it
  • 48. SECURE COPY PROTOCOL (SCP) Secure copy or SCP is a means of securely transferring computer files between a local host and a remote host or between two remote hosts. It is based on the Secure Shell (SSH) protocol. - Wikipedia
  • 49. COPY FILE FROM LOCAL TO SERVER scp example.txt username@server:myfile.txt COPY ALL FILES IN REMOTE SITE TO LOCAL (FOLDER YOU ARE IN) scp serveralias:/var/www/public_html/wp-uploads/* . COPY FILES FROM ONE SERVER TO ANOTHER scp serveralias:/var/www/public_html/wp- content/files/file1.zip secondserveralias:/var/www/public_html/wp- content/files/file1.zip
  • 50. YOU HAVE SURPASSED THE INTERMEDIATE LEVEL WITH EASE! Source SKIP TO END
  • 51. GIT FOR VERSION CONTROL Git is a widely used source code management system for so ware development. It is a distributed revision control system with an emphasis on speed, data integrity, and support for distributed, non- linear workflows. - Wikipedia
  • 52. GIT IN PLAIN ENGLISH Git gives us a canonical/main source of the code of the project. Multiple versions can be checked out, and merged back in. History of commits/different versions can be saved. Easily sync multiple servers, Development, Staging, Productions.
  • 53. REALLY GREAT GIT TUTORIAL https://git-scm.com/docs/gittutorial
  • 54. COMMON GIT COMMANDS git clone repo.url Clones a repository to your computer git fetch Gets updated code from repository git merge origin/master Merges code from repository, master branch git pull Fetch and merge in one step! git checkout -b branchname Makes a new branch
  • 55. COMMON GIT COMMANDS git diff filename Shows the changes you have made to the file git add -A Adds all files to "staging area" git commit Moves from "staging area" to a commit git push origin master Pushes local master branch to origin master git log Lists history of commits
  • 57. FUTURE DEVELOPMENT WILL BE POWERED BY JAVASCRIPT Node.js® is a JavaScript runtime built that runs NPM (Node Package Manager), the largest ecosystem of open source libraries in the world I use Node.js® to install NPM to install Grunt which installs...
  • 58. TOOLS FOR OUR JAVASCRIPT FILES: jshint - Detect errors and potential problems in your JavaScript code. jscs - Linter/formatter for programmatically enforcing your style guide. uglify - Minify files with UglifyJS concat - Concatenate (merge) files into one.
  • 59. TOOLS FOR OUR CSS FILES: grunt-contrib-less, grunt-sass - Compile LESS/SASS files to CSS csslint - Checks syntax checking and applys a set of rules that look for problematic patterns or signs of inefficiency. cssmin - Minimizes CSS files csscomb - Formats and sorts style sheets to make them organized and consistent.
  • 60. SO MANY USES: imagemin - Minify images seamlessly. copy - automate the copying of files or directories. Thousands more... [ ] [ ]Grunt Plugins Gulp Plugins
  • 61. WATCH! Once these tasks have been assembled in a Gruntfile.js file, you can run the following command to implement these tasks on any changes: grunt watch Any JS/CSS/LESS/SASS files changed will be checked and organized! Images put in the folder I am watching will be minified. Any errors will be reported immediately!
  • 62. DEPENDENCY/PACKAGE MANAGERS LIKE COMPOSER Composer helps you declare, manage and install dependencies of PHP projects, ensuring you have the right stack everywhere. - Composer on Github
  • 63. AN OVERARCHING MAINTAINER OF YOUR WEBSITE AND IT'S NEEDS A composer.json file defines all of the things your website needs. These are called dependencies. This would include Wordpress itself, plugins, and themes. It could also include outside libraries like jQuery, Bootstrap, Foundation, and more.
  • 64. AN OVERARCHING MAINTAINER OF YOUR WEBSITE AND IT'S NEEDS A composer.json file defines all of the things your website needs. These are called dependencies. This would include Wordpress/Drupal core, plugins/modules, and themes. It could also include outside libraries like jQuery, Bootstrap, Foundation, Masonry, and more.
  • 65. REBUILD THIS PROJECT IN A MOMENT'S NOTICE If all dependencies are defined in a composer.json file, composer installcould be run to install the site anywhere. All you would need to do then is setup the database and move the files.
  • 66. SUMMARY BEGINNER Command Line Basics Commands and Flags Archiving and Unarchiving Command Line Editors
  • 67. SUMMARY INTERMEDIATE Connecting to Servers with SSH MySQL WP-CLI / Drush Aliases Secure Copy Protocol - SCP
  • 68. SUMMARY ADVANCED Git for Version Control Automation/task runners like Grunt and Gulp Dependency/Package Managers like Composer
  • 69. NOW YOU CAN BE ALL LIKE... Source
  • 70. THE END CONTINUING THE CONVERSATION: Created by Jim Birch jimbir.ch/cmd @thejimbirch Xeno Media, Inc.