Last active
August 5, 2020 19:45
-
-
Save mokanfar/ce2a154811ee24ce0b9b to your computer and use it in GitHub Desktop.
Common Bash Commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#=====tar up missing htaccess hidden files recursively from a parent directory and preserve folder structure=====# | |
find ./magento_dir -name "\.htaccess" | tar -cf missing_htaccess_files_and_dirs -T - | |
#=====general settings when setting up shell=====# | |
sudo chmod -R 755 /var/www | |
sudo chown -R $USER:$GROUP <dir> | |
sudo usermod -a -G root $USER | |
#=====insert 1 line beginning of file before everything else=====# | |
sed -i 1i"sku,qty,eta" ${filename} | |
#=====generate ssh key and add it to list on remote server as acceptable=====# | |
ssh-keygen -t rsa -C "[email protected]" | |
ssh-agent -s | |
eval `ssh-agent -s` | |
ssh-add ~/.ssh/id_rsa | |
#OR add it to authorized_keys file | |
cat ~/.ssh/id_rsa >> authorized_keys | |
#=====new authorized keys make sure has right permissions=====# | |
chmod 0600 ~/.ssh/authorized_keys | |
#=====copy recursively one directory into another NOTICE THE SLASHES OR LACK THEREOF <source> -> <destination>=====# | |
cp -r /home/user/public_html/swatches/ /home/user/stage_html #end result will be in /home/stage_html/swatches | |
#===== cut/move recursively one directory into another NOTICE THE SLASHES OR LACK THEREOF <source> -> <destination> =====# | |
mv /home/public_html/dirname /home/stage_html/ #end result will be in /home/stage_html/dirname | |
#=====find what and where the php.ini file is that php cli uses=====# | |
php -i | grep php.ini | |
#=====Symlink=====# | |
ln -s actual_dir symlink_area | |
ln -s /home/user/public_html/theme/app/design/frontend/la app/design/frontend/la | |
#=====ssh into server=====# | |
ssh user@ip | |
#=====copy from/to the most reliable way=====# | |
rsync -av magmi/ ~/public_html/magmi/ | |
#=====magmi command line create/update=====# | |
php ~/public_html/magmi/cli/magmi.cli.php -profile=create -mode=xcreate | |
php ~/public_html/magmi/cli/magmi.cli.php -profile=update -mode=update | |
#=====check human readable format how much space files take up sorted from biggest at top =====# | |
ls -shS [dirname] | |
#=====check human readable format how much space files take up =====# | |
ls -lh [dirname] | |
#=====check human readable format how much space a directory takes up=====# | |
du -chs [dirname] | |
#=====git config file alteration settings=====# | |
git config --global user.name "user_name" | |
git config --global user.email [email protected] | |
git remote set-url https://github.com/user_name/xxx.git | |
git remote set-url --push https://github.com/user_name/xxx.git | |
git reset --hard origin/master | |
git reset HEAD@{1} | |
git reset HEAD@{3} | |
#=====usual git commands=====# | |
git reflog | |
git diff --cached | |
git pull | |
#=====usual git commands=====# | |
git status | |
git add . | |
git commit -m 'server side connected git' | |
git push | |
#=====git initialize new repository=====# | |
git init | |
git add . | |
git commit -m "first commit" | |
git remote add origin {URL_GOES_HERE_OR_SSH_SERVER} | |
git push -u origin master | |
#=====git branch commands=====# | |
git checkout -b new_branch_name | |
git push origin new_branch_name | |
git branch -D remove_branch_name | |
git push origin :remove_branch_name | |
git merge temp_branch_name #while in master branch to merge | |
git checkout new_branch_name | |
#=====git remove files you manually deleted all at once in command line=====# | |
git ls-files --deleted -z | xargs -0 git rm | |
#=====git settings for local/remote branches=====# | |
#=====remote repo =====# | |
mkdir website.git && cd website.git | |
git init --bare | |
cd hooks | |
nano post-receive | |
#=====post-receive script=====# | |
#!/bin/sh | |
GIT_WORK_TREE=/var/www/www.example.org git checkout -f | |
chmod +x post-receive | |
#=====git settings for local=====# | |
git remote add web ssh://server.example.org/home/ams/website.git | |
git push web +master:refs/heads/master | |
git config --local push.default current | |
git push web | |
#=====local put 'config' file with following info in github ssh folder located in C:\Users\name\.ssh=====# | |
User vagrant | |
IdentityFile C:\Users\name\.ssh\id_rsa_vagrant | |
#=====Find files older than 5 days and delete=====# | |
find /home/ovh/stff/db -iname "*.sql.gz" -mtime +4 -exec rm -f {} + | |
find /home/ovh/stff/db -type f -mtime +4 -exec rm -f {} + | |
#=====Find last php files modified in last 120 days=====# | |
find . -iname "*.php" -mtime -120 -print | |
#=====Find recursively file in sub folders and copy to a specified folder =====# | |
cp $(find . -name 5052-beige-sofa-13-.jpg) ./folderName/ | |
#=====Find last phtml, php or JS files modified in last 14 days with date printed out=====# | |
find . -type f \( -iname \*.phtml -o -iname \*.js -o -iname \*.php \) -mtime -14 -exec stat -c "%n %y" {} \; | |
#=====find text inside file=====# | |
grep -nr --color=always --include=*.extension "search-string-here" . | |
#=====export db=====# | |
mysqldump prefix_db_name -uuser_name -p > mysql.sql | |
#=====create db and assign user access=====# | |
mysql> create database prefix_db_name; | |
mysql> GRANT ALL ON prefix_db_name.* TO user_name@localhost IDENTIFIED BY 'YOUR-PASSWORD-HERE'; | |
#=====magento mysql post import local dev environment=====# | |
select * from core_config_data where path = 'web/secure/base_url'; | |
select * from core_config_data where path = 'web/unsecure/base_url'; | |
update core_config_data set value = 'http://www.xxx.com/' where config_id = 2243; | |
update core_config_data set value = 'http://www.xxx.com/' where config_id = 1066; | |
mysql> DELETE FROM core_config_data WHERE path='web/cookie/cookie_domain'; | |
#=====import .sql.gz db into newly made db with new user=====# | |
zcat db_filename.sql.gz | mysql -u[user] -p db_name | |
#=====untar file into a custom directory=====# | |
tar -C ~/dirname -xvf filename.tar.gz | |
#=====Rsync folder =====# | |
rsync -zqcrae ssh droplet2:/var/www/html/XXXX /mnt/c/z/droplet2 --exclude var/cache --exclude '.git' --exclude var/log --exclude var/report --exclude var/session --exclude var/tmp --exclude magmi --exclude media/catalog/product/cache --exclude 'media/js/*' --exclude 'media/css/*' --exclude 'media/css_secure/*' --exclude 'media/tmp/*' --exclude 'media/import' --exclude n98-magerun.phar --exclude 'dev/stock-sync/node_modules' --delete | |
#=====import db into newly made db with new user=====# | |
mysql -uasdf -ppass db_namedb_name < backup.sql | |
php n98-magerun.phar db:import --compression="gzip" ../labdz.sql.gz | |
#=====Ripgrep and fzf windows find string in files and open in sublime=====# | |
fzfg() { | |
setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null | |
rg -n '' | sed -e 's/:/+/' -e 's/:/\t/' -e 's/+/:/' -e 's/\\/\//g' | fzf | cut -f 1 | cut -d ':' -f 1 | xargs echo ./$@ | |
} | |
#=====manual shared folder mount vagrant windows host=====# | |
sudo mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant | |
#===== custom alias for servers and specify key to use for passwordless userless ssh access=====# | |
nano ~/.ssh/config | |
Host ssh.name.com | |
Hostname ssh.name.com | |
User user_name | |
IdentityFile ~/.ssh/id_rsa_name | |
ssh reload | |
#=====magento web server permissions reset =====# | |
find . -type d -exec chmod 777 {} \; | |
find . -type f -exec chmod 644 {} \; | |
find . -type d -exec chmod 755 {} \; | |
#===== db dump n98 cron job =====# | |
(cd /var/www/html/XXXX/ && php n98-magerun.phar db:dump --strip "@stripped @idx" --compression=gz var/dbbkup) | |
#=====template hints magento on/off toggle =====# | |
n98-magerun.phar --root-dir="/vagrant/httpdocs/mag/" dev:template-hints | |
#=====necessary for ergodox firmware makefile command=====# | |
sudo apt-get install gcc-avr binutils-avr gdb-avr avr-libc avrdude | |
make -f Makefile.lufa cub | |
make -f Makefile.lufa clean | |
#=====wget image and put it in existing folder with a custom name=====# | |
wget --output-document="P:\asdf\dan\category\category2\image.jpg" http://www.website.com/image/image.jpg | |
#=====browser sync CD into directory and run this command=====# | |
browser-sync start --server --files "*.html,*.css" --config "/home/bs-config.js" | |
#=========bs-config.js file===========# | |
module.exports = { | |
"files": '**/*', | |
"watchOptions": { | |
usePolling: true | |
}, | |
"server": true | |
}; | |
#=========Gruntfile.js uncss Extract only css used on specific html file===========# | |
module.exports = function(grunt){ | |
grunt.loadNpmTasks('grunt-uncss'); | |
grunt.initConfig({ | |
uncss: { | |
dist: { | |
files: { | |
'style.css': 'page.html' | |
} | |
} | |
} | |
}); | |
#=========Magento install via cli===========# | |
php -f install.php -- \ | |
--license_agreement_accepted "yes" \ | |
--locale "en_US" \ | |
--timezone "America/Phoenix" \ | |
--default_currency "USD" \ | |
--db_host "DB_HOST" \ | |
--db_name "DB_NAME" \ | |
--db_user "DB_USER" \ | |
--db_pass "DB_PASS" \ | |
--url "SITE_URL" \ | |
--use_rewrites "yes" \ | |
--use_secure "no" \ | |
--secure_base_url "" \ | |
--use_secure_admin "no" \ | |
--admin_firstname "FIRST_NAME" \ | |
--admin_lastname "LAST_NAME" \ | |
--admin_email "EMAIL_ADDRESS" \ | |
--admin_username "USERNAME" \ | |
--admin_password "PASSWORD" | |
#=========.bashrc ===========# | |
alias g='cd /home/grunt/' | |
alias z='cd /vagrant/httpdocs/z/' | |
alias sync='browser-sync start --server --files "*.html,*.css" --config "/home/bs-config.js"' | |
alias hint='n98-magerun.phar --root-dir="/vagrant/httpdocs/mag/" dev:template-hints' | |
alias mt='sudo mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant' | |
alias home='cd ~/'' | |
alias bashrc=nano ~/.bashrc | |
alias src=source ~/.bashrc | |
n98() { n98-magerun.phar "$@"; } | |
#=========.zshrc ===========# | |
alias g='cd /home/grunt/' | |
alias z='cd /vagrant/httpdocs/z/' | |
alias sync='browser-sync start --server --files "*.html,*.css" --config "/home/bs-config.js"' | |
alias hint='n98-magerun.phar --root-dir="/vagrant/httpdocs/mag/" dev:template-hints' | |
alias mt='sudo mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant' | |
alias zshrc='nano ~/.zshrc' | |
alias src='source ~/.zshrc' | |
function g { grep -rnIi "$1" . --color; } | |
alias h='cd' | |
alias bashrc='vim ~/.bashrc' | |
bindkey -s "^[OM" "^M" | |
n() { n98-magerun.phar "$@"; } | |
export PS1="%F{2}%~ %{$reset_color%}%% " | |
alias tmk='cd /vagrant/httpdocs/z/tmk_keyboard/keyboard/ergodox' | |
#=========ffmpeg downvert to tablet size movie ===========# | |
ffmpeg -i input.mp4 -vcodec libx264 -vprofilke main -preset slow -b:v 400k -maxrate 400k -bufsize 800k -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -threads 0 -acodec libvo_aacenc -ab 128k output.mp4 | |
#=========apache commands ===========# | |
sudo service apache2 stop | |
sudo service apache2 start | |
sudo service apache2 graceful | |
sudo vi -w /etc/apache2/sites-available/site-name.conf | |
sudo a2ensite site-name.conf | |
sudo a2enmod rewrite | |
#=========cron example to run every sunday 2 am===========# | |
0 2 * * 6 /usr/local/bin/php /dz/mag/shell/cleaner.php var log | |
#=========cron job view + edit ===========# | |
crontab -e [cron job edit] | |
#=========clear history ===========# | |
history -c [clears history] | |
#========= Magento cache remove to free up space===========# | |
rm -rf media/catalog/product/cache/* | |
rm -rf media/tmp/* | |
rm -rf var/cache/* | |
rm -rf var/report/* | |
rm -rf var/tmp/* | |
rm -rf var/log/* | |
rm -rf var/locks/* | |
rm -rf media/tmp/* | |
#=========change file + directory permissions magento ===========# | |
find . -type d -exec chmod 777 {} \; | |
find . -type f -exec chmod 644 {} \; | |
find . -type d -exec chmod 755 {} \; | |
chmod o+w var app/ etcvar/.htaccess | |
chmod 550 pear | |
chmod -R o+w media | |
sudo chown -R www-data:www-data /var/www | |
sudo chmod -R g+rwX /var/www | |
#If you restrict ftp user to a certain directory, then change the permissions on that directory to disallow "Execute" (so make the directory permissions 644), it should block their php scripts from doing anything. | |
#=========Process Kill Commands Unix===========# | |
ps aux | egrep '(apache|httpd)' | |
kill PID #(SIGTERM) | |
pidof lighttpd | |
killall Process-Name-Here | |
#=========Magento clean up products viewed sql statements===========# | |
SELECT COUNT( * ) | |
FROM `report_viewed_product_index` | |
WHERE `index_id` >=6800002 | |
AND `index_id` <=7800002 | |
DELETE FROM `report_viewed_product_index` | |
WHERE `index_id` >=######## | |
AND `index_id` <=######## | |
#=========copy file from local to remote===========# | |
scp -v -p 22 ./file server: | |
#ssh into server and perform unzip and move (if necessary) | |
ssh server | |
unzip file.zip | |
rsync -av /source/ /destination/ | |
#safe to empty: `catalog_compare_item` | |
#keywords: linux php ubuntu shell commands bash zsh apache mysql magento |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment