# If user is not root, pass all commands via sudo. #if [ $UID -ne 0 ]; then # alias reboot='sudo reboot' # alias update='sudo apt-get upgrade' #fi # Instruct bash to expand the arguments to aliases. shopt -s expand_aliases #------------------------------------------------------------- # Protection for these commands; which will prompt before overwriting. #------------------------------------------------------------- # Do not delete / and prompt before deleting. alias rm='rm -i --preserve-root' alias cp='cp -i' alias mv='mv -i' alias ln='ln -i' # Preventing changing perms on / alias chown='chown --preserve-root' alias chmod='chmod --preserve-root' alias chgrp='chgrp --preserve-root' alias rmdir='rm -Rf $1' # To remove directories and their contents. alias rmtrash='mv --force -t ~/.local/share/Trash ' # Toss files into the Trash bin. #------------------------------------------------------------- # APT. #------------------------------------------------------------- # List APT repositories. alias aptlist='cat /etc/apt/sources.list{,.d/*} 2>/dev/null | grep -v "^#"' #------------------------------------------------------------- # Archiving. #------------------------------------------------------------- # Compress with one of the best comp. algos out there + 7z format is platform agnostic. alias 7zadd='7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=64m -ms=on' #------------------------------------------------------------- # Backup. #------------------------------------------------------------- alias rsync='rsync -ravz' # Recusive, Archive Mode, Verbose, Compress alias rsyncssh='rsync -e ssh' # Use ssh. alias backuphome='\rsync -avhpr --delete-delay /home/peter /backup/home/peter' #------------------------------------------------------------- # cd #------------------------------------------------------------- # To pick up when user forgets the space. alias cd..='cd ..' # Uses cd() function = pushd, # b = go backwards (popd), f = go forwards (kind of like "unpopd"). alias d='dirs' alias b='pushd +1' # go backwards (popd). alias f='pushd -0' # go forwards (kind of like "unpopd"). alias gohome='pushd ~/ > /dev/null' # alias goback='popd' # # Add many of similar to these... #alias goproject?"pushd ~/git/project > /dev/null" #alias gologs?"pushd /var/log > /dev/null" #------------------------------------------------------------- # Clipboard #------------------------------------------------------------- # Helps with copy and pasting to and from a terminal using X and the mouse. # Especially for piping output to the clipboard and vice versa. # Alias names chosen according to what the internet said the corresponding macos commands are. alias pbcopy='xsel --clipboard --input' alias pbpaste='xsel --clipboard --output' #echo 'foo' | cpy copies ‘foo’ to the clipboard #alias cpy="xclip -selection clipboard" alias setclip='xclip -selection c' alias getclip='xclip -selection clipboard -o' #------------------------------------------------------------- # Copy. #------------------------------------------------------------- alias cpv='\rsync -ah --info=progress2' # Progress bar on file copy. --info=progress2 gives a total percentage. alias cpv2='\rsync --progress -ravz' # Progress bar on file copy. --progress = show progress during transfer. #------------------------------------------------------------- # Date. #------------------------------------------------------------- alias week='date +"%V"' # Week of the year. # View the calender by typing the first three letters of the month. alias jan='cal -m 01' alias feb='cal -m 02' alias mar='cal -m 03' alias apr='cal -m 04' alias may='cal -m 05' alias jun='cal -m 06' alias jul='cal -m 07' alias aug='cal -m 08' alias sep='cal -m 09' alias oct='cal -m 10' alias nov='cal -m 11' alias dec='cal -m 12' #------------------------------------------------------------- # Disk #------------------------------------------------------------- #alias du='\du -ach | sort -h' # Human-readable format. #alias du='du -kh' # Human-readable format. alias du="\du -hc -d1 2> >(grep -v 'Permission denied') | sort -h" alias dutotal='\du -ch 2> /dev/null |tail -1' # Displays only the total. alias du1='\du -h -d 1' # Shows only 1 level deep. alias du10='\du -hsx * | sort -rh | head -10' # What is using the most space. alias df='\df -kTh;\df -Thl --total | grep total' # Adds total to the df command. #alias df="df -Tha --total" # Shows the individual partition usages without the temporary memory values. alias dfx='\df -kThl --exclude-type=tmpfs --exclude-type=devtmpfs' alias mount='\mount | column -t' # Make mount command output pretty and human readable format. # View only mounted drives. #alias mnt="mount | awk -F ' ' '{print \$1, \$3}' | column -t | grep -E ^/dev/ | sort" # The \ before the $ is only needed when used as an alias. alias mnt='\mount | awk -F'\'' '\'' '\''{ printf "%s\t%s\n",$1,$3; }'\'' | column -t | grep -E ^/dev/ | sort' #alias mnt="\mount | awk -F' ' '{ printf \"%s\t%s\n\",\$1,\$3; }' | column -t | grep -E ^/dev/ | sort" #alias mnt="mount | awk '$1 ~ /\/dev/ { print $1,$3; }' | column -t | sort;" alias mntnice='\mount | grep -E ^/dev | column -t # Display mount nicely.' #------------------------------------------------------------- # Directories. #------------------------------------------------------------- alias mkdir='mkdir -p' # Make parent directories if needed. alias back='cd $OLDPWD' # Return to the last directory you were in. Same as 'cd -'. #------------------------------------------------------------- # Docker. #------------------------------------------------------------- alias dockershell="docker run --rm -i -t --entrypoint=/bin/bash" # Specify an image and drop into an interactive bash shell. alias dockershellsh="docker run --rm -i -t --entrypoint=/bin/sh" # Specify an image and drop into an interactive sh shell. #alias dockerphp='docker run --rm -it -v "$PWD":/opt -w /opt php php' #alias dockerjava='docker run --rm -it -v "$PWD":/opt -w /opt java java' #alias dockernode='docker run --rm -it -v "$PWD":/opt -w /opt node node' #alias dockerruby='docker run --rm -it -v "$PWD":/opt -w /opt ruby ruby' #alias dockerpython='docker run --rm -it -v "$PWD":/opt -w /opt python python' #alias dockerhtop='docker run --rm -it --pid host tehbilly/htop' #alias dockermysql='docker run --rm -it imega/mysql-client mysql' #------------------------------------------------------------- # Downloading. #------------------------------------------------------------- alias wget='wget -c' # -c flag to continue download in case of problems. alias wgetpage='wget --html-extension --recursive --convert-links --page-requisites --no-parent $1' # Save a local copy of a remote web resource. #------------------------------------------------------------- # Files. #------------------------------------------------------------- alias fcount='ls -l | wc -l' # File count. alias fcounta='ls -la | wc -l' # File count (incl hidden files). alias fcountr='find . -type f | wc -l' # File count recursive. alias lastmod='ls -t -1' # Last modified file. alias lastmodified='find -type f -print0 | xargs -r0 stat -c %y\ %n | sort' # Last modified file in all subdirectories as well. alias blanks="grep '(^[[:space:]]*$'" # Only blank lines. alias noblanks="grep -Ev '(^[[:space:]]*#|^$|^[[:space:]]*//)'" # Only print actual code/configuration. alias comments="grep '^ *\#.*$'" # Show comments in a file. alias nocomments='grep -Ev "^(#|$)"' # Show text file without comment (#) lines; or empty lines. alias decomment='grep -Ev "^[[:space:]]*((#|;|//).*)?$" ' # Removes full-line comments and blank lines. alias unprintable='grep --color="auto" -P -n "[\x00-\x1E]"' # Shows which lines (with line numbers) in a file contain control characters. alias expletives='grep --color="auto" -P -n "[^\x00-\x7E]" ' # Shows which lines in a file contain anything "above" a RUBOUT, i.e. above ASCII 127. alias bigfiles='find . -type f 2>/dev/null | xargs du -a 2>/dev/null | awk "{ if ( \$1 > 5000) print \$0 }" | sort -hr' alias verybigfiles='find . -type f 2>/dev/null | xargs du -a 2>/dev/null | awk "{ if ( \$1 > 500000) print \$0 }" | sort -hr' alias brokenlinks='\find . -xtype l -printf "%p -> %l\n"' # Find broken symlinks. # count files by type - http://www.shell-fu.org/lister.php?id=173 #alias ftype="\find ${*-.} -type f | xargs file | awk -F, '{print $1}' | awk '{$1=NULL;print $0}' | sort | uniq -c | sort -nr" alias fdiff='grep -F -x -v -f $1 $2' # Show diffs between files. alias filedeletefirstline='cat tmp.txt | sed 1d | wc -l' # Delete first line of file. #------------------------------------------------------------- # File Permissions. #------------------------------------------------------------- alias fperm="find . -type f -exec chmod 0644 '{}' \;" # File permissions. alias dperm="find . -type d -exec chmod 0755 '{}' \;" # Directory permissions. #------------------------------------------------------------- # GPU. #------------------------------------------------------------- alias showgpu="watch -d -n 0.5 nvidia-smi"a # Nvidia. #------------------------------------------------------------- # Greps. #------------------------------------------------------------- alias grep='grep --color=auto' # Color output. alias egrep='egrep --color=auto' # Color output. alias fgrep='fgrep --color=auto' # Color output. alias grepall='find . -name "*" | xargs grep --color=auto ' # Greps everything, including subdirectories. #------------------------------------------------------------- # History. #------------------------------------------------------------- # Find a command in your grep history. # Usage: # histgrep bash alias histgrep='history|grep' # Find a command in history. Usage "histgrep something". #alias histtop10="history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10" # Returns most commonly used commands. #------------------------------------------------------------- # Images. #------------------------------------------------------------- # Resizes images. # Use the ImageMagick package (sudo apt-get install imagemagick) which contains a command called mogrify that does just this. # This will resize all of the PNG images in the current directory, only if they are wider than 690px. #alias imgresizepng='mogrify -resize 690\> *.png' # Resize all PNG images wider than 690px in the current directory. #------------------------------------------------------------- # Logs. #------------------------------------------------------------- # alias syslog='sudo tail -10f /var/log/syslog' # Follow syslog. # alias messages='sudo tail -10f /var/log/messages' # Follow messages. alias dmesg='dmesg -T' # Make log times human readable. # Last 10 items within every log file. alias logs='tail -f /var/log/{dmesg,messages,*{,/*}{log,err}}' alias syslog="tail -F /var/log/syslog" # Returns the frequency of each line; i.e. how many times the line is in the file. # Useful when parsing logs. # What is the most common line in this stream. alias rank="sort| uniq -c|sort -n" #------------------------------------------------------------- # ls. (Assumes you use a recent GNU ls). #------------------------------------------------------------- alias ls='\ls -h --color=auto' # Add colors and human-readable sizes by default on 'ls'. alias lsn='\ls --color=never' # With no color. alias lsa='ls -A' # Show hidden files. alias lsd='ls -d */ >/dev/null 2>/dev/null; [ $? -eq 0 ] && ls -d */ || : ;' # List only directories, if any exist. alias lsdf='ls -v --group-directories-first' # Directories first, with alphanumeric sorting. #alias lsdt='ls -h --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F' #alias lsdt='ls -h --group-directories-first --time-style=+"%Y.%m.%d %H:%M" --color=auto -F' alias lsdt='ls -h --group-directories-first --time-style="+%Y-%m-%d %H:%M:%S" --color=auto -F' alias lse='ls -AF | grep -E "\.|/"' # Show only file with an extension. alias lsh='ls -Am' # List files horizontally, comma-separated. alias lsm='ls -Al |more' # Pipe through 'more'. alias lsne='ls -AF | grep -Ev "\.|/"' # Show only file without an extension. alias lsnx='ls -AF | grep -v \*' # Show non executables only. alias lsr='ls -lR' # List files recursively. alias lssd='ls -Atr' # Sort by date, most recent last alias lssh='ls -Ax' # Sort by name horizontally. #alias lsss='ls --human-readable --size -1 -S --classify' # Sort by size, biggest first. alias lsss='ls -Sr' # Sort by size, biggest last. alias lsssh='ls -shAxSr' # Sort by size, biggest last, horizontally. alias lssta='ls -Atur' # Sort by/show access time,most recent last. alias lsstc='ls -Atcr' # Sort by/show change time,most recent last. alias lssx='ls -AXB' # Sort by extension. alias lsx='ls -AF | grep \*' # Show executables only. alias ll='ls -lF' # Long listing, classify. alias lla='ls -lAF' # All files, long listing. alias lld='ls -lFA | grep :*/' # List only directories, if any exist. alias lldf='ls -lv --group-directories-first' # Directories first, with alphanumeric sorting. #alias lldt='ls -lh --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F' #alias lldt='ls -lh --group-directories-first --time-style=+"%Y.%m.%d %H:%M" --color=auto -F' alias lldt='ls -lh --group-directories-first --time-style="+%Y-%m-%d %H:%M:%S" --color=auto -F' alias lle='ls -lFA | grep -E "\.|/"' # Show only file with an extension. alias llm='ll |more' # Pipe through 'more' alias llne='ls -lFA | grep -Ev "\.|/"' # Show only file without an extension. alias llnx='ls -lFA | grep -v \*' # Show non executables only. alias llr='ll -lAR' # Recursive ls. alias llsd='ls -lAtrh' # Sort by date, most recent last, and human readable alias llss='ls -lSr' # Sort by size, biggest last. alias llsta='ls -ltur' # Sort by/show access time,most recent last. alias llstc='ls -ltcr' # Sort by/show change time,most recent last. alias llsx='ls -lXB' # Sort by extension. alias llx='ls -lFA | grep \*' # Show executables only. alias tree='find . | sed "s/[^/]*\//| /g;s/| *\([^| ]\)/+--- \1/"' # Simple tree of current dir. #------------------------------------------------------------- # Memory. #------------------------------------------------------------- alias free="free -mt" # Shows nicer output. alias gpumem='grep -i --color memory /var/log/Xorg.0.log' alias mem='grep -E "Mem|Cache|Swap" /proc/meminfo' #alias mem2='echo -e Memory usage: $(free -h | grep "+" | cut -c26-30)/ $(free -h | grep "Mem:" | cut -c15-18)' #------------------------------------------------------------- # Misc. #------------------------------------------------------------- # Set the ? (question mark) as an alias. alias -- ?='echo Help' #alias '?'='echo help' # Makes all of the other aliases you define function correctly when used with sudo. # The ALIASES section of the bash manual says: # If the last character of the alias value is a blank, then the next command word following the alias is also checked for alias expansion. # So this ensures commands are evaluated for aliases before being passed over to sudo, which ends up being pretty useful. alias sudo='sudo ' # Makes all of the other aliases you define function correctly when used with sudo. alias please='sudo $(fc -ln -1)' # Rerun the last typed command, but prepend it with 'sudo' this time. alias machine='uname -a | cut -f2 -d" "' # Machine name. alias pause='read -n 1 -p "Press any key to continue…"' alias restart='killall -SIGUSR1' alias utf='iconv -f ISO-8859-1 -t UTF-8' alias which='type -a' # Includes aliases. alias userinfo='getent passwd|column -t -s: -n' alias groupinfo='getent group|column -t -s: -n' # Generate sha1 digest. alias sha1='openssl sha1' #------------------------------------------------------------- # Networking. #------------------------------------------------------------- alias connections='sudo /usr/bin/lsof -i -P' #alias openports='netstat -lntp 2>/dev/null | grep -v " - *$"' # Shows open ports. #alias openports='ss -lntp 2>/dev/null | grep -v " - *$"' # Shows open ports. alias openports='sudo lsof -i -P -n | grep LISTEN' # Shows open ports. #alias macs='ifconfig | grep HWaddr' # Shows MAC addresses for all nics. alias macs='ip a | grep link/ether' # Shows MAC addresses for all nics. #alias netstatus="netstat -ant | awk '{print $6}' | sort | uniq -c | sort -n" alias netstatus="ss -ant | awk '{print $6}' | sort | uniq -c | sort -n" #alias nics='ifconfig em1 | egrep "[0-9]{1,3}(\.[0-9]{1,3}){3}"' # Shows all nics. alias nics='ip a | grep -E "[0-9]{1,3}(\.[0-9]{1,3}){3}"' # Shows all nics. #alias nics='ip a | egrep "[0-9]{1,3}(\.[0-9]{1,3}){3}"' # Shows all nics. alias ping='ping -c 5' # Stop after sending 5 ECHO_REQUEST packets. alias fastping='sudo ping -c 5 -s.2' # Do not wait interval 1 second, go fast. #alias pingrouter="ping `netstat -nr| grep -m 1 -iE 'default|0.0.0.0' | awk '{print $2}'`" # Print the router. #alias pingrouter="ping `ip a|sort -nr| grep -m 1 -iE 'default|0.0.0.0' | awk '{print $2}'`" # Print the router. #####alias pingrouter="ping `ss -nr| grep -m 1 -iE 'default|0.0.0.0' | awk '{print $2}'`" # Print the router. #alias subnet="netstat -nr| grep -m 1 -iE 'default|0.0.0.0' | awk '{print $2}' | sed 's/\.[0-9]*$//'" # Returns 192.168.1. #####alias subnet="ss -nr| grep -m 1 -iE 'default|0.0.0.0' | awk '{print $2}' | sed 's/\.[0-9]*$//'" # Returns 192.168.1. # Show a listing of IP addresses. alias ips="ip a | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'" # Network diagnostic. # Usage: mtr google.com alias trace='mtr --report-wide --curses $1' #------------------------------------------------------------- # Monitors. #------------------------------------------------------------- # Disconnect monitors or if back to officef #alias monitormulti='xrandr --output HDMI-2 --primary --auto --right-of eDP-1' #alias monitorsingle='xrandr --output HDMI-2 --off' #alias monitormax='sudo ~/xbacklight -set 100' #------------------------------------------------------------- # Notifications. #------------------------------------------------------------- # Sends a note to all logins. # Usage: growl this is my message. # [TODO: Need to check this works - take care!] #alias growl=`notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e `\s/^s*[0-9]\+\s*//;s/[;&|]\s*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 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 alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' # 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$//'\'')"' #------------------------------------------------------------- # Passwords. #------------------------------------------------------------- #------------------------------------------------------------- # Path. #------------------------------------------------------------- # Pretty-print of some PATH variables: alias path='echo -e ${PATH//:/\\n}' alias libpath='echo -e ${LD_LIBRARY_PATH//:/\\n}' #------------------------------------------------------------- # Processes. #------------------------------------------------------------- alias ps="\ps auxf" # Set default. alias psc='\ps h -eo pcpu,pmem,pid,comm,user,cputime | sort -nr | head' alias psc10="ps auxf | sort -nr -k 3 | head -10" alias psm='\ps h -eo pmem,pcpu,pid,comm,user,cputime | sort -nr | head' alias psm10="ps auxf | sort -nr -k 4 | head -10" alias pstree='\ps -e -o pid,args --forest' alias psfull='\ps -auxwww' # ps with wide output so you can see full commands. # usage: psg peter # usage: psg ssh alias psg="\ps aux | grep -v grep | grep -i -e VSZ -e" # ps grep. #alias psg='ps -Helf | grep -v $$ | grep -i -e WCHAN -e ' # ps grep. # Show only 1 line for ps grep. alias psg1="\ps -el | column -t | head -1 && \ps -el | column -t | \grep $1" # Show only my procs. alias myps='\ps -fHu $USER' # if not $USER, try $LOGIN #------------------------------------------------------------- # Programming – C/C++/Java/PHP. #------------------------------------------------------------- # Count lines of php code under the current directory. alias countphp='find . -name "*.php" -print0 | xargs -0 wc' # Count lines of java code under the current directory. alias countjava='find . -name "*.java" -print0 | xargs -0 wc' # Count lines of C or C++ or Obj-C code under the current directory. alias countc='find . \( -name "*.c" -or -name "*.cpp" -or -name "*.h" -or -name "*.m" \) -print0 | xargs -0 wc' # Count lines of C or C++ or Obj-C or Java or PHP code under the current directory. alias countcode='find . \( -name "*.c" -or -name "*.cpp" -or -name "*.h" -or -name "*.m" -or -name "*.java" -or -name "*.php" \) -print0 | xargs -0 wc' alias gcc='gcc -std=c99' alias g++='g++ -std=c++2a' #------------------------------------------------------------- # Python. #------------------------------------------------------------- # Create a Python virtual environment. # # Running pyve creates a new directory, called venv, containing the usual virtual environment filesystem for Python3. # The pyva alias activates the environment in your current shell: # #$ cd my-project #$ ve #$ va #(venv) $ alias pyve='python3 -m venv ./venv' alias pyva='source ./venv/bin/activate' #------------------------------------------------------------- # Screen. #------------------------------------------------------------- # Turn screen off. alias screenoff="xset dpms force off" alias screencast="ffmpeg -threads 0 -async 30 -f x11grab -s 1920x1080 -r 30 -i :0 -vcodec libx264 -preset superfast -crf 16 -f mp4 out.mp4" alias screencastaudio="ffmpeg -threads 0 -async 30 -f alsa -i pulse -f x11grab -s 1920x1080 -r 30 -i :0 -vcodec libx264 -preset superfast -crf 16 -acodec libmp3lame -f mp4 out.mp4" alias screentest='P=(" " █ ░ ▒ ▓); while :; do printf "\e[$[RANDOM%LINES+1];$[RANDOM%COLUMNS+1]f${P[$RANDOM%5]}"; done' #------------------------------------------------------------- # Sound. #------------------------------------------------------------- alias mic-on="pactl load-module module-loopback" alias mic-off="pactl unload-module module-loopback" #------------------------------------------------------------- # Spelling typos. Highly personal and keyboard-dependent. #------------------------------------------------------------- alias xs='cd' alias vf='cd' alias moer='more' alias moew='more' alias kk='ll' #------------------------------------------------------------- # Time. #------------------------------------------------------------- alias now='date +"%T"' alias nowtime=now alias nowdate='date +"%Y-%m-%d"' #------------------------------------------------------------- # TMUX. #------------------------------------------------------------- alias tmuxn='tmux new-session -s' # tmux new session. alias tmuxa='tmux attach -t' # tmux attach. alias tmuxls='tmux ls' # tmux list. alias tmuxkill='tmux kill-session -s' # kill session name. #------------------------------------------------------------- # UUID. #------------------------------------------------------------- alias uuid="uuidgen | tr -d - | tr -d '\n' | tr '[:upper:]' '[:lower:]' && echo" #------------------------------------------------------------- # Web. #------------------------------------------------------------- # Pass it via sudo so whoever is admin can reload it without calling you. alias nginxreload='sudo /usr/sbin/nginx -s reload' alias nginxtest='sudo /usr/sbin/nginx -t'