Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Using the Command Line with Magento

A brief overview of useful bash commands in a Magento context

  • Als Erste(r) kommentieren

Using the Command Line with Magento

  1. 1. @ma$hewhaworth
  2. 2. SSH@ma$hewhaworth
  3. 3. Make use of SSH config @ma$hewhaworth
  4. 4. SSH Config file # ~/.ssh/config Host myclient-dev HostName dev.example.com Port 2020 User myclientu IdentityFile ~/.ssh/id_rsa @ma$hewhaworth
  5. 5. SSH Config file # ~/.ssh/config Host myclient-dev HostName dev.example.com Port 2020 User myclientu IdentityFile ~/.ssh/id_rsa $ ssh myclient-dev @ma$hewhaworth
  6. 6. Use screen @ma$hewhaworth
  7. 7. screen Start terminal sessions that you can disconnect from and resume at any 3me. @ma$hewhaworth
  8. 8. Screen Cheatsheet # Create and name a new screen session $ screen -S <name> # Detach from screen (but keep it alive) $ Ctrl+a d # Resume a named session $ screen -r <name> # List active sessions $ screen -ls # Catch all (use existing, or create new) $ screen -dRR @ma$hewhaworth
  9. 9. Escape a dead SSH connec-on @ma$hewhaworth
  10. 10. Enter ~ . Kills a dead SSH session and lets you keep your terminal @ma$hewhaworth
  11. 11. Files@ma$hewhaworth
  12. 12. Tricks to ge,ng around @ma$hewhaworth
  13. 13. This makes me want to kill you $ cd app $ cd code $ cd MyVendor $ cd MyModule $ cd etc $ cd ../../.. $ cd .. $ cd .. @ma$hewhaworth
  14. 14. This is much nicer $ cd app/code/MyVendor/MyModule/etc $ cd - @ma$hewhaworth
  15. 15. Using tar for archiving and compression @ma$hewhaworth
  16. 16. Tar tar czf myarchive.tar.gz <files> c - Create new archive z - Zip f - Filename @ma$hewhaworth
  17. 17. @ma$hewhaworth
  18. 18. T-arghh! $ tar czf magento_backup.tar.gz <files> c - Create z - Ze f - Files @ma$hewhaworth
  19. 19. T-arghh! $ tar czf magento_backup.tar.gz <files> c - Create z - Ze f - Files $ tar xzf magento_backup.tar.gz x - eXtract z - Ze f - Files @ma$hewhaworth
  20. 20. A bit more on tar # Extract to specific directory $ tar xf magento_ce.tar.gz -C myDirectory # Only extract a particular file $ tar xf magento_ce.tar.gz magento @ma$hewhaworth
  21. 21. mkdir magic @ma$hewhaworth
  22. 22. mkdir magic -p allows you to create children and parents at the same 4me # Verbose $ mkdir app && mkdir app/code && mkdir app/code/MyModule # Better $ mkdir -p app/code/MyModule @ma$hewhaworth
  23. 23. mkdir magic Using {} allows you to create mul4ple directories at once $ mkdir -p app/code/MHCommerce/{ShippingMethods,Checkout}/{Block,Model,etc} └── app └── code └── MHCommerce ├── Checkout │   ├── Block │   ├── Model │   └── etc └── ShippingMethods ├── Block ├── Model └── etc @ma$hewhaworth
  24. 24. tree $ brew install tree $ tree └── app └── code └── MHCommerce ├── Checkout │   ├── Block │   ├── Model │   └── etc └── ShippingMethods ├── Block ├── Model └── etc @ma$hewhaworth
  25. 25. Keeping an eye on files @ma$hewhaworth
  26. 26. less and Shift + F Browse file and s-ck to the bo3om $ less var/log/system.log [Shift + F] @ma$hewhaworth
  27. 27. tail -f Print end of file to standard out # Prints last ten lines to standard out $ tail var/log/system.log # Prints the end of the file continuously $ tail -f var/log/system.log # Print last x lines $ tail -f -n20 var/log/system.log @ma$hewhaworth
  28. 28. watch Con$nuously execute a command $ brew install watch $ watch -n[update_interval] "[command]" $ watch -n1 "cat var/log/system.log" $ watch -n0.1 "ls -lsah" @ma$hewhaworth
  29. 29. Other useful file based commands - grep - Filter lines in a file - sed - Find and replace on a file - awk - More complex text manipulation @ma$hewhaworth
  30. 30. Processes @ma$hewhaworth
  31. 31. Keeping processes quiet @ma$hewhaworth
  32. 32. Background Processes with & $ tar czf backup.tar.gz magento & [1] 13281 $ jobs [1] + running tar czf backup.tar.gz magento # some time later ... [1] + 13281 done tar czf backup.tar.gz magento @ma$hewhaworth
  33. 33. Hal$ng Processes $ tar czf backup.tar.gz magento [Ctrl + z] [1] + 13552 suspended tar czf backup.tar.gz magento $ bg [1] + 13552 continued tar czf backup.tar.gz magento $ jobs [1] + running tar czf backup.tar.gz magento $ fg [1] + 13613 running tar czf backup.tar.gz magento @ma$hewhaworth
  34. 34. Hal$ng SSH SSH is just another process, it can be halted and resumed in the same way $ ssh my-client-staging my-client-staging $ Enter + ~ then [Ctrl + z] [1] + 13702 suspended ssh my-client-staging $ fg [1] + 13702 continued ssh my-client-staging my-client-staging $ ls #... @ma$hewhaworth
  35. 35. Pipe viewer View the progress of pipe'd input $ brew install pv $ pv db.sql | mysql -uroot my_client_db 178MiB 0:00:38 [17.9MiB/s] [==========> ] 60% ETA 0:00:28 @ma$hewhaworth
  36. 36. Other useful process based commands - top - See a process list - htop - See a colourful and more interactive process list - ps - Print out processes to std out, use `ps aux` - kill - Kill a process by id - killall - Kill all processes with a certain name @ma$hewhaworth
  37. 37. Shortcuts @ma$hewhaworth
  38. 38. Forgot sudo? Lazy? $ service mysql restart Permission denied $ sudo !! MySQL restarted # equivalent to... $ sudo service mysql restart MySQL restarted @ma$hewhaworth
  39. 39. Already wri+en a file path once? Lazy? $ ls -lash app/etc/env.php $ vim !$ # equivalent to... $ vim app/etc/env.php @ma$hewhaworth
  40. 40. Want to pull in a command from history? $ history ... 1028 ls -lash 1029 vim app/etc/local.xml 1030 rm app/etc/local.xml # Re-run command 1028 $ !1028 OR [Ctrl + r] allows you to search through previous commands @ma$hewhaworth
  41. 41. Wri$en a command that's star1ng to get too long? [Ctrl + x] [Ctrl + e] This will open a text editor containing the command you currently have wri7en on the command line @ma$hewhaworth
  42. 42. Further Reading Mac users --------- - https://brew.sh/ - Homebrew - https://github.com/robbyrussell/oh-my-zsh All Unix -------- - http://www.commandlinefu.com/ - https://github.com/learnbyexample/ @ma$hewhaworth
  43. 43. Thank you! Specifically those who suffered my prac5ce runs... Sam Beckingham-Cook: @SamboBeckingham Lee Frankland: @leefrankland Lissie Cox: @LissieCox Phil Turner: @FlipTurner Vinai Kopp: @VinaiKopp @ma$hewhaworth

×