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 @ALIAS db query "SELECT CONCAT('ALTER TABLE ', TABLE_SCHEMA,'.', TABLE_NAME, ' ENGINE=InnoDB;') FROM information_schema.TABLES WHERE ENGINE = 'MyISAM'" --skip-column-names | wp @ALIAS db query
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>
ssh-keygen -C YOUR_EMAIL -m PEM -f ./id_rsa && echo && cat id_rsa && echo && cat id_rsa.pub
tail --follow FILE_NAME
df -hT
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 -a -h --max-depth=1 | sort -h
From StackExchange
find . -type f -name '*.jpg' -exec du -ch {} + | grep total$
From StackExchange
du -sh .
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))
From Tec Admin
while true
do
read -r -p "Is $this_variable correct? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
break;;
[nN][oO]|[nN])
read -p "Enter variable again:" this_variable;;
*)
echo "Invalid input..."
;;
esac
done