Shell Cheatsheet

Quelques astuces pour SHELL…

Boucler sur les sous-répertoires d’un répertoire
Operateur Description Exemple
-b file Checks if file is a block special file; if yes, then the condition becomes true. [ -b $file ] is false.
-c file Checks if file is a character special file; if yes, then the condition becomes true. [ -c $file ] is false.
-d file Checks if file is a directory; if yes, then the condition becomes true. [ -d $file ] is not true.
-f file Checks if file is an ordinary file as opposed to a directory or special file; if yes, then the condition becomes true. [ -f $file ] is true.
-g file Checks if file has its set group ID (SGID) bit set; if yes, then the condition becomes true. [ -g $file ] is false.
-k file Checks if file has its sticky bit set; if yes, then the condition becomes true. [ -k $file ] is false.
-p file Checks if file is a named pipe; if yes, then the condition becomes true. [ -p $file ] is false.
-t file Checks if file descriptor is open and associated with a terminal; if yes, then the condition becomes true. [ -t $file ] is false.
-u file Checks if file has its Set User ID (SUID) bit set; if yes, then the condition becomes true. [ -u $file ] is false.
-r file Checks if file is readable; if yes, then the condition becomes true. [ -r $file ] is true.
-w file Checks if file is writable; if yes, then the condition becomes true. [ -w $file ] is true.
-x file Checks if file is executable; if yes, then the condition becomes true. [ -x $file ] is true.
-s file Checks if file has size greater than 0; if yes, then condition becomes true. [ -s $file ] is true.
-e file Checks if file exists; is true even if file is a directory but exists. [ -e $file ] is true.

 

DIRECTORIES=`ls -1`

for DIR in $DIRECTORIES 
do
 if [ -d $DIR ]
 
 fi
done

 

Grep recursif
grep -r foo
# Comptage
grep -r -c foo

 

 

 

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Matomo encountered an error: Uncaught Piwik\Exception\DatabaseSchemaIsNewerThanCodebaseException: Your Matomo codebase is running the old version 4.14.2 and we have detected that your Matomo Database has already been upgraded to the newer version 4.15.1. Maybe your Matomo administrators are currently finishing the upgrade process. Please try again in a few minutes. If you still have this issue please contact your Matomo administrator for assistance. in /var/www/piwik/core/FrontController.php:692 Stack trace: #0 /var/www/piwik/core/FrontController.php(387): Piwik\FrontController->throwIfPiwikVersionIsOlderThanDBSchema() #1 /var/www/thegtricks/wp-content/plugins/wp-piwik/classes/WP_Piwik/Request/Php.php(40): Piwik\FrontController->init() #2 /var/www/thegtricks/wp-content/plugins/wp-piwik/classes/WP_Piwik/Request/Php.php(18): WP_Piwik\Request\Php->call() #3 /var/www/thegtricks/wp-content/plugins/wp-piwik/classes/WP_Piwik/Request.php(63): WP_Piwik\Request\Php->request() #4 /var/www/thegtricks/wp-content/plugins/wp-piwik/classes/WP_Piwik.php(1038): WP_Piwik\Request->perform() #5 /var/www/thegtricks/wp-content/plugins/wp-piwik/classes/WP_Piwik.php(1205): WP_Piwik->request() #6 /var/www/thegtricks/wp-content/plugins/wp-piwik/classes/WP_Piwik/TrackingCode.php(16): WP_Piwik->updateTrackingCode() #7 /var/www/thegtricks/wp-content/plugins/wp-piwik/classes/WP_Piwik.php(296): WP_Piwik\TrackingCode->__construct() #8 /var/www/thegtricks/wp-includes/class-wp-hook.php(324): WP_Piwik->addJavascriptCode() #9 /var/www/thegtricks/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() #10 /var/www/thegtricks/wp-includes/plugin.php(517): WP_Hook->do_action() #11 /var/www/thegtricks/wp-includes/general-template.php(3068): do_action() #12 /var/www/thegtricks/wp-content/themes/twentyfifteen-child/footer.php(45): wp_footer() #13 /var/www/thegtricks/wp-includes/template.php(790): require_once('...') #14 /var/www/thegtricks/wp-includes/template.php(725): load_template() #15 /var/www/thegtricks/wp-includes/general-template.php(92): locate_template() #16 /var/www/thegtricks/wp-content/themes/twentyfifteen/single.php(53): get_footer() #17 /var/www/thegtricks/wp-includes/template-loader.php(106): include('...') #18 /var/www/thegtricks/wp-blog-header.php(19): require_once('...') #19 /var/www/thegtricks/index.php(17): require('...') #20 {main} thrown (which lead to: Session must be started before any output has been sent to the browser; output started in /var/www/thegtricks/wp-includes/script-loader.php/2925)