BASH

From Craft of Testing - Wiki
Jump to navigation Jump to search

What can we help you find?

Language Syntax
XPath Examples

Random
Home Testing Automation AI IoT OS RF Data Development References Tools Wisdom Inspiration Investing History Fun POC Help

This section is all about helpful BASH commands and can be used as a cheatsheet for BASH.

1. File and Directory Management

Commands to manage, view, and manipulate files or directories:

  • ls, ls -lah, ls -alh, ls -l, ls -la, -*lah: Variations for listing files and directories with details.
  • mkdir plugins.off: Creates a directory.
  • mv plugins plugins.off, mv plugins.off plugins, mv .htaccess .htaccess.off: Moves or renames files and directories (e.g., for disabling or re-enabling).
  • rm -rf plugins.off: Recursively deletes a directory and its contents (use with caution).
  • pwd: Displays the current working directory.
  • find . -type d -exec chmod 755 {} \;: Sets directory permissions to 755.
  • find . -type f -exec chmod 644 {} \;: Sets file permissions to 644.
  • nano .htaccess, nano wp-config.php: Edits configuration files with the nano text editor.

2. Navigation

Commands for moving through the file system:

  • cd ..: Moves up one directory level.
  • cd logs, cd www.testing.com/, cd https, cd ~/logs/, cd ~: Navigates to specific directories.
  • cd wp-content/, cd testing.com, cd platformpurpose.com: Navigates between other specified directories.
  • exit: Ends the current session.

3. Log Viewing and Debugging

Commands for inspecting logs and configurations:

  • tail error.log, tail ~/logs/www.testing.com/https/error.log: Views the end of a log file.
  • tail -n 30 ~/logs/www.testing.com/https/error.log: Displays the last 30 lines of a log file.
  • tail -f ~/logs/www.testing.com/https/error.log: Continuously monitors updates to a log file.
  • cat error.log, cat plugins error.log, cat ../logs/bobsmith.com/https/error.log: Displays the contents of specific files.
  • grep Fatal error.log, grep -r "eval" ../bobsmith.com: Searches for patterns within files or directories.
  • less index.php, head index.php, stat index.php: Views file content and attributes.
  • nano LocalSettings.php, nano /home/bobsmith/...: Opens files for editing.

4. Permissions and Ownership

Commands for modifying permissions and ownership of files and directories:

  • find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +: Grants group write permissions for files.
  • find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +: Grants group write and setgid permissions for directories.
  • chown -R :www-data .: Recursively changes ownership of files to a specific group (www-data).
  • chmod u+w .htaccess, chmod u+w index.php: Grants write access to files.
  • chmod u .htaccess, chmod u-w .htaccess: Modifies user permissions for a specific file.

5. PHP, Magento, and MediaWiki Maintenance

Commands specific to managing PHP, Magento, and MediaWiki:

  • php update.php, php maintenance/update.php: Executes MediaWiki update scripts.
  • php bin/magento setup:static-content:deploy: Deploys static content for Magento.
  • php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');": Downloads the Composer installer script.
  • php composer-setup.php: Installs Composer.
  • php bin/magento cache:clean: Clears Magento cache.
  • php -i | grep HTTP_AUTHORIZATION: Fetches specific PHP configuration details.
  • bin/magento setup:install [config options]: Installs Magento with the specified options.
  • tar xvzf mediawiki-1.39.1.zip -C /home/... --strip-components=1: Extracts files to a specific directory.
  • cat phprc: Displays PHP configuration details.

6. Composer Management

Commands for managing dependencies with Composer:

  • composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /home/bobsmith/luma.testing.com/: Creates a new Magento project.
  • composer install: Installs project dependencies.

7. MySQL and Database Management

Commands for interacting with databases:

  • mysql -u craftoftesting -p: Connects to a MySQL database.
  • SHOW DATABASES;: Lists available databases.
  • wp db export ~/backup\`date +"%d-%m-%Y"-%T\`.sql: Exports a database to a timestamped backup file.

8. WordPress Management

Commands for maintaining and debugging WordPress installations:

  • wp plugin list, wp plugin deactivate wp-malware-removal: Lists or deactivates plugins.
  • wp theme list, wp theme activate rational-start: Lists or activates themes.
  • wp rewrite flush --hard: Resets WordPress rewrite rules.
  • wp core verify-checksums, wp doctor check --all: Validates WordPress core files and performs health checks.

9. Search and Cleanup

Commands for finding and cleaning up files:

  • grep -rh "bobsmith" ../bobsmith.com | sort | uniq: Searches for unique occurrences of a keyword.
  • grep -rl "PhP|php5|PHP5" ../platformpurpose.com | sort | uniq | xargs rm -f: Finds and deletes specific files matching a pattern.

10. Resource and System Monitoring

Commands for monitoring system resources and activity:

  • df -h, df -i: Displays disk space and inode usage.
  • top: Monitors active processes and system resource usage.

11. Miscellaneous Utilities

Other helpful commands:

  • host www.testing.com: Resolves a hostname to an IP address.