Collection of code snippets to make command line life a bit easier...
This happens when file/folder write permissions are set securely
Add this code to wp-config.php
From Stack Overflow
define('FS_METHOD', 'direct');
I love all you, precious plugins, slowing everything to a crawl, phoning home for fresh ads to show, so much.
From Twitter @Rarst
define( 'WP_HTTP_BLOCK_EXTERNAL', true );
define( 'WP_ACCESSIBLE_HOSTS', '*.wordpress.org' );
// Remove WP embed script
function ecotechie_stop_loading_wp_embed() {
if ( ! is_admin() ) {
wp_deregister_script( 'wp-embed' );
}
}
add_action( 'init', 'ecotechie_stop_loading_wp_embed' );
/**
* Conditionally change menus.
*/
function ecotechie_wp_nav_menu_args( $args = '' ) {
// change the menu in the Header menu position.
if ( 'top' === $args['theme_location'] && is_page( '138' ) ) {
$args['menu'] = '4'; // 4 is the ID of the menu to use here
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'ecotechie_wp_nav_menu_args' );
wp db query "SELECT option_name, length(option_value) AS option_value_length FROM wp_options WHERE autoload='yes' ORDER BY option_value_length DESC LIMIT 20;"
wp db size --skip-plugins --format=csv --human-readable --all-tables | sed 's/ //g' | sort -k2 -h -t'\"' | grep KB -v | column -t -s, | sed 's/"//g'
wp db query "UPDATE $(wp db prefix)options SET autoload='no' WHERE option_name='OPTION_NAME'"
Replace ... with variables to display on screen
wp_die( '<pre>' . print_r( array( ... ), 1 ) . '</pre>' );
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule wp-content/uploads/(.*) \
http://{PROD}/wp-content/uploads/$1 [NC,L]
</IfModule>
Add www. and https
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
#not working
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Strip www. add https
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
#or using the hardcoded domain
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www. [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://DOMAIN.com/$1 [L,R=301]
<IfModule>
#not working
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [L,R=301]
<IfModule>
ssh-keygen -C YOUR_EMAIL -m PEM -f ./id_rsa && echo && cat id_rsa && echo && cat id_rsa.pub
ssh -i ./id_rsa -p 22 [email protected] -L 65000:127.0.0.1:3306 -N
tail --follow FILE_NAME
df -hT
du -a | cut -d/ -f2 | sort | uniq -c | sort -n
From StackExchange
find . -type d | while read dir; do echo "$dir" : $(find "$dir" -type f | wc -l); done | sort -k2 -t ':' -n;
From StackOverflow
du --all --apparent-size --human-readable --max-depth=1 2>/dev/null | sort -h
From StackExchange
find . -type f -name '*.jpg' -exec du --apparent-size --human-readable --total {} + | grep total$
From StackExchange
du --summarize --human-readable --apparent-size .
From ShellHacks
Remaining
dig +noall +answer domain.com
Configured
DOMAIN=domain.com; dig +noall +answer $DOMAIN @$(dig NS $DOMAIN +short|head -n1)
From ShellHacks
curl -s -w '\nLookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nAppCon time:\t%{time_appconnect}\nRedirect time:\t%{time_redirect}\nPreXfer time:\t%{time_pretransfer}\nStartXfer time:\t%{time_starttransfer}\n\nTotal time:\t%{time_total}\n' -o /dev/null domain.com
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
ps2pdf in.pdf out.pdf
Files modified on Jan 11 at 4am
find . -type f -ls | grep 'Jan 11 04'
Files edited in date range
find . -type f -newermt 2018-01-10 ! -newermt 2018-01-11
CAREFUL WITH THESE!!!
f = files, d = directories
find . -type f ! -perm 0644 -print0 | xargs -0 chmod 644
find . -type d ! -perm 755 -print0 | xargs -0 chmod 755
find . ! -group GROUPNAME ! -path './APATH/' ! -path './ANOTHERPATH'
From Unix Stack Exchange
start=`date +%s`
# Code to be timed...
end=`date +%s`
runtime=$((end-start))
or
start_time=$SECONDS
# Code to be timed...
elapsed_time=$(($SECONDS - $start_time))
Inspired by Tec Admin
validate_input () {
read -r -p "$*" input
while true
do
read -r -p "Is $input correct? [Y/n] " maybe
case $maybe in
[yY][eE][sS]|[yY]|"")
echo "$input"
break
;;
[nN][oO]|[nN])
read -p "Enter variable again:" $input
;;
*)
echo "Invalid input..."
echo
;;
esac
done
}
yes_no () {
echo
while true
do
read -r -p "$* [Y/n] " maybe
case $maybe in
#Return 0, a non failure status.
[yY][eE][sS]|[yY]|"")
return 0
break
;;
# Return 101, a non-zero (failure) status.
[nN][oO]|[nN])
return 101
break
;;
*)
echo "Invalid input..."
;;
esac
done
}
read -r -p "What's your question? [y/N] " response
[[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]] && $do_something || $do_something_else