Last active
December 16, 2020 18:31
-
-
Save inbalj/d5bf80a02ae4d5d49692 to your computer and use it in GitHub Desktop.
Linux Bash and scripts
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
#!/bin/bash | |
# | |
# All the alias for you linux | |
# | |
# | |
# Some more ls aliases | |
alias e='exit' | |
# To see all the aliases list just type "ali" | |
alias ali="cat /home/$USER/.bash_aliases | grep '^alias' | sed 's/alias //g' | grep -e '^[^=]*' " | |
# Clear the terminal | |
alias c="clear" | |
# list the files with readable file size | |
alias ll="ls -lahG" | |
# To open the last edited file with vim | |
alias lvim="vim -c \"normal '0\"" | |
# Handy shortcuts | |
alias h='history' | |
alias j='jobs -l' | |
# cd stuff | |
## Get rid of command not found ## | |
alias cd..='cd ..' | |
## a quick way to get out of current directory (and get list of all files in the upper dir) | |
cdl() { | |
cd "$@"; | |
ls -al; | |
} | |
alias ..='cdl ..' | |
alias ...='cdl ../../../' | |
alias ....='cdl ../../../../' | |
alias .....='cdl ../../../../' | |
alias .4='cdl ../../../../' | |
alias .5='cdl ../../../../..' | |
up(){ | |
dir="" | |
if [ -z "$1" ]; then | |
dir=.. | |
elif [[ $1 =~ ^[0-9]+$ ]]; then | |
x=0 | |
while [ $x -lt ${1:-1} ]; do | |
dir=${dir}../ | |
x=$(($x+1)) | |
done | |
else | |
dir=${PWD%/$1/*}/$1 | |
fi | |
cd "$dir"; | |
} | |
alias up="up" | |
# A quick way to list all files in the directory | |
cdls(){ | |
if [ -z "$1" ]; then | |
cd ~/ ; | |
else | |
cd "$1"; | |
ls -la; | |
fi | |
} | |
# alias cd='cdls' | |
# Alias for server | |
alias web="cd /home/$USER/www ; ls -ar --sort=time | cat" | |
alias log='cd /var/log/apache2/ ; ls -a | cat ' | |
alias solr='cd /home/solr/apache-solr-3.6.0/example/solr' | |
# list only the directories | |
alias lf='ls -la | grep ^d' | |
# Drupal drush stuff | |
alias dc='drush cc all' | |
alias db='drush archive-dump --tar-options="--exclude=sites/default/files"' | |
alias dw='drush watchdog-list' | |
alias dwt='drush watchdog-show --tail --sleep-delay=2' | |
alias dl='drush pm-list' | |
alias drush7='~/drush7/vendor/bin/drush' | |
alias drush9='~/drush9/vendor/bin/drush' | |
# *** Git *** | |
alias gs='git status' | |
alias ga="git add" | |
alias gaa="git add -A" | |
alias gp="git push origin master" | |
alias gl="git log --oneline --decorate" | |
alias gb="git branch" | |
alias gpl="git pull" | |
alias gk='gitk --all &' | |
# starting and restarting apache2 | |
alias rs='sudo /etc/init.d/apache2 restart' | |
alias ss='sudo cd /home/solr/apache-solr-3.6.0/example/ ; java -jar start.jar' | |
# PS1 - Data and user in the terminal | |
#export PS1="\u \w > " | |
export PS1='\[\e[1;36m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] \[\e[1;37m\]' | |
# Laravel stuff | |
alias pa="php artisan" | |
alias artisan="php artisan" | |
alias migrate="php artisan migrate" | |
alias serve="php artisan serve" | |
alias dump="php artisan dump" | |
alias t="phpunit" | |
# Laravel Generators Package | |
alias g:c="php artisan generate:controller" | |
alias g:m="php artisan generate:model" | |
alias g:v="php artisan generate:view" | |
alias g:mig="php artisan generate:migration" | |
alias g:t="php artisan generate:test" | |
alias g:r="php artisan generate:resource" | |
alias g:s="php artisan generate:scaffold" | |
alias g:f="php artisan generate:form" | |
# Set file promotions | |
alias h7="/home/$USER/bin/permission.sh" | |
# create alias for files | |
# please notes that this function execute script /bin/create_alias.sh | |
function mkdir_alias() { | |
if [ -f /home/$USER/bin/create_alias.sh ] ; then | |
dir=${PWD}; | |
mkdir "$1" && /home/$USER/bin/create_alias.sh "$1" $dir ; | |
cd "$1"; | |
else | |
printf "It look likes the script create_alias.sh - is missing \n" ; | |
fi | |
} | |
alias mkdir_alias="mkdir_alias" | |
# ---------------------------------------------------------------- | |
# **** Do NOT **** edit after this line. | |
# the Alias script will append alias in the end of this file. | |
# | |
# list of alias to files | |
# ******* | |
alias dev="cd /home/$USER/webdev" | |
alias home="cd ~" | |
alias chrome="google-chrome %U &" | |
#alias mv='mv -i' | |
#alias rm='rm -i' | |
#alias cp='cp -i' | |
#alias df='df -h' | |
#alias du='du -h' | |
#alias mkdir='mkdir -p' | |
## SVN ## | |
alias svnu='svn update' | |
alias svns='status' | |
alias svnsm='status | grep "^M"' | |
export LANG=en_US.UTF-8 | |
export LC_TIME=en_US.UTF-8 | |
## | |
export BROWSER="firefox" | |
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
# ~/.bashrc: executed by bash(1) for non-login shells. | |
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) | |
# for examples | |
# If not running interactively, don't do anything | |
case $- in | |
*i*) ;; | |
*) return;; | |
esac | |
# don't put duplicate lines or lines starting with space in the history. | |
# See bash(1) for more options | |
HISTCONTROL=ignoreboth | |
HISTIGNORE="history:pwd:exit:df:ls:ls -la:ll:h" | |
# append to the history file, don't overwrite it | |
shopt -s histappend | |
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) | |
HISTSIZE=1000 | |
HISTFILESIZE=2000 | |
HISTTIMEFORMAT='%b %d %I:%M %p ' # using strftime format | |
# check the window size after each command and, if necessary, | |
# update the values of LINES and COLUMNS. | |
shopt -s checkwinsize | |
# If set, the pattern "**" used in a pathname expansion context will | |
# match all files and zero or more directories and subdirectories. | |
#shopt -s globstar | |
# make less more friendly for non-text input files, see lesspipe(1) | |
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" | |
# set variable identifying the chroot you work in (used in the prompt below) | |
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then | |
debian_chroot=$(cat /etc/debian_chroot) | |
fi | |
# set a fancy prompt (non-color, unless we know we "want" color) | |
case "$TERM" in | |
xterm-color) color_prompt=yes;; | |
esac | |
# uncomment for a colored prompt, if the terminal has the capability; turned | |
# off by default to not distract the user: the focus in a terminal window | |
# should be on the output of commands, not on the prompt | |
#force_color_prompt=yes | |
if [ -n "$force_color_prompt" ]; then | |
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then | |
# We have color support; assume it's compliant with Ecma-48 | |
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such | |
# a case would tend to support setf rather than setaf.) | |
color_prompt=yes | |
else | |
color_prompt= | |
fi | |
fi | |
if [ "$color_prompt" = yes ]; then | |
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' | |
else | |
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' | |
fi | |
unset color_prompt force_color_prompt | |
# If this is an xterm set the title to user@host:dir | |
case "$TERM" in | |
xterm*|rxvt*) | |
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" | |
;; | |
*) | |
;; | |
esac | |
# enable color support of ls and also add handy aliases | |
if [ -x /usr/bin/dircolors ]; then | |
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" | |
alias ls='ls --color=auto' | |
#alias dir='dir --color=auto' | |
#alias vdir='vdir --color=auto' | |
alias grep='grep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias egrep='egrep --color=auto' | |
fi | |
# some more ls aliases | |
alias ll='ls -alF' | |
alias la='ls -A' | |
alias l='ls -CF' | |
# Add an "alert" alias for long running commands. Use like so: | |
# sleep 10; alert | |
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' | |
# Alias definitions. | |
# You may want to put all your additions into a separate file like | |
# ~/.bash_aliases, instead of adding them here directly. | |
# See /usr/share/doc/bash-doc/examples in the bash-doc package. | |
if [ -f ~/.bash_aliases ]; then | |
. ~/.bash_aliases | |
fi | |
# enable programmable completion features (you don't need to enable | |
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile | |
# sources /etc/bash.bashrc). | |
if ! shopt -oq posix; then | |
if [ -f /usr/share/bash-completion/bash_completion ]; then | |
. /usr/share/bash-completion/bash_completion | |
elif [ -f /etc/bash_completion ]; then | |
. /etc/bash_completion | |
fi | |
fi | |
LC_TIME=en_US.UTF-8 |
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
#!/bin/bash | |
# Download a DB dump - remote to local | |
PROJECT_NAME=my_project_name | |
HOST=22.22.222.222 | |
SITE_DIR=/var/www/live/sites/default | |
DUMP_DIR=/home/drupal | |
SSH_USER=drupal | |
SSH_PORT=22 | |
TARGET_DUMP_DIR=~/Documents/dir_name/dump | |
TARGET_DIR=/home/inbal/webdev/project_name/sites/default | |
### connect to remote server ### | |
echo "Dumping the DB of "$PROJECT_NAME" " | |
ssh $SSH_USER@"$HOST" -p $SSH_PORT "cd $SITE_DIR ; drush sql-dump --gzip > $DUMP_DIR/"$PROJECT_NAME"_bak_$(date +%d%m%y).sql.gz && echo 'Finished dumping...'" | |
echo "Downloading the DB of "$PROJECT_NAME" :" | |
scp -P $SSH_PORT $SSH_USER@"$HOST":$DUMP_DIR/"$PROJECT_NAME"_bak_$(date +%d%m%y).sql.gz $TARGET_DUMP_DIR | |
read -r -p "Remove the backup from the server? [y/n] " response | |
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] | |
then | |
ssh $SSH_USER@"$HOST" -p $SSH_PORT "cd $DUMP_DIR ;rm -v "$PROJECT_NAME"_bak_$(date +%d%m%y).sql.gz* && echo '*Backup removed*' " | |
else | |
echo "Don't forget to remove the backup from the server :)" | |
fi | |
### sql-import ### | |
read -r -p "import DB? [y/n] " response | |
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] | |
then | |
echo "Change Dir to "$PROJECT_NAME" " | |
cd $TARGET_DIR | |
echo "Extract archive" | |
gunzip $TARGET_DUMP_DIR/$PROJECT_NAME"_bak_$(date +%d%m%y).sql.gz" && echo 'finished' | |
echo "Importing file to local db" | |
drush sqlc < $TARGET_DUMP_DIR/$PROJECT_NAME"_bak_$(date +%d%m%y).sql" && toilet -f mono12 -F metal "Done!" | |
else | |
toilet -f mono12 -F metal "Bye" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment