Magento 2 Bootcamp Cheatcheet

Learn, Act, Commit

VI, Linux, Git, Magento Commands

VI Commands

:e filename Open filename for edition
:w Save file
:q Exit Vim
:w! Write file and quit

Search

/word Search word from top to bottom
?word Search word from bottom to top
/jo[ha]n Search john or joan
/\< the Search the, theatre or then
/the\> Search the or breathe
/\< the\> Search the
/\< ¦.\>Search all words of 4 letters
/\/ Search fred but not alfred or frederick
/fred\|joe Search fred or joe
/\<\d\d\d\d\> Search exactly 4 digits
/^\n\{3} Find 3 empty lines
:bufdo /searchstr/ Search in all open files

Replace

:%s/old/new/g Replace all occurences of old by new in file
:%s/old/new/gw Replace all occurences with confirmation
:2,35s/old/new/g Replace all occurences between lines 2 and 35
:5,$s/old/new/g Replace all occurences from line 5 to EOF
:%s/^/hello/g Replace the begining of each line by hello
:%s/$/Harry/g Replace the end of each line by Harry
:%s/onward/forward/gi Replace onward by forward, case unsensitive
:%s/ *$//g Delete all white spaces
:g/string/d Delete all lines containing string
:v/string/d Delete all lines containing which didn’t contain string
:s/Bill/Steve/ Replace the first occurence of Bill by Steve in current line
:s/Bill/Steve/g Replace Bill by Steve in current line
:%s/Bill/Steve/g Replace Bill by Steve in all the file
:%s/\r//g Delete DOS carriage returns (^M)
:%s/\r/\r/g Transform DOS carriage returns in returns
:%s#<[^>]\+>##g Delete HTML tags but keeps text
:%s/^\(.*\)\n\1$/\1/ Delete lines which appears twice
Ctrl+a Increment number under the cursor
Ctrl+x Decrement number under cursor
ggVGg? Change text to Rot13

Case

Vu Lowercase line
VU Uppercase line
g~~ Invert case
vEU Switch word to uppercase
vE~ Modify word case
ggguG Set all text to lowercase
:set ignorecase Ignore case in searches
:set smartcase Ignore case in searches excepted if an uppercase letter is used
:%s/\<./\u&/g Sets first letter of each word to uppercase
:%s/\<./\l&/g Sets first letter of each word to lowercase
:%s/.*/\u& Sets first letter of each line to uppercase
:%s/.*/\l& Sets first letter of each line to lowercase

Read/Write files

:1,10 w outfile Saves lines 1 to 10 in outfile
:1,10 w >> outfile Appends lines 1 to 10 to outfile
:r infile Insert the content of infile
:23r infile Insert the content of infile under line 23

File explorer

:e . Open integrated file explorer
:Sex Split window and open integrated file explorer
:browse e Graphical file explorer
:ls List buffers
:cd .. Move to parent directory
:args List files
:args *.php Open file list
:grep expression *.php Returns a list of .php files contening expression
gf Open file name under cursor

Interact with Unix

:!pwd Execute the pwd unix command, then returns to Vi
!!pwd Execute the pwd unix command and insert output in file
:sh Temporary returns to Unix
$exit Retourns to Vi

Alignment

:%!fmt Align all lines
!}fmt Align all lines at the current position
5!!fmt Align the next 5 lines

Tabs

:tabnew Creates a new tab
gt Show next tab
:tabfirst Show first tab
:tablast Show last tab
:tabm n(position) Rearrange tabs
:tabdo %s/foo/bar/g Execute a command in all tabs
:tab ball Puts all open files in tabs

Window spliting

:e filename Edit filename in current window
:split filename Split the window and open filename
ctrl-w up arrow Puts cursor in top window
ctrl-w ctrl-w Puts cursor in next window
ctrl-w_ Maximise current window
ctrl-w= Gives the same size to all windows
10 ctrl-w+ Add 10 lines to current window
:vsplit file Split window vertically
:sview file Same as :split in readonly mode
:hide Close current window
:­nly Close all windows, excepted current
:b 2 Open #2 in this window

Auto-completion

Ctrl+n Ctrl+p (in insert mode) Complete word
Ctrl+x Ctrl+l Complete line
:set dictionary=dict Define dict as a dictionnary
Ctrl+x Ctrl+k Complete with dictionnary

Marks

mk Marks current position as k
˜k Moves cursor to mark k
d™k Delete all until mark k

Abbreviations

:ab mail mail@provider.org Define mail as abbreviation of mail@provider.org

Text indent

:set autoindent Turn on auto-indent
:set smartindent Turn on intelligent auto-indent
:set shiftwidth=4 Defines 4 spaces as indent size
ctrl-t, ctrl-d Indent/un-indent in insert mode
>> Indent
<< Un-indent

Syntax highlighting

:syntax on Turn on syntax highlighting
:syntax off Turn off syntax highlighting
:set syntax=perl Force syntax highlighting

Linux Commands

System Info

dateShow the current date and time
calShow this month's calendar
uptimeShow current uptime
wDisplay who is online
whoamiWho you are logged in as
finger userDisplay information about user
uname -aShow kernel information

File Commands

lsDirectory listing
ls -lList files in current directory using long format
ls -laCList all files in current directory in long format and display in columns
ls -FList files in current directory and indicate the file type
ls -alFormatted listing with hidden files
treeDirectory listing in tree format
cd dirChange directory to dir
cat /proc/cpuinfoCPU information
cat /proc/meminfoMemory information
df -hShow disk usage
duShow directory space usage
freeShow memory and swap usage

Learn the commands

apropos subjectList manual pages for subject
man -k keywordDisplay man pages containing keyword
man commandShow the manual for command
man -t command | ps2pdf -> command.pdfMake a pdf of a manual page
which commandShow full path name of command
time commandSee how long a command takes
whereis appShow possible lcoations of app
which appShow which app will be run by default; it shows the full path

Searching

grep pattern filesSearch for pattern in files
grep -r pattern dirSearch recusrively for pattern in dir
command | grep patternSearch for pattern in the output of command
locate fileFind all instances of file
find / -name filenameStarting with the root directory, look for the file called filename
find / -name "*filename*Starting with the root directory, look for the file containing the string filename
locate fileFind all instances of file
updatedbCreate or update the database of files on all file systems attached to the Linux root directory
which filenameShow the subdirectory containing hte executalbe file called filename
grep TextStringToFind /dirStarting with the directory called dir, look for and list all files containing TextStringToFind

File Permissions

chmod octal fileChange the permissions of file to octal which can be found separately for user, group and world by adding: 4 - read (r), 2 - write (w), 1 - execute (x)
chmod 777read, write, execute for all
chmod 755rwx for owner, rx for group and world. For more options see man chmod.dir
cdChange to home
mkdir dirCreate a directory dir
pwdShow current directory
rm nameRemove a file or directory called name
rm -r dirDelete directory dir
rm -f fileForce remove file
rm -rf dirForce remove an entire directory dir and all it's included files and subdirectories (use with extreme caution)
cp file1 file2Copy file1 to file2
cp -r dir1 dir2Copy dir1 to dir2; create dir2 if it doesn't exist
cp file /home/dirnameCopy file to the /home/dirname directory
mv file /home/dirnameMove the file to the /home/dirname directory
mv file1 file2Rename or move file1 to file2; if file2
ln -s file linkCreate symbolic link link to file
touch fileCreate or update file
cat > filePlaces standard input into file
cat fileDisplay the file called file
more fileDisplay the file called file one page at a time, proceed to next page using the spacebar
head fileOutput the first 10 lines of the file called file
head - 20 fileOutput the first 20 lines of the file called file
tail fileOutput the last 10 lines of the file called file
tail -20 fileOutput the last 20 lines of the file called file
tail -f fileOutput the contents of file as it grows, starting with the last 10 lines

Compression

tar cf file.tar filesCreate a tar named file.tar containing files
tar xf file.tarExtract the files from file.tar
tar czf file.tar.gz filesCreate a tar with Gzip compression
tar xzf file.tar.gzExtract a tar using Gzip
tar cjf file.tar.bz2Create a tar with Bzip2 compression
tar xjf file.tar.bz2Extract a tar using Bzip2
gzip fileCompresses file and renames it to file.gz
gzip -d file.gzDecompresses file.gz back to file

Network

ifconfigList IP addresses for all devices on the local machine
iwconfigUsed to set the parameters of the network interface which are specific to the wireless operation (for exmple: the frequency)
iwlistUsed to display some additional information from a wireless network interface that is not displayed by iwconfig
ping hostPing host and output results
whois domainGet whois information for domain
dig domainGet DNS information for domain
dig -x hostReverse lookup host
wget fileDownload file
wget -c fileContinue a stopped download

SSH

ssh user@hostConnect to host as user
ssh -p port user@hostConnect to host on port port as user
ssh-copy-id user@hostAdd your key to host for user to enable a keyed or passwordless login

User Administration

adduser accountnameCreate a new user called accountname
passwd accountnameGive accountname a new password
suLogin as superuser from current login
exitStop being superuser and revert to normal user

Process Management

psDisplay your currently active processes
topDisplay all running processes
htopDisplay all running processes
kill pidKill process id pid
killall procKill all processes named proc (use with extreme caution)
bgLists stopped or background jobs; resume a stopped job in the background
fgBrings the most recent job to foreground
fg nBring job n to the foreground

Installation from package manager

apt-get install apache2Install Apache2 (Debian / Ubuntu /Linux Mint)
apt-get install -y apache2Install Apache2 without confirm (Debian / Ubuntu /Linux Mint)
apt-get install -y apache2 && apt-get install -y php-fpmInstall Apache2 and PHP-FPM without confirm

Installation from source

./configure
make
make install
dpkg -i pkg.debInstall a DEB package (Debian / Ubuntu / Linux Mint)
rpm - Uvh pkg.rpmInstall an RPM package (Red Hat / Fedora)

Stopping & Starting

shutdown -h nowShutdown the system now and do not reboot
haltStop all processes - same as above
shutdown -r 5Shutdown the system in 5 minutes and reboot
shutdown -r nowShutdown the system now and reboot
rebootStop all processes and then reboot - same as above
service apache2 start|stop|restartStart the Apache2 system
service varnish start|stop|restartStar the Varnish system

GIT Commands

git init
git remote add origin [eigen link]
git fetch
git checkout [branch]
git add --all
git commit -m "comment"
git push origin [branch]

Or create a new respository from the command line

echo "# [repo name]" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:[alias]/[branch].git
git push -u origin master

Or push an existing repository from the command line

git remote add origin git@github.com:[alias]/[branch].git
git push -u origin master

Setup

Configuring user information used across all local repositories

git config --global user.name "firstname lastname"Set a aname that is identifiable for credit when reviewing version history
git config --global user.email "email"Set an email address that will be associated with each history marker
git config --global color.ui autoSet automatic command line coloring for Git for easy reviewing

Init

Initializing and cloning repositories

git initInitialize an existing direcotry
git clone urlRetrieve an entire repository from a hosted location via url

Stage & Snapshot

Working with snapshots and the Git staging area

git statusShow modified files in working directory, staged for your next commit
git add [file]Add file as it looks now to your next commit (stage)
git reset [file]Unstage file while retaining the changes in working directory
git diffShow a diff of what is changed but not staged
git diff --stagedShow a diff of what is staged but not yet committed
git commit -m "descriptive message"Commit your staged content as a new commit

Branch & Merge

Isolating work in branches, changing context and integrating changes

git branchList your branches. A * will appear next to the currently active branch
git branch [branch-name]Create a new branch with name branch-name at the current commit
git checkoutSwitch to another branch and check it out into your working directory
git merge [branch]Merge the history of branch with name branch into the current one
git logShow all commits in the current branch's history

Inspect & Compare

Examining logs, diffs and object information

git logShow the commit history for the currently active branch
git log branchB..branchAShow the commits on branchA that are not on branchB
git log --follow [file]Show the commits that changed file, even across renames
git diff branchB...branchAShow the diff of what is in branchA that is not in branchB
git show [SHA]Show any object in Git in human-readable format

Tracking path changes

Versioning file removes and path changes

git rm [file]Deletes file from project and stage the removal for commit
git mv existing-path new-pathChange an existing file path and stage the move
git log --stat -MShow all commit logs with indication of any paths that moved

Ignoring Patterns

Preventing unintentional staging or committing files

logs/

*.notes

pattern*/

Save a file with desired patterns as .gitignore with either direct string matches or wildcard globs.

git config --global core.excludesefile [file]Systemwide ignore pattern for all local repositories

Share & Update

Retrieving updates from another repository and updating local repos

git remote add [alias] [url]Add a git url as an alias
git fetch [alias]Fetch down all the branches from that Git remote
git merge [alias]/[branch]Merge a remote branch into your current branch to bring it up to date
git push [alias] [branch]Transmit local branch commits to the remote repository branch
git pullFetch and merge any commits from the tracking remote branch

Rewrite history

Rewriting branches, updating commits and clearing history

git rebase [branch]Apply any commits of current branch ahead of specified one
git reset --hard [commit]Clear staging area, rewrite working tree from specified commit

Temporary commits

Temporarily store modified, tracked files in order to change branches

git stashSave modified and staged changes
git stash listList stack-order of stashed file changes
git stash popWrite working from top of stash stack
git stash dropDiscard the changes from top of stash stack

Magento 2 Commands

Usage:

command [options] [arguments]

Options

--help (-h)Displays help message
--quiet (-q)Do not output any message
--verbose (-v|vv|vvv)Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version (-V)Display this application version
--ansiForce ANSI output
--no-ansiDisable ANSI output
--no-interaction (-n)Do not ask any interactive question

Available commands

helpDisplays help for a command
listLists commands

Admin

admin:user:createCreates an administrator
admin:user:unlockUnlock admin account

Cache

cache:cleanCleans cache type(s)
cache:disableDisables cache type(s)
cache:enableEnables cache type(s)
cache:flushFlushes cache storage used by cache type(s)
cache:statusChecks cache status

Catalog

catalog:images:resizeCreates resized product images

Cron

cron:runRuns jobs by schedule

Customer

customer:hash:upgradeUpgrade customer's hash according to the latest algorithm

Deploy

deploy:mode:setSet application mode
deploy:mode:showDisplays current application mode

Dev

dev:source-theme:deployCollects and publishes source files for theme
dev:tests:runRuns tests
dev:urn-catalog:generateGenerates the catalog of URNS to *.xsd
dev:xml:convertConverts XML file using XSL style sheets

i18n

i18n:collect-phrasesDiscovers phrases in the codebase
i8n:packSaves language package
i18n:uninstallUninstalls language packages

Indexer

indexer:infoShows allowed indexers
indexer:reindexReindexes data
indexer:set-modeSets index mode type
indexer:show-modeShows index mode
indexer:statusShows status of indexer

Maintenance

maintenance:allow-ipsSets maintenance mode exempt IPs
maintenance:disableDisables maintenance mode
maintenance:enableEnables maintenance mode
maintenance:statusDisplays maintenance mode status

Module

module:disableDisables specified modules
module:enableEnables specified modules
module:statusDisplays status of modules
module:uninstallUninstalls modules installed by composer

Sampledata

sampledata:deployDeploy sample data modules
sampledata:removeRemove all sample data from composer.json
sampledata:resetReset sample data modules for re-installation

Theme

theme:uninstallUninstalls theme

Info

info:adminuriDisplays the Magento Admin URI
info:backups:listPrints list of available backup files
info:currency:listDisplays the list of available currencies
info:dependencies:show-frameworkShows number of dependencies on Magento framework
info:dependencies:show-modulesShows number of dependencies between modules
info:dependencies:show-modules-circularShows number of circular dependencies between modules
info:language:listDisplays the list of available language locales
info:timezone:listDisplays the list of available timezones

Setup

setup:backupTakes backup of Magento Application code base, media and database
setup:config:setCreates or modifies the deployment configuration
setup:cron:runRuns cron job scheduled for setup application
setup:db-data:upgradeInstalls and upgrades data in the DB
setup:db-schema:upgradeInstalls and upgrades the DB schema
setup:db:statusChecks if the DB schema or data requires upgrade
setup:di:compileGenerates DI configuration and all non-existing interceptors and factories
setup:di:compile-multi-tenantGenerates all non-existing proxies and factories, and pre-compile class definitions, inheritance information and plugin definitions
setup:installInstalls the Magento application
setup:performance:generate-fixturesGenerates fixtures
setup:rollbackRolls back Magento Application codebase, media and database
setup:static-content:deployDeploys static view files
setup:store-config:setInstalls the store configuration
setup:uninstallUninstalls the Magento application
setup:upgradeUpgrades the Magento application, DB data, and schema

Back to top