├── .bash_alias ├── .nanorc ├── .tmux.conf ├── .vimrc ├── LICENSE ├── README.md ├── custom.conkyrc ├── export.sh ├── in_progress.sh └── ubuntu_setup.sh /.bash_alias: -------------------------------------------------------------------------------- 1 | function weather() { 2 | if [[ -z $1 ]]; then 3 | curl wttr.in/$1 4 | elif [[ -z $CITY ]]; then 5 | curl wttr.in/$CITY 6 | else 7 | echo "Please specify city!" 8 | fi 9 | } 10 | 11 | function find_big_files() { 12 | find . -size +"$1" -type f -print0 | xargs -0 ls -Ssh | sort -z 13 | } 14 | 15 | # Find file functions 16 | # https://github.com/adsr/dotfiles/blob/master/bashrc 17 | function ff() { local IFS='*'; local patt="$*"; find . -iwholename "*${patt}*"; } 18 | function fo() { ff "$@" | head -n1; } 19 | function fd() { local IFS='*'; local patt="$*"; find . -type d -iname "*${patt}*"; } 20 | function fcd() { local d=$(fd "$@" | head -n1); [ -n "$d" ] && cd "$d"; } 21 | 22 | # Emulate the "pbcopy" and "pbpaste" commands from Mac OS X 23 | if ! [ -x "$(command -v xclip)" ]; then 24 | sudo apt install -y xclip 25 | fi 26 | alias pbcopy='xclip -selection clipboard' 27 | alias pbpaste='xclip -selection clipboard -o' 28 | 29 | # Extract common archive files by file extension 30 | function extract() { 31 | if [ -f $1 ] ; then 32 | case $1 in 33 | *.tar.gz|*.tgz) tar xzf $1 ;; 34 | *.tar|*.tar.xz) tar xf $1 ;; 35 | *.tar.bz2|*.tbz2) tar xjf $1 ;; 36 | *.xz) unxz $1 ;; 37 | *.zip) unzip $1 ;; 38 | *.Z) uncompress $1 ;; 39 | *.tar.zst) tar -I=unzstd xf $1 ;; 40 | *.zst) unzstd $1 ;; 41 | *.7z) 7z x $1 ;; 42 | esac 43 | else 44 | echo "'$1' is not valid archive file." 45 | fi 46 | } 47 | 48 | # Colorize output of man command 49 | # http://tuxdiary.com/2016/06/16/color-man-pages/#more-27324 50 | # https://hunden.linuxkompis.se/2021/02/17/coloured-manual-pages.html 51 | function man() { 52 | env \ 53 | LESS_TERMCAP_mb=$'\e[01;31m' \ 54 | LESS_TERMCAP_md=$'\e[01;31m' \ 55 | LESS_TERMCAP_me=$'\e[0m' \ 56 | LESS_TERMCAP_se=$'\e[0m' \ 57 | LESS_TERMCAP_so=$'\e[01;44;33m' \ 58 | LESS_TERMCAP_ue=$'\e[0m' \ 59 | LESS_TERMCAP_us=$'\e[01;32m' \ 60 | man "$@" 61 | } 62 | 63 | # Create a directory and change to it 64 | function mcd() { 65 | mkdir -pv $1 66 | cd $1 67 | } 68 | 69 | # Use xdg-open in a subshell, derived output and detached 70 | function open() { 71 | (nohup xdg-open "$1" >/dev/null 2>&1 &) 72 | } 73 | 74 | # Get latest statistics for COVID-19 in USA 75 | function coronavirus_cases() { 76 | curl -s https://corona-stats.online/GT?minimal=true | head -n 3 | awk '{ print $2 $3 "\t"$5 "\t"$6 "\t" $7 "\t" $8 $9 "\t" $10 $11 }' 77 | } 78 | 79 | # Generate a random alphanumeric password 80 | function genpass() { 81 | local passlen=${1:-32} # Default length is 32 characters 82 | LC_ALL=C tr -cd '[:alnum:]' < /dev/urandom | fold -w $passlen | head -n1 83 | } 84 | 85 | # Display headers from a web site/URL (requires cURL) 86 | function headers() { 87 | curl -sv "$@" 2>&1 >/dev/null | 88 | grep -v "^\*" | 89 | grep -v "^}" | 90 | cut -c3- 91 | } 92 | 93 | # Simple command-line calculator 94 | function = { 95 | # declare -i i=${1:-$( 144 | # https://github.com/cgoldberg/dotfiles/blob/master/.bash_aliases#L271 145 | function hs() { 146 | local n="150" 147 | history | grep -i --color=always "$1" | tail -n "$n" 148 | } 149 | 150 | # Convert input string to all only lowercase alphanumeric characters separated with hyphens 151 | # https://github.com/SixArm/sixarm-unix-shell-functions 152 | function slugify() { 153 | printf %s\\n "$*" | sed 's/[^[:alnum:]]/_/g; s/--*/-/; s/^-*//; s/-*$//;' | tr '[[:upper:]]' '[[:lower:]]' 154 | } 155 | 156 | # Convert input string to all only alphanumeric characters separated with underscores 157 | # https://github.com/SixArm/sixarm-unix-shell-functions 158 | function snake_format() { 159 | printf %s\\n "$*" | sed 's/[^[:alnum:]]\{1,\}/_/g; s/_\{2,\}/_/g; s/^_\{1,\}//; s/_\{1,\}$//;' 160 | } 161 | 162 | # List files in current directory and sub-directories displayed as a tree 163 | # https://github.com/SixArm/sixarm_unix_shell_scripts/blob/main/ls-tree 164 | function lstree() { 165 | ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' 166 | } 167 | 168 | # Convert between JSON and YAML 169 | # http://github.com/frgomes/bash-scripts 170 | function json2yaml { 171 | python -c 'import sys, yaml, json; print(yaml.dump(json.loads(sys.stdin.read())))' 172 | } 173 | 174 | function yaml2json { 175 | python -c 'import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin.read())))' 176 | } 177 | 178 | # Print display of terminal foreground and background colors with legend. 179 | # https://github.com/mathaou/dotfiles/blob/master/.bashrc 180 | function colors() { 181 | local fgc bgc vals seq0 182 | 183 | printf "Color escapes are %s\n" '\e[${value};...;${value}m' 184 | printf "Values 30..37 are \e[33mforeground colors\e[m\n" 185 | printf "Values 40..47 are \e[43mbackground colors\e[m\n" 186 | printf "Value 1 gives a \e[1mbold-faced look\e[m\n\n" 187 | 188 | # foreground colors 189 | for fgc in {30..37}; do 190 | # background colors 191 | for bgc in {40..47}; do 192 | fgc=${fgc#37} # white 193 | bgc=${bgc#40} # black 194 | 195 | vals="${fgc:+$fgc;}${bgc}" 196 | vals=${vals%%;} 197 | 198 | seq0="${vals:+\e[${vals}m}" 199 | printf " %-9s" "${seq0:-(default)}" 200 | printf " ${seq0}TEXT\e[m" 201 | printf " \e[${vals:+${vals+$vals;}}1mBOLD\e[m" 202 | done 203 | echo; echo 204 | done 205 | } 206 | 207 | # Experimental command-line search engine 208 | # Example: rip "q=software testing" 209 | # alias rip="curl -G -H 'Accept: text/plain' --url https://dontbeevil.rip/search --data-urlencode " 210 | 211 | #alias ls='ls --group-directories-first --time-style=+"%m/%d/%Y %H:%M" --color=auto -F' 212 | #alias ll='ls -lrt --group-directories-first --time-style=+"%m/%d/%Y %H:%M" --color=auto -F' 213 | #alias la='ls -la --group-directories-first --time-style=+"%m/%d/%Y %H:%M" --color=auto -F' 214 | # octal file modes through http://stackoverflow.com/questions/1795976/can-the-unix-list-command-ls-output-numerical-chmod-permissions 215 | #alias lsoct='ls -al --color=auto|awk '\''{k=0;s=0;for(i=0;i<=8;i++){;k+=((substr($1,i+2,1)~/[rwxst]/)*2^(8-i));};j=4;for(i=4;i<=10;i+=3){;s+=((substr($1,i,1)~/[stST]/)*j);j/=2;};if(k){;printf("%0o%0o ",s,k);};print;}'\''' 216 | 217 | # System functions 218 | # https://www.digitalocean.com/community/tutorials/an-introduction-to-useful-bash-aliases-and-functions 219 | alias df="df -Tha --total" 220 | alias du="du -ach | sort -h" 221 | alias pl="ps -eH -o user,pid,ppid,pgid,%cpu,%mem,vsz,rss,tty,stat,etime,args | less -S" # process list 222 | alias path='printf "%b\n" "${PATH//:/\\n}"' # Pretty print $PATH 223 | 224 | alias rm='rm -i -v' 225 | alias cp='cp -v' 226 | alias mv='mv -v' 227 | alias mkdir='mkdir -pv' 228 | alias top='htop' 229 | alias apt-version='apt-cache madison' 230 | alias more='less' 231 | 232 | # Copy public and private SSH keys to clipboard 233 | alias pubkey="more ~/.ssh/id_ed25519.pub | pbcopy | echo ' => Public key copied to clipboard.'" 234 | alias prikey="more ~/.ssh/id_ed25519 | pbcopy | echo ' => Private key copied to clipboard.'" 235 | 236 | # Colorize output of ip command 237 | alias ip='ip -c' 238 | 239 | # Get public IP address 240 | alias publicip='curl https://ipecho.net/plain; echo' 241 | 242 | # Another method to get public IP using 'dig' 243 | alias ext_ip="dig +short myip.opendns.com @resolver1.opendns.com" 244 | 245 | # Get local IP address 246 | # https://github.com/jpbruinsslot/dotfiles/blob/master/files/alias/.alias 247 | alias localip="sudo ifconfig | grep -Eo 'inet (addr:)?([0-9]*\\.){3}[0-9]*' | grep -Eo '([0-9]*\\.){3}[0-9]*' | grep -v '127.0.0.1'" 248 | 249 | # Show WiFi access points 250 | alias wifi_ap="nmcli dev wifi list" 251 | 252 | # View HTTP traffic 253 | # https://github.com/lacymorrow/dotfiles/blob/master/.aliases 254 | alias sniff="sudo ngrep -d 'eth0' -t '^(GET|POST) ' 'tcp and port 80'" 255 | alias httpdump="sudo tcpdump -i eth0 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\"" 256 | 257 | # Searchable 'ps' command alias 258 | alias psg="ps aux | grep -v grep | grep -i -e VSZ -e" 259 | 260 | # Summary of top 10 commands from history 261 | alias hist_summary='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' 262 | 263 | alias hist_summary2="history | awk {'print $2, $3, $4'} | sort | uniq -c | sort -k1 -rn | head -n 30" 264 | 265 | alias dateiso='date -u +"%Y-%m-%dT%H:%M:%SZ"' 266 | 267 | # Run nano with sudo using current user's .nanorc. 268 | alias snano="sudo nano --rcfile=~/.nanorc " 269 | # Git aliases 270 | alias gitlog='git log --all --decorate --graph --oneline' 271 | alias glog="git log --graph --pretty=format:'%Cred%h%Creset %an: %s - %Creset %C(yellow)%d%Creset %Cgreen(%cr)%Creset' --abbrev-commit --date=relative" 272 | # Undo last commit, but don't throw away your changes. 273 | alias git-undo="git reset --soft HEAD^" 274 | 275 | # Run Docker GUI application in container. 276 | # Specify the Docker container name on command line. 277 | # Ensure that 'xhost' has been run prior to enable permissions to X11 display. 278 | alias d-run="docker run --rm -it --net=host --cpuset-cpus 0 --memory 512mb -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY " 279 | 280 | # Open a random 'man' page - Great way to learn new commands 281 | alias randman="apropos . | shuf -n 1 | awk '{print$1}' | xargs man" 282 | 283 | # Display information about Linux distribution, package management, etc. 284 | alias distinfo="echo /etc/*_ver* /etc/*-rel*; cat /etc/*_ver* /etc/*-rel*" 285 | 286 | # URL-encode strings 287 | alias urlencode='python2 -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"' 288 | 289 | # Set some helpful defaults for nano 290 | alias nano='nano --smarthome --multibuffer --const --autoindent --suspend --linenumbers' 291 | 292 | # APT (Auto Package Tool) aliases 293 | alias apt-clean="sudo apt autoremove -f && sudo apt autoclean && sudo apt clean" 294 | 295 | # Functionalize 'command -v' to allow 'if get_command [command]' idiom 296 | # https://github.com/rawiriblundell/dotfiles/blob/master/.bashrc 297 | get_command() { 298 | local errcount cmd 299 | case "${1}" in 300 | (-v|--verbose) 301 | shift 1 302 | errcount=0 303 | for cmd in "${@}"; do 304 | command -v "${cmd}" || 305 | { printf -- '%s\n' "${cmd} not found"; (( errcount++ )); } 306 | done 307 | (( errcount == 0 )) && return 0 308 | ;; 309 | ('') 310 | printf -- '%s\n' "get_command [-v|--verbose] list of commands" \ 311 | "get_command will emit return code 1 if any listed command is not found" >&2 312 | return 0 313 | ;; 314 | (*) 315 | errcount=0 316 | for cmd in "${@}"; do 317 | command -v "${1}" >/dev/null 2>&1 || (( errcount++ )) 318 | done 319 | (( errcount == 0 )) && return 0 320 | ;; 321 | esac 322 | # If we get to this point, we've failed 323 | return 1 324 | } 325 | alias exists="get_command" 326 | alias is_command="get_command" 327 | 328 | # Always run these commands with 'sudo' 329 | for cmd in apt-get apt-cache update-grub shutdown reboot ; do 330 | alias $cmd="sudo $cmd" 331 | done; unset cmd 332 | 333 | # Use Neovim for Vim, if available 334 | [ -x "$(command -v nvim)" ] && alias vim="nvim" vimdiff="nvim -d" 335 | 336 | # `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring 337 | # the `.git` directory, listing directories first. The output gets piped into 338 | # `less` with options to preserve color and line numbers, unless the output is 339 | # small enough for one screen. 340 | function tre() { 341 | tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX 342 | } 343 | 344 | # Show basic information from Wikipedia on command-line topic 345 | # Requires 'jq'. (Install with 'sudo apt-get install -y jq'.) 346 | function wikip() { 347 | LANG="en" 348 | if [[ -z $1 ]]; then 349 | echo -e "No argument specified.\nUsage: wikip TOPIC\n" 350 | else 351 | var=$(echo $* | sed 's/ /_/g') # Transforms 'One Time' to 'One_Time' 352 | wiki_data=$(curl -s "https://"$LANG".m.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&titles="$var"&redirects" | jq '.query.pages | to_entries[0] | .value.extract') 353 | data=$(echo $wiki_data | sed 's/\\\"/"/g') # Removes \" characters 354 | if [[ $data = "null" ]]; then 355 | echo "Nothing found. Check query/topic." 356 | else 357 | url="https://en.m.wikipedia.org/wiki/"$var 358 | echo -e ${data:1:${#data}-2}"\n" 359 | echo "See more on "$url 360 | fi 361 | fi 362 | } 363 | 364 | # Create 7z archive with some reasonable defaults 365 | function 7za() { 366 | 7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on $@ 367 | } 368 | 369 | # Clean file names using various rules 370 | function clean_file_names() { 371 | for i in "$@" 372 | do 373 | b=$(\ 374 | echo "$i" | \ 375 | sed \ 376 | -e 's%([^()]*)%%g' -e '# Remove all parentheses' \ 377 | -e's%[♪▶♫♥"»«"]\+%%g' -e '# Removes one or more of various unwanted characters' \ 378 | -e "s%[,']\+%%g" -e '# Remove commas and single quotes' \ 379 | -e "s%\.\+%.%g" -e '# convert multiple consecutive periods into single period' \ 380 | -e "s%[:»]\+%_%g" -e '# convert multiple these unwanted characters into single _' \ 381 | -e "s%&%_and_%g" -e '# convert ampersand ("&") to "_and_"' \ 382 | -e's%^[-_\. ]\+%%' -e '# Remove dashes, periods, and spaces at beginning' \ 383 | -e's%-\+%-%g' -e '# convert multiple consecutive dashes into one dash' \ 384 | -e's%_\{2,99\}%__%g' -e '# convert multiple underscores to one __.' \ 385 | -e's%\(_-\)\+_%_-_%g' -e '# convert multiple _-_-_ to one __' \ 386 | -e's% \+% %g' -e '# convert multiple spaces to one space' \ 387 | -e's% - YouTube%%g' \ 388 | -e's%[-_ ]\+\(\.[^\.]\+\)$%\1%g' -e'# Remove spaces, periods, dashes, etc. before suffix/extension' \ 389 | -e's%[-_\. ]\+$%%' -e'# Remove dashes, periods, or whitespace at end (after extension)' \ 390 | ) 391 | c=$( echo "$i" | sed -e's%"%\\"%g') 392 | [ "$i" != "$b" ] && echo "mv -v -- \"$c\" \"$b\"" 393 | done 394 | } 395 | 396 | function sysinfo() { 397 | IFS=" " read LOAD1 LOAD5 LOAD15 <<<$(cat /proc/loadavg | awk '{ print $1,$2,$3 }') 398 | # get free memory 399 | IFS=" " read USED AVAIL TOTAL <<<$(free -htm | grep "Mem" | awk {'print $3,$7,$2'}) 400 | # get processes 401 | PROCESS=`ps -eo user=|sort|uniq -c | awk '{ print $2 " " $1 }'` 402 | PROCESS_ALL=`echo "$PROCESS"| awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'` 403 | PROCESS_ROOT=`echo "$PROCESS"| grep root | awk {'print $2'}` 404 | PROCESS_USER=`echo "$PROCESS"| grep -v root | awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'` 405 | # get processors 406 | PROCESSOR_NAME=`grep "model name" /proc/cpuinfo | cut -d ' ' -f3- | awk {'print $0'} | head -1` 407 | PROCESSOR_COUNT=`grep -ioP 'processor\t:' /proc/cpuinfo | wc -l` 408 | 409 | W="\e[0;39m" 410 | G="\e[1;32m" 411 | 412 | temp="" 413 | if [ -x "$(command -v landscape-sysinfo)" ]; then 414 | temp=$(landscape-sysinfo --sysinfo-plugins Temperature | sed 's/ *$//g' | sed 's/Temperature: //g') 415 | fi 416 | 417 | echo -e " 418 | ${W}system info: 419 | $W Distro : $W`cat /etc/*release | grep "PRETTY_NAME" | cut -d "=" -f 2- | sed 's/"//g'` 420 | $W Kernel : $W`uname -sr` 421 | $W Uptime : $W`uptime -p` 422 | $W Load : $G$LOAD1$W (1m), $G$LOAD5$W (5m), $G$LOAD15$W (15m) 423 | $W Processes :$W $G$PROCESS_ROOT$W (root), $G$PROCESS_USER$W (user), $G$PROCESS_ALL$W (total) 424 | $W CPU : $W$PROCESSOR_NAME ($G$PROCESSOR_COUNT$W vCPU) 425 | $W Memory : $G$USED$W used, $G$AVAIL$W avail, $G$TOTAL$W total$W" 426 | temp="" 427 | if [ -x "$(command -v landscape-sysinfo)" ]; then 428 | temp=$(landscape-sysinfo --sysinfo-plugins Temperature | sed 's/Temperature: //g' | sed 's/^ *//g') 429 | fi 430 | if [ -z "$temp" ]; then 431 | echo -e "$W Temperature : $W$G$temp$W" 432 | fi 433 | } 434 | 435 | # Convert datetime to Unix epoch timestamp 436 | # Examples: 437 | # $ date2epoch "2021-03-01 00:00:00+0600" 438 | # 1614535200 439 | # 440 | # $ date2epoch # Shows current time 441 | # 1640213943 442 | # https://github.com/thombashi/dotfiles/blob/master/.functions.sh 443 | date2epoch() { 444 | if [ "$1" != "" ]; then 445 | \date +%s -d "$1" 446 | else 447 | \date +%s 448 | fi 449 | } 450 | 451 | # Convert Unix epoch timestamp to datetime 452 | # Example: 453 | # $ epoch2date 1234567890 454 | # 2009-02-13 17:31:30-06:00 455 | # 456 | # https://github.com/thombashi/dotfiles/blob/master/.functions.sh 457 | epoch2date() { 458 | if [ "$1" == "" ]; then 459 | echo "Usage: ${FUNCNAME[0]} EPOCH_TIME" 1>&2 460 | return 22 461 | fi 462 | 463 | \date -d @"$1" --rfc-3339=seconds 464 | } 465 | 466 | # Create and attach to new tmux session with specified parameters. 467 | # Defaults to session named "new" in ${HOME} directory with window 468 | # named "main". 469 | # 470 | # https://tech.serhatteker.com/post/2022-02/tmux-new-session/ 471 | # 472 | # Usage: 473 | # $ tnew 474 | # $ tnew remote ~/path/to/dir 475 | # $ tnew remote ~/path/to/dir window_name 476 | tnew() { 477 | local session_name="${1:-new}" 478 | local session_dir=${2:-~/} 479 | local session_window_name="${3:-main}" 480 | 481 | tmux new-session \ 482 | -d \ 483 | -s ${session_name} \ 484 | -c ${session_dir} \ 485 | -n ${session_window_name} 486 | } 487 | 488 | # Some convenient 'ls' aliases 489 | # detailed list in alphabetical order 490 | alias lss='ls --group-directories-first --color=always --time-style=+"%Y-%m-%d %I:%M:%S %p" -lhF' 491 | # detailed list in reverse time order 492 | alias ltr='ls --group-directories-first --color=always --time-style=+"%Y-%m-%d %I:%M:%S %p" -lhFtr' 493 | # simple list in reverse time order 494 | alias 1tr='ls --group-directories-first --color=always -1Ftr' 495 | # just filenames in alphabetical order 496 | alias lsf='ls --group-directories-first --color=always -F' 497 | 498 | # Add an "alert" alias for long-running command. 499 | # Usage: sleep 10; alert 500 | 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$//'\'')"' 501 | 502 | # Get IPv4 address of specified interface (e.g., "eth0"). 503 | ipv4_addr() { 504 | ip addr show $1 | grep 'inet ' | awk '{ print $2; }' | sed 's/\/.*$//' 505 | } 506 | -------------------------------------------------------------------------------- /.nanorc: -------------------------------------------------------------------------------- 1 | # References 2 | # https://bash-prompt.net/guides/nanorc-settings/ 3 | # https://gist.github.com/ShyftXero/a3c481cce0feb57290ddd3288287fc1d 4 | 5 | set atblanks # wrap line at blanks. 6 | set cutfromcursor # CTRL+K cuts from cursor position to end of line. 7 | set nohelp # Disable the help information (CTRL+G to view the help screen). 8 | set softwrap # Enable softwrap of lines. 9 | # set suspend # Enables CTRL+Z to suspend nano. 10 | set tabsize 4 # Sets tab-to-spaces size to 4. 11 | set tabstospaces # Converts TAB key press to spaces. 12 | include "/usr/share/nano/*.nanorc" # Enables the syntax highlighting. 13 | set speller "aspell -x -c" # Sets what spelling utility to use. 14 | set constantshow # Displays useful information e.g. line number and position in the bottom bar. 15 | set linenumbers # Lines are numbered. 16 | set numbercolor green,normal 17 | set casesensitive # Case insensitive search. 18 | set historylog # Save the last 100 history searches for later use. 19 | set positionlog # Saves the cursor position between editing sessions. 20 | set zap # Allows you to highlight text (CTRL+SHIFT+ARROW) and delete it with backspace. 21 | set autoindent # A new line will have the same number of leading spaces as the previous one. 22 | set indicator # Displays a scroll bar on the right that shows the position and size of the current view port. 23 | set minibar # Displays file name and other information in the bottom bar. Removes top bar. 24 | set titlecolor white,blue # white, black, blue, green, red, cyan, yellow, magenta 25 | 26 | # Enable and set a working backup directory 27 | # set backup # Creates backups of your current file. 28 | # set backupdir "~/.cache/nano/backups/" # The location of the backups. 29 | 30 | # Shortcut key bindings 31 | bind ^C copy main # CTRC+C - Copy 32 | bind ^V paste all # CTRL+V - Past 33 | bind ^F whereis all # CTRL+F - Find 34 | bind ^S savefile main # CTRL+S - Save 35 | -------------------------------------------------------------------------------- /.tmux.conf: -------------------------------------------------------------------------------- 1 | # Change prefix to + a (to match "screen") 2 | unbind C-b 3 | # set-option -g prefix C-a 4 | # bind-key C-a send-prefix 5 | set -g prefix C-Space 6 | bind C-Space send-prefix 7 | 8 | set -g default-terminal "screen-256color" # Set to 256 color mode 9 | 10 | set -g history-limit 5000 # Increase history 11 | 12 | # Enable mouse for scrollback buffer. 13 | set -g mouse on 14 | 15 | set-window-option -g mode-keys vi # Use Vim keybindings (instead of Emacs) 16 | bind -T copy-mode-vi v send-keys -X begin-selection 17 | bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard' 18 | 19 | set -g base-index 1 # Start _window_ numbering at 1 20 | set-window -g pane-base-index 1 # Start _pane_ numbering at 1 21 | set -g renumber-windows on # Renumber windows sequentially after closing one 22 | 23 | # More intuitive keyboard shortcuts for window split 24 | # Open new pane in same directory as current pane. 25 | unbind - 26 | bind-key - split-window -v -c '#{pane_current_path}' # horizontal 27 | unbind | 28 | bind-key | split-window -h -c '#{pane_current_path}' # vertical 29 | 30 | # Use Vim keyboard shortcuts for pane navigation 31 | # Note: These keybindings use `-n` meaning "root table", which indicates 32 | # that they do *NOT* require prefix key for activation. 33 | bind-key -n M-h select-pane -L # left 34 | bind-key -n M-j select-pane -U # up 35 | bind-key -n M-k select-pane -D # down 36 | bind-key -n M-l select-pane -R # right 37 | bind > swap-pane -D # swap current pane with next 38 | bind < swap-pane -U # swap current pane with previous 39 | 40 | # https://github.com/nicholaschiasson/dotfiles/blob/master/.tmux.conf 41 | # Use Alt-n and Alt-p keys without prefix to switch windows 42 | bind -n M-p previous-window 43 | bind -n M-n next-window 44 | 45 | # Shift arrow without prefix to switch windows 46 | bind -n S-Left previous-window 47 | bind -n S-Right next-window 48 | 49 | # Close/terminate panes/windows *without* confirmation 50 | unbind K 51 | bind-key K kill-window 52 | unbind k 53 | bind-key k kill-pane 54 | 55 | # Status Bar 56 | set -g status-bg colour4 57 | set -g status-fg colour11 58 | set-window -g window-status-style "fg=cyan,bg=colour234,dim" 59 | set-window -g window-status-current-style "fg=white,bg=colour88,bright" 60 | set-option -g pane-active-border-style "fg=colour238,bg=default" 61 | set-option -g pane-active-border-style "fg=colour1,bg=default" 62 | # Toggle status bar on/off 63 | bind C-s if -F '#{s/off//:status}' 'set status off' 'set status on' 64 | 65 | # Dim inactive panes in when multiple panes in use 66 | # https://github.com/carlmjohnson/dotfiles-public/blob/master/tmux.conf 67 | set-option -g window-style 'bg=colour8' 68 | set-option -g window-active-style 'bg=black' 69 | -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | set nocompatible " Disable Vi compatibility to allow Vim advanced features 2 | 3 | " Allow saving of files as sudo, if forgot to run using sudo. 4 | cmap w!! w !sudo tee > /dev/null % 5 | 6 | " Enable 256 colors 7 | set t_Co=256 8 | 9 | " Show line numbers 10 | set number relativenumber numberwidth=5 11 | 12 | " Wrap text after 80 characters and highlight column 80 13 | set textwidth=80 14 | highlight ColorColumn ctermbg=LightGrey guibg=LightGrey 15 | set colorcolumn=80 16 | set wrap 17 | 18 | " Change color of line numbers for easier reading 19 | highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE 20 | 21 | " Highlight EOL, extends, precedes and special characters like non-breaking spaces, , trailing spaces, etc. 22 | highlight NonText ctermfg=LightGrey guifg=LightGrey 23 | highlight SpecialKey ctermfg=LightGrey guifg=LightGrey 24 | 25 | " Highlight matching parentheses 26 | highlight MatchParen ctermbg=4 27 | set matchpairs=(:),{:},[:] 28 | 29 | " Enable 30 | set backspace=2 31 | 32 | " Convert to 33 | set expandtab 34 | set smarttab 35 | 36 | " Set tab stops to 4 spaces/characters 37 | set tabstop=4 38 | set shiftwidth=4 39 | set softtabstop=4 40 | set shiftround " Automatically round indents to multiple of 'shiftwidth' 41 | 42 | " Display whitespace characters 43 | set list listchars=tab:→⠀,space:· 44 | 45 | " Enable auto-indent 46 | set autoindent smartindent 47 | 48 | " Display command as you type it 49 | set showcmd 50 | 51 | " Show current mode 52 | set showmode 53 | 54 | " Enable syntax highlighting 55 | filetype on 56 | filetype plugin on 57 | syntax enable 58 | 59 | " Enable English spell-checking, but don't check by default 60 | if version >= 700 61 | set spl=en spell 62 | set nospell 63 | endif 64 | 65 | " Enable completion functions 66 | set wildmenu 67 | set wildmode=list:longest,full 68 | 69 | " Enable mouse in console 70 | set mouse=a 71 | 72 | " Disable case-sensitivty 73 | set ignorecase 74 | 75 | " Enable smart case-sensitivity 76 | set smartcase 77 | 78 | " Enable code folding/collapsing 79 | set foldenable 80 | set foldnestmax=10 " 10 nested fold max 81 | set foldlevelstart=10 " open most folds by default 82 | set foldmethod=syntax " fold based on indent level 83 | " space open/closes folds 84 | nnoremap za 85 | 86 | " Remap 'jj' to in INSERT mode 87 | inoremap jj 88 | nnoremap JJJJ 89 | 90 | " Enable incremental search and search highlighting 91 | set incsearch 92 | set hlsearch 93 | map - :nohlsearch " Turn off search highlight with '-' 94 | 95 | " Show status line and format contents 96 | set laststatus=2 97 | " set statusline=%F%m%r%h%w\ (%{&ff}){%Y}\ [%1\ %v][%p%%] 98 | set statusline=%<%f\ " Filename 99 | set statusline+=%w%h%m%r " Options 100 | set statusline+=\ [%{&ff}/%Y] " filetype 101 | set statusline+=\ [%{getcwd()}] " current directory 102 | set statusline+=\ [A=\%03.3b/H=\%02.2B] " ASCII / Hex value of character at cursor 103 | set statusline+=%=%-14.(%l,%c%V%)\ %p%% " Right aligned file position info 104 | 105 | " Create blank lines and stay in NORMAL mode 106 | nnoremap zj o 107 | nnoremap zk O 108 | 109 | " Center window vertically on line of 'next' search result 110 | map N Nzz 111 | map n nzz 112 | 113 | " Put all backup and temporary files in same directory 114 | set backup 115 | set backupdir=~/.vim/backup 116 | set directory=~/.vim/tmp 117 | 118 | " Change to directory contain file when editing 119 | set autochdir 120 | 121 | " Set 1000 commands to undo and save to file 122 | if !isdirectory($HOME."/.vim") 123 | call mkdir($HOME."/.vim", "", 0770) 124 | endif 125 | if !isdirectory($HOME."/.vim/undo-dir") 126 | call mkdir($HOME."/.vim/undo-dir", "", 0700) 127 | endif 128 | set undolevels=1000 129 | set undodir=~/.vim/undo-dir 130 | set undofile 131 | 132 | " Keep at least 4 lines above and below the current line 133 | set scrolloff=4 134 | 135 | " Use +S for "Save" 136 | nnoremap :w 137 | inoremap :w 138 | 139 | " Remove trailing whitespace on save 140 | autocmd BufWritePre * :%s/\s\+$//e 141 | 142 | " Make cursor behave as expected for long lines 143 | inoremap gj 144 | inoremap gk 145 | 146 | " Switch to COMMAND mode from INSERT mode by entering 'ii' 147 | imap ii 148 | 149 | " Remap + to word completion 150 | noremap! 151 | 152 | " Shortcuts for switching between buffers in INSERT mode 153 | map :bprev 154 | map :bnext 155 | 156 | " Highlight the word under cursor 157 | highlight flicker cterm=bold ctermfg=white 158 | au CursorMoved exe 'match flicker /\V\<'.escape(expand(''), '/').'\>/' 159 | 160 | " Allow saving file owned by root if Vim not opened using sudo 161 | " Tip: We use the 'w!!' command to follow pattern from shell of '!!' to 162 | " re-run previous command with sudo. 163 | " https://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work 164 | cmap w!! w !sudo tee > /dev/null % 165 | 166 | " Toggle between regular and relative line numbering when in INSERT mode. 167 | au InsertEnter * :set norelativenumber 168 | au InsertLeave * :set relativenumber 169 | 170 | " Disable auto-indent for top-level HTML tags. 171 | let g:html_indent_autotags = "html,head,body" 172 | 173 | " + arrow navigation 174 | " https://github.com/pyk/dotfiles/blob/master/vim/.vimrc 175 | nmap : wincmd k 176 | nmap : wincmd j 177 | nmap : wincmd h 178 | nmap : wincmd l 179 | 180 | " Strip trailing whitespaces on each save 181 | " https://github.com/hukl/dotfiles/blob/master/.vimrc#L40 182 | fun! StripTrailingWhitespaces() 183 | let l = line(".") 184 | let c = col(".") 185 | %s/\s\+$//e 186 | call cursor(l, c) 187 | endfun 188 | autocmd BufWritePre * :call StripTrailingWhitespaces() 189 | 190 | set splitbelow " Open new split below current buffer. 191 | set splitright " Open new split to right of current buffer. 192 | 193 | " Buffer commands 194 | nmap T :enew " Open a new/empty buffer 195 | nmap l :bnext " Next buffer 196 | nmap h :bprevious " Previous buffer 197 | nmap bq :bp bd # " Close buffer 198 | nmap bl :ls " List open buffers 199 | 200 | " Miscellaneous key bindings 201 | noremap r :source ~/.vim/vimrc " Re-source ~/.vimrc 202 | nnoremap :nohlsearch " Turn off search highlight 203 | 204 | " Display lines longer than 80 characters in red 205 | highlight OverLength ctermbg=red ctermfg=white guibg=#592929 206 | match OverLength /\%81v.\+/ 207 | 208 | " File format-specific settings 209 | " -------------------------------------- 210 | 211 | " YAML 212 | autocmd BufRead,BufNewFile *.yml,*.yaml,*.yaml.txt setlocal filetype=yaml 213 | autocmd FileType yaml setlocal textwidth=64 colorcolumn=65 214 | \ tabstop=2 softtabstop=2 shiftwidth=2 expandtab 215 | 216 | " PYTHON 217 | autocmd BufRead,BufNewFile *.py,*.pyc setlocal filetype=python 218 | autocmd FileType python setlocal textwidth=80 colorcolumn=81 219 | \ tabstop=4 softtabstop=4 shiftwidth=4 expandtab 220 | 221 | " MARKDOWN 222 | autocmd BufRead,BufNewFile *.md,*.mmd,*.mkd,*.mdown,*.markdown,*.markdown.txt setlocal filetype=markdown 223 | autocmd FileType markdown setlocal textwidth=64 colorcolumn=65 spell 224 | 225 | " SHELL 226 | autocmd FileType sh,bash setlocal 227 | \ tabstop=2 softtabstop=2 shiftwidth=2 expandtab 228 | 229 | " HTML 230 | autocmd FileType html setlocal 231 | \ tabstop=2 shiftwidth=2 expandtab 232 | 233 | " JAVASCRIPT 234 | autocmd FileType javascript setlocal 235 | \ tabstop=2 shiftwidth=2 expandtab 236 | 237 | " GOLANG 238 | autocmd FileType go setlocal tabstop=4 shiftwidth=4 noexpandtab 239 | 240 | " CLOJURE 241 | autocmd BufRead,BufNewFile *.clj setlocal filetype=clojure 242 | autocmd FileType clojure setlocal tabstop=2 shiftwidth=2 expandtab 243 | 244 | " HEX EDITING 245 | " vim -b : edit binary using xxd-format! 246 | augroup Binary 247 | au! 248 | au BufReadPre *.bin,*.exe let &bin=1 249 | au BufReadPost *.bin,*.exe if &bin | %!xxd 250 | au BufReadPost *.bin,*.exe setlocal ft=xxd | endif 251 | au BufWritePre *.bin,*.exe if &bin | %!xxd -r 252 | au BufWritePre *.bin,*.exe endif 253 | au BufWritePost *.bin,*.exe if &bin | %!xxd 254 | au BufWritePost *.bin,*.exe setlocal nomod | endif 255 | augroup END 256 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # linux-tips 2 | Collection of tips on Linux (mostly Debian/Ubuntu) helpful to me 3 | 4 | ## Bash Keyboard Shortcuts 5 | | Shortcut | Action | 6 | |:---------|:-------| 7 | | Esc + t | Swap the two _words_ before the cursor | 8 | | Ctrl + r | Search command history | 9 | | Ctrl + g | Cancel command history search without running command | 10 | | Ctrl + l | Clear terminal screen | 11 | | Ctrl + x | List possible filename completions | 12 | | Ctrl + c | Cancels the running command | 13 | | Ctrl + z | Suspends the running command | 14 | | Ctrl + u | Deletes entire line _before_ the cursor | 15 | | Ctrl + k | Deletes entire line _after_ the cursor | 16 | | Ctrl + t | Swap the two characters before the cursor | 17 | | Ctrl + d | Close the terminal | 18 | | Ctrl + f | Go _forward_ one character | 19 | | Ctrl + b | Go _back_ one character | 20 | | Ctrl + a | Go to the _beginning_ of the line | 21 | | Ctrl + e | Go to the _end_ of the line | 22 | | Ctrl + w | Delete the _word_ before the cursor | 23 | | Ctrl + y | Retrieves the last _word_ deleted or cut | 24 | | Ctrl + xx | Toggle between current cursor position and start or end of line | 25 | | Alt + u | Capitalize all letters in word after cursor | 26 | | Alt + l | Lower case all letters in word after cursor | 27 | | Alt + . | Use the last word of the last command | 28 | 29 | [Reference1](https://ostechnix.com/list-useful-bash-keyboard-shortcuts/) 30 | 31 | ## Basic configuration for new Git repository 32 | ```bash 33 | # Set user name and e-mail address (required to do 'commit') 34 | git config [--global] user.email "user@domain.com" 35 | git config [--global] user.name "User Name" 36 | 37 | # Store/cache password 38 | git config [--global] credential.helper store 39 | git pull 40 | 41 | # Set the remote repository (for existing code) 42 | git remote add origin https://github.com/user/repo_name.git 43 | ``` 44 | 45 | ## Add existing user to existing group 46 | ```bash 47 | sudo usermod -a -G groupnames username 48 | ``` 49 | `-a` - append groups to group user belongs to (instead of overwrite). 50 | `groupnames` - a comma-separated (no spaces!) list of group names to add user to. 51 | User must log out and back in for group membership updates to be applied. 52 | [Reference](http://askubuntu.com/a/79566) 53 | 54 | ## Swap the `Caps Lock` and `(Right) Control` keys on keyboard 55 | The level of configurability in Linux is simply amazing. With the venerable [`xmodmap`](https://linux.die.net/man/1/xmodmap) utility, keyboard remapping is a snap. Just add these lines to your `$HOME/.xmodmap` file to swap the `Caps Lock` and `(Right) Control` keys. 56 | ```bash 57 | remove Lock = Caps_Lock 58 | remove Control = Control_R 59 | keysym Control_R = Caps_Lock 60 | keysym Caps_Lock = Control_R 61 | add Lock = Caps_Lock 62 | add Control = Control_R 63 | ``` 64 | 65 | ## Enter Unicode characters with keyboard in Linux 66 | In most applications in Linux, including at the command line, to enter a [Unicode](https://www.rapidtables.com/code/text/unicode-characters.html) character, hold down `` and `` plus _u_ and enter the 2- or 4-character *hexadecimal* Unicode code. When you release `` and ``, the character will be displayed. For example, to enter superscript 2 (²), which is Unicode 00B2, type ``+``+_u_+B2; for the trademark symbol (™), which is Unicode 2122, type ``+``+_u_+2122. Note that you can use the numeric keys across the top of the keyboard or on the numeric keypad (with NumLock enabled). 67 | [Reference1](https://twitter.com/brianredbeard/status/1371862052797517825) 68 | [Reference2](https://old.reddit.com/r/linux/comments/m6dbbm/til_on_linux_one_can_type_arbitrary_unicode/) 69 | 70 | ## Install packages required to build application from source in Ubuntu/Debian 71 | If you want to build an application from source for a new version of an application that has a Ubuntu/Debian package, you can use the `build-dep` utility to install the required dependencies in one go. 72 | ```bash 73 | sudo apt-get build-dep PKG_NAME 74 | ``` 75 | where `PKG_NAME` is the package name, such as `vim-common`. 76 | [Reference](https://wiki.debian.org/BuildingTutorial#Get_the_build_dependencies) 77 | 78 | ## "Safe" alternative to bypassing password prompt for `sudo` 79 | To avoid getting prompted for password when running commands with [`sudo`](https://manpages.ubuntu.com/manpages/precise/en/man8/sudo.8.html), one common option is to append `NOPASSWD:ALL` to your user name in the `/etc/sudoers` file. Obviously, this is a security risk. Instead, you can run the `sudo` command with the `-s` ("session") flag to allow the `sudo` session to be persistent until your close the terminal (end the session). To explicitly end the session run `sudo -k` ("kill"). 80 | [Reference](https://vitux.com/how-to-specify-time-limit-for-a-sudo-session/) 81 | 82 | ## Change default editor for `visudo` 83 | By default, Linux systems use the `$VISUAL` or `$EDITOR` environment variables (usually defined in your `~/.bashrc` file or `/etc/profile`) as the default editor the [`visudo`](https://linux.die.net/man/8/visudo) command. If you'd prefer to use a different editor, such as [nano](https://nano-editor.org/), you can use either of these methods. 84 | 1. To **temporarily** use a different editor, run: 85 | ```console 86 | $ sudo EDITOR=/path/to/editor visudo 87 | ``` 88 | For example, to use `nano`, you would run: 89 | ```console 90 | $ sudo EDITOR=nano visudo 91 | ``` 92 | 2. To **permanently** change the default editor, edit the `/etc/sudoers` file (you can use the _temporary_ method above!) and add the following line to the file near the top, but _after_ `Defaults env_reset`: 93 | ```console 94 | Defaults editor=/path/to/editor 95 | ``` 96 | 97 | [Reference1](https://unix.stackexchange.com/questions/4408/how-to-set-visudo-to-use-a-different-editor-than-the-default-on-fedora) 98 | 99 | ## Upgrade Ubuntu to non-LTS version via command line 100 | By default, most installations of Ubuntu are configured to upgrade only to LTS (long-term support) distribution releases, which come out every two years (e.g., 18.04, 20.04, etc.). If you want to upgrade your Ubuntu installation to a non-LTS release (e.g., from Bionic Beaver [18.04] to Eoan Ermine [19.10]) you can do so via command line. Here's how. 101 | 102 | ### Update current release to latest patches 103 | ```bash 104 | sudo apt-get install update-manager-core -y 105 | sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y 106 | ``` 107 | 108 | ### Update upgrade manager to `normal` (non-LTS) setting 109 | ```bash 110 | sudo sed -i 's/Prompt=lts/Prompt=normal/g' /etc/update-manager/release-upgrades 111 | ``` 112 | 113 | ### Change distribution reference to desired version codename* and disable third-party repositories (PPAs) 114 | ```bash 115 | sudo sed -i 's/bionic/eoan/g' /etc/apt/sources.list 116 | sudo sed -i 's/^/#/' /etc/apt/sources.list.d/*.list 117 | ``` 118 | Replace `bionic` and `eoan` above with the current and desired distribution version codenames, respectively, as appropriate. 119 | *See [here](https://en.wikipedia.org/wiki/Ubuntu_version_history) for list of Ubuntu distribution codenames with associated version numbers. 120 | 121 | ### Run the upgrade, remove unneeded packages, and reboot to complete update 122 | ```bash 123 | echo '* libraries/restart-without-asking boolean true' | sudo debconf-set-selections 124 | sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confnew 125 | sudo apt-get autoremove -f -y && sudo apt-get clean -y 126 | sudo shutdown -r now 127 | ``` 128 | See [this article](https://unix.stackexchange.com/questions/22820/how-to-make-apt-get-accept-new-config-files-in-an-unattended-install-of-debian-f) for details about forcing use of new/package maintainer's version of configuration files. For additional details refer to [this article](https://serverfault.com/a/858361). 129 | 130 | ### Confirm new release version 131 | ```bash 132 | lsb_release -a 133 | ``` 134 | 135 | ### Re-enable third-party repositories (PPAs) and change them to the new version codename 136 | ```bash 137 | sudo sed -i '/deb/s/^#//g' /etc/apt/sources.list.d/*.list 138 | sudo sed -i 's/bionic/eoan/g' /etc/apt/sources.list.d/*.list 139 | sudo apt-get update && sudo apt-get upgrade -y 140 | ``` 141 | If you get any errors that a repository can't be found (e.g., `The repository 'http://linux.dropbox.com/ubuntu eoan Release' does not have a Release file.`), then you will need to revert these individual repositories to the earlier distribution version codename in `/etc/apt/sources.list.d` directory. 142 | 143 | [Reference](https://www.linuxbabe.com/ubuntu/upgrade-ubuntu-18-04-to-ubuntu-19-10-from-command-line) 144 | 145 | ## Bash script to toggle touchpad on and off 146 | If you use an external mouse with your laptop, you probably want to disable your touchpad when the mouse is plugged in. Here's how to create a simple Bash script to toggle the touchpad on and off. 147 | 148 | At the Bash prompt, run this command to list _all_ of your input devices, such as the keyboard, mouse, and touchpad: 149 | ```bash 150 | $ xinput 151 | ⎡ Virtual core pointer id=2 [master pointer (3)] 152 | ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] 153 | ⎜ ↳ USB Optical Mouse id=10 [slave pointer (2)] 154 | ⎜ ↳ **SynPS/2 Synaptics TouchPad id=12** [slave pointer (2)] 155 | ``` 156 | In this example, the touchpad, has device ID **12**. Next, we check the status (enabled or disabled) for this device: 157 | ```bash 158 | $ xinput -list-props 12 | grep "Device Enabled" 159 | Device Enabled (**116**): **1** 160 | ``` 161 | Here, the **1** means that the touchpad is _enabled_. Create a script named `touchpad.sh` with the following contents and replace **12** and **116** with the appropriate values for your machine: 162 | ```bash 163 | #!/bin/bash 164 | if xinput list-props **12** | grep "Device Enabled (**116**):.*1" >/dev/null 165 | then 166 | xinput disable **12** 167 | notify-send -u low -i mouse "Touchpad disabled" 168 | else 169 | xinput enable **12** 170 | notify-send -u low -i mouse "Touchpad enabled" 171 | fi 172 | ``` 173 | Copy `touchpad.sh` to a directory in your `$PATH` and make it executable (`chmod +x touchpad.sh`). Simply run it anytime that you want to toggle the touchpad on or off. 174 | 175 | [Reference](http://tuxdiary.com/2016/08/15/toggle-touchpad-ubuntu-16-04/) 176 | 177 | ## Disable GPG checking for third-party repositories (PPAs) 178 | When using third-party repositories (PPAs), you typically need to install GPG key. If you have trouble with GPG keys, you can configure the repository, in `/etc/apt/sources.list` or the custom configuration file in `/etc/apt/sources.list.d/` by adding `trusted=yes` or `allow-insecure=yes`. The difference between them is that `allow-insecure=yes` will prompt you before allowing you to install, but `trusted=yes` won't. 179 | 180 | For example, here's the setting used with the MongoDB repository: 181 | ```bash 182 | deb [ arch=amd64 `allow-insecure=yes ] http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse 183 | ``` 184 | [Reference](https://unix.stackexchange.com/questions/198000/bypass-gpg-signature-checks-only-for-a-single-repository) 185 | 186 | ## Reset 'root' password for MySQL Server (version 8.0+) 187 | If you install [MySQL Server 8.0](https://dev.mysql.com/doc/refman/8.0/en/) or later in Ubuntu without specifying the `root` password, you can set (reset) it as follows. 188 | 189 | Run `mysql` utility with `root` account without password: 190 | ```bash 191 | sudo mysql 192 | ``` 193 | (Note: This only works if no `root` password is set.) 194 | 195 | At the MySQL prompt, use the [`ALTER USER`](https://dev.mysql.com/doc/refman/8.0/en/alter-user.html) command to set the desired password. It is important to specify the authentication plugin as [`mysql_native_password`](https://dev.mysql.com/doc/refman/8.0/en/native-pluggable-authentication.html) to allow applications such as [phpMyAdmin](https://www.phpmyadmin.net/) to connect (see also [here](https://github.com/phpmyadmin/phpmyadmin/issues/14220)). 196 | ```bash 197 | ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_root_password'; 198 | FLUSH PRIVILEGES; 199 | ``` 200 | 201 | Restart MySQL service: 202 | ```bash 203 | sudo systemctl restart mysql 204 | ``` 205 | 206 | You should now be able to log in to MySQL from command prompt with the new password: 207 | ```bash 208 | mysql -u root -pnew_root_password 209 | ``` 210 | 211 | [Reference](https://askubuntu.com/questions/766900/mysql-doesnt-ask-for-root-password-when-installing/766908#766908) 212 | 213 | ## Mount AWS S3 Bucket Using `s3fs` 214 | `s3fs` is a [FUSE](http://manpages.ubuntu.com/manpages/precise/man8/mount.fuse.8.html) [(File System in Userspace)](https://en.wikipedia.org/wiki/Filesystem_in_Userspace) extension which allows you to mount an Amazon Web Services (AWS) S3 bucket as native local file system. In other words, no specialized tools are required. 215 | 216 | We will use `s3fs` package from the Ubuntu repositories. You can install `s3fs` by building it from source; see [`s3fs` Github repository](https://github.com/s3fs-fuse/s3fs-fuse) for details. 217 | 218 | Switch to the `root` user *before* performing the other steps: 219 | ```bash 220 | sudo su - 221 | ``` 222 | 223 | Install `s3fs`: 224 | ```bash 225 | apt-get install -y s3fs 226 | ``` 227 | 228 | Create the *system* `s3fs` password file using the appropriate AWS S3 credentials (access key ID and secret access key). 229 | ```bash 230 | echo AWS_ACCESS_KEY_ID:AWS_SECRET_ACCESS_KEY > /etc/passwd-s3fs 231 | chmod 600 /etc/passwd-s3fs 232 | ``` 233 | `/etc/passwd-s3fs` can contain multiple sets of credentials (access key ID and secret access key pair combinations) with each on its own line in the file. 234 | 235 | Create file system directories to mount S3 bucket and for caching S3 bucket contents. The cache directory is optional, but will improve performance when using S3 bucket with large number of files. 236 | ```bash 237 | mkdir /tmp/cache 238 | mkdir /mnt/s3-bucket 239 | chmod 777 /tmp/cache /mnt/s3-bucket 240 | ``` 241 | 242 | Mount the S3 bucket using `s3fs`. (Note: This mount is temporary/non-persistent. See below for mounting the file system on boot using `/etc/fstab`.) 243 | ```bash 244 | s3fs s3-bucket-name /mnt/s3-bucket -o passwd_file=/etc/passwd-s3fs -o allow_other,use_cache=/tmp/cache 245 | ``` 246 | Replace `s3-bucket-name` with the desired S3 bucket for the credentials specified in `/etc/passwd-s3fs` from above. Note that `rw` means to mount the file system as "read-write" (the default setting); if you want to mount as "read-only", change this to `ro`. 247 | 248 | Test the S3 bucket file system mount. You should see a "standard" file system listing. And, of course, you can use GUI file managers by navigating to `/mnt/s3-bucket`. 249 | ```bash 250 | ls -lrt /mnt/s3-bucket 251 | ``` 252 | 253 | To mount the S3 bucket as your (non-root) user ID, at a *regular* (non-root) command prompt run `id ${USER}`. You should see something *like*: 254 | ```bash 255 | id ${USER} 256 | uid=1000(tim) gid=1000(tim) groups=1000(tim),4(adm),24(cdrom),27(sudo),30(dip),33(www-data),46(plugdev),107(input),121(lpadmin),131(lxd),133(sambashare),998(docker) 257 | ``` 258 | Use the `uid` and `gid` values above to run `s3fs`: 259 | ```bash 260 | s3fs s3-bucket-name /mnt/s3-bucket -o passwd_file=/etc/passwd-s3fs -o allow_other,use_cache=/tmp/cache,uid=1000,umask=077,gid=1000 261 | ``` 262 | If you get an error about not being allowed to use `allow_other` as regular user, you will need to uncomment the `user_allow_other` line in `/etc/fuse.conf` FUSE configuration file. 263 | 264 | To configure your system to automatically ("permanently") mount the S3 bucket when it boots, do the following. (This assumes that you are still logged in as `root` user.) 265 | ```bash 266 | echo s3fs#s3-bucket-name /mnt/s3-bucket fuse _netdev,rw,nosuid,nodev,allow_other,nonempty,uid=1000,umask=077,uid=1000 0 0 >> /etc/fstab 267 | ``` 268 | Mount (re-mount) the file system to ensure that it works properly. 269 | ```bash 270 | mount -a 271 | ``` 272 | 273 | That\'s it! Now you can transparently work with your S3 buckets just like they are local files. 274 | 275 | 276 | [Reference1](https://sysadminxpert.com/how-to-mount-s3-bucket-on-linux-instance/) 277 | [Reference2](https://winscp.net/eng/docs/guide_amazon_s3_sftp#mounting) 278 | 279 | ## Fix HP Pavilion Laptop lockup/freeze problem on idle/inactivity in Linux 280 | Some HP Pavilion laptops experience problems with freezing after inactivity timeouts or other idle conditions. Some or all of the following items can _help_ prevent such problems. 281 | 282 | - Disable power saving features. 283 | - Disable screensaver and screen lock features. 284 | - Add [kernel boot parameters](https://wiki.ubuntu.com/Kernel/KernelBootParameters) to GRUB boot menu options. 285 | - `noapic` - Disable APIC (Advanced Programmable Interrupt Controller) support. 286 | - `idle=nomwait` - Disable "mwait" for CPU idle state. 287 | 288 | 289 | [Reference1](https://stackoverflow.com/questions/53001737/what-do-boot-option-noapic-and-noacpi-actually-do) 290 | 291 | ## Display time and time zone details for system 292 | For a quick check of the time and time zone details of your Linux system, run the _`timedatectl`_ command. It will show you the current local time, UTC time, RTC (real-time clock from BIOS) and the time zone, along with some additional details. The command can also be used to change these settings. See the [_`timedatectl`_](https://man7.org/linux/man-pages/man1/timedatectl.1.html) `man` page for more information. 293 | 294 | *** 295 | 296 | ## Show processor architecture information and use in shell script 297 | Many times in a shell script, you may need to differentiate between whether your Linux platform is 32-bit or 64-bit and which processor type/architecture is used. Here are a few commands you can use to get such information. 298 | 299 | | Command | Flags | Action | Example Output | 300 | | :------ | :---- | :----- | :------------- | 301 | | `uname` | `-m` | Display machine hardware name | `x86_64` or `i686`| 302 | | `arch` | | Alias for `uname -m` | `x86_64` | 303 | | `dpkg` | `--print-architecture` | Display machine/platform architecture (Debian/Ubuntu) | `amd64`, `arm64`, `i386` | 304 | | `dpkg-architecture` | `--query DEB_BUILD_**ARCH**_CPU` | Display machine/platform architecture (Debian/Ubuntu) | `amd64`, `arm64`, `i386` | 305 | | `dpkg-architecture` | `--query DEB_BUILD_**GNU**_CPU` | Display GNU architecture | `x86`, `x86_64` | 306 | | `nproc` | | Display number of CPU cores | `4` | 307 | | `getconf` | `LONG_BIT` | Displays 32 or 64, depending on address bus | `64` | 308 | | `lscpu` | | Detailed information about CPU | N/A | 309 | | `lshw` | `-C CPU` | Summary information about CPU | N/A | 310 | 311 | [Reference1](https://www.tecmint.com/check-linux-cpu-information/) 312 | [Reference2](https://www.linuxtechi.com/server-cpu-architecture-linux/) 313 | [Reference3](https://stackoverflow.com/questions/45125516/possible-values-for-uname-m/45125525#45125525) 314 | 315 | ## Tidy up your Linux command line history with `HISTIGNORE` 316 | If you use the Linux command line often, one of the greatest features is the [`history`](https://www.man7.org/linux/man-pages/man3/history.3.html) of commands run. Simply press the up and down arrows to navigate backward and forward through the commands or hit Ctrl+R to search. However, if you navigate around a lot and list directory contents, your history can filled with extra commands that you aren't likely to want to from history, since they are simple enough to just run again. To prevent history from adding these to your command history, just add the `HISTIGNORE` variable to your `.bashrc` with a list of the commands to ignore separated with colons (`:`). Here's an example: 317 | ```bash 318 | HISTIGNORE="ls:ls -lrt:[bf]g:history*:exit:*shutdown*:*reboot*:[ \t]*" 319 | ``` 320 | In this example, we ignore `ls` by itself and `ls -lrt`, the `bg` and `fg` commands, `exit`, and anything _starting with_ `history`. Likewise, you can see that we've included "dangerous" commands like `shutdown` and `reboot` that we probably don't want to accidentally run when quickly scrolling through a long history list. And, finally, `[ \t]*` means to ignore any command that you enter that starts with a Space or Tab so that you can selectively run a command and have it ignored in the history. 321 | 322 | ## Configure remote access on Ubuntu with XRDP 323 | Historically, remote access on Linux was handled through the [VNC (Virtual Network Computing)](https://en.m.wikipedia.org/wiki/Virtual_Network_Computing) platform, such as with [x11vnc](https://github.com/LibVNC/x11vnc). However, recently, the [Remote Desktop Protocol (RDP)](https://en.m.wikipedia.org/wiki/Remote_Desktop_Protocol) developed for Microsoft Windows has gained popularity on Linux using the [XRDP](https://xrdp.org/) tool. Here's how to set it up on Ubuntu. 324 | 325 | 1. Install XRDP from the Ubuntu repositories. 326 | ``` 327 | $ sudo apt-get install -y xrdp dbus-x11 328 | ``` 329 | 2. After installation, Ubuntu will automatically launch the XRDP service. To confirm that it launched properly, run: 330 | ``` 331 | $ sudo systemctl status xrdp 332 | ``` 333 | You should see output similar to the following. The main thing to confirm is that it shows that the service is `active (running)` next to `Active`. 334 | ``` 335 | ● xrdp.service - xrdp daemon 336 | Loaded: loaded (/lib/systemd/system/xrdp.service; enabled; vendor prese> 337 | Active: active (running) since Thu 2021-07-22 06:37:19 CDT; 29min ago 338 | Docs: man:xrdp(8) 339 | man:xrdp.ini(5) 340 | Process: 58107 ExecStartPre=/bin/sh /usr/share/xrdp/socksetup (code=exit> 341 | Process: 58115 ExecStart=/usr/sbin/xrdp $XRDP_OPTIONS (code=exited, stat> 342 | Main PID: 58116 (xrdp) 343 | Tasks: 2 (limit: 8740) 344 | Memory: 16.6M 345 | CGroup: /system.slice/xrdp.service 346 | ├─58116 /usr/sbin/xrdp 347 | └─58124 /usr/sbin/xrdp 348 | ``` 349 | 3. XRDP uses the `/etc/ssl/private/ssl-cert-snakeoil.key` SSL certificate file for authentication. Access to this file is limited to members of the `ssl-cert` group, so we must add the `xrdp` user to that group with this command: 350 | ``` 351 | $ sudo adduser xrdp ssl-cert 352 | ``` 353 | 4. To ensure that XRDP service is enabled, so that it starts on system boot, run: 354 | ``` 355 | $ sudo systemctl enable xrdp 356 | ``` 357 | As in step #2 above, you can check the status again to ensure that it's running and `enabled`. 358 | 5. To avoid an authentication warning on the Ubuntu machine after logging in (see step #5 below), we must add a [Policy Kit](https://www.freedesktop.org/software/polkit/docs/latest/) rule, as indicated below. 359 | ``` 360 | $ sudo nano /etc/polkit-1/localauthority.conf.d/02-allow-colord.conf 361 | 362 | polkit.addRule(function(action, subject) { 363 | if ((action.id == "org.freedesktop.color-manager.create-device" || action.id == "org.freedesktop.color-manager.create-profile" || action.id == "org.freedesktop.color-manager.delete-device" || action.id == "org.freedesktop.color-manager.delete-profile" || action.id == "org.freedesktop.color-manager.modify-device" || action.id == "org.freedesktop.color-manager.modify-profile") && subject.isInGroup("{group}")) 364 | { 365 | return polkit.Result.YES; 366 | } 367 | }); 368 | ``` 369 | Restart the xrdp service for the change to take effect. 370 | ``` 371 | $ sudo systemctl restart xrdp 372 | ``` 373 | 6. Connect to your Ubuntu machine from another machine. If you are connecting from a Windows machine, you can use the standard Remote Desktop client (Start --> Windows Accessories --> Remote Desktop Connection _or_ Start --> Run --> mstsc.exe). Enter the IP address or hostname of your Ubuntu machine to connect. In a few seconds, you'll be prompted to log in; log in using the same **Ubuntu** username and password that you usually use. (You may also be prompted about SSL certificate validation, which you will need to accept.) 374 | 375 | For connecting from another Ubuntu (or other Linux) machine, there are various RDP clients that you can use, including: 376 | - [Remmina](https://remmina.org/)* 377 | - [Vinagre](https://wiki.gnome.org/Apps/Vinagre)* 378 | - [TigerVNC](https://tigervnc.org/)* - To use TigerVNC with RDP, enter the IP address or hostname in the _viewer_ connection window followed by **:3389**. This means to connect on TCP port 3389, which is the port that RDP listens on. 379 | - [KRDC](https://apps.kde.org/krdc/)* 380 | - [X2Go](https://wiki.x2go.org/doku.php)* 381 | *Indicates that these are available in standard Ubuntu repositories (i.e., install using `sudo apt-get install`). 382 | 7. If you get a black (blank) screen on the remote machine after logging in remotely, you'll need to make a simple adjustment on the Ubuntu machine (the one that you are accessing remotely) in the script to launches the X11 window manager for XRDP. Do the following: 383 | ``` 384 | sudo nano /etc/xrdp/startwm.sh 385 | ``` 386 | Add the lines below right _below/after_ `if` block concerning `/etc/profile` near the bottom of the file. 387 | ``` 388 | unset DBUS_SESSION_BUS_ADDRESS 389 | unset XDG_RUNTIME_DIR 390 | ``` 391 | After making the change, the file should looking something like this: 392 | ``` 393 | ... 394 | if test -r /etc/profile; then 395 | . /etc/profile 396 | fi 397 | 398 | unset DBUS_SESSION_BUS_ADDRESS 399 | unset XDG_RUNTIME_DIR 400 | 401 | test -x /etc/X11/Xsession && exec /etc/X11/Xsession 402 | exec /bin/sh /etc/X11/Xsession 403 | ``` 404 | Finally, restart and enable the `xrdp` service to ensure the change takes effect. 405 | 406 | [Reference1](https://linuxize.com/post/how-to-install-xrdp-on-ubuntu-18-04/) 407 | [Reference2](https://www.tecmint.com/install-xrdp-on-ubuntu/) 408 | [Reference3](https://linoxide.com/xrdp-connect-ubuntu-linux-remote-desktop-via-rdp-from-windows/) 409 | 410 | ## Prevent laptop from suspending when closing lid in Linux 411 | If you have an old laptop that you typically access remotely (i.e., via VNC or RDP), then usually you will want to close the lid, but not have the device suspend, so that you can still connect remotely. Some Linux desktop environments (DE) have GUI options to do this, but many don't and, even those that do, use a variety of different techniques (e.g., power management, login, etc.). Here's the most reliable way to do it. 412 | 1. Edit the `logind` service configuration file as root. 413 | ``` 414 | $ sudo nano /etc/systemd/logind.conf 415 | ``` 416 | 2. Locate the lines under `[Login]` section that _start_ with `HandleLidSwitch` and uncomment them (remove the `#` at the start of the line, if any) and set the value to either `lock` (preferred) or `ignore`. (The current values, as commented out, are the defaults.) The `lock` setting will turn off the display and lock the machine, which will require you to enter your password when you open the lid, while `ignore` does nothing when you close the lid. 417 | ``` 418 | HandleLidSwitch=lock 419 | HandleLidSwitchExternalPower=lock 420 | HandleLidSwitchDocked=ignore 421 | ``` 422 | 3. Save the file and _reboot_ the machine for the changes to take effect. (You can actually just restart the `logind` service \[i.e., `sudo systemctl restart logind`\]. However, this will have the effect of logging you out.] 423 | 424 | ## Change screen resolution in Linux in running in Windows HyperV VM 425 | When running Linux in a Windows HyperV VM, typically, the _Display_ configuration in the Linux instance will not have any provision to change the screen resolution. To change the resolution, you can adjust it via a command-line parameter in Grub. Edit the `/etc/default/grub` file as `root` user and append `video=hyperv_fb:1152x864` to the `GRUB_CMDLINE_LINUX_DEFAULT` and `GRUB_CMDLINE_LINUX` settings. You can choose whatever resolution you prefer, such as 1024x768, 1900x1200, etc. For example: 426 | ``` 427 | GRUB_CMDLINE_LINUX_DEFAULT="quiet nosplash video=hyperv_fb:1152x864" 428 | ``` 429 | Save the `/etc/default/grub` file and update the Grub configuration: 430 | ``` 431 | sudo update-grub 432 | ``` 433 | The changes will take effect the next time you reboot the HyperV VM. 434 | 435 | [Reference](https://arcanecode.com/2020/12/28/adjust-the-screen-resolution-of-an-ubuntu-hyper-v-virtual-machine/) 436 | 437 | ## Command line options for extracting files with `tar` 438 | The [`tar`](https://man7.org/linux/man-pages/man1/tar.1.html) command line utility is the _de facto_ standard in Linux for compressing/uncompressing files. Here are the most common command line options. 439 | | Option | Long Option | Description | 440 | | :----- | :---------- | :---------- | 441 | | `-x` | `--extract` | Extract files from archive. | 442 | | `-f` | `--file` | Specify name of file to extract. | 443 | | `-v` | `--verbose` | List all files processed and result for each. | 444 | | `-j` | `--bzip2` | Extract `bzip2` compressed file. | 445 | | `-J` | `--xz` | Extract `xz` compressed file. | 446 | | `-z` | `--gunzip` | Extract `gzip` compressed file. | 447 | | `-Z` | `--uncompress` | Extract `zip` compressed file. | 448 | | N/A | `--zstd` | Extract `zstd` compressed file. | 449 | 450 | ## Launch `tmux` automatically when opening terminal/shell 451 | If you typically run `tmux` immediately after opening a new terminal window or interactive shell, you can make this automatic. Just add the following lines to your `.bashrc` or `.bash_profile`. 452 | ```bash 453 | # Start tmux automatically if interactive session and not already running 454 | if command -v tmux > /dev/null; then 455 | [[ $- == *i* ]] && [[ ! $TERM =~ screen ]] && [[ -z $TMUX ]] && exec tmux new-session 456 | fi 457 | ``` 458 | 459 | ## Rebase local Git repository from upstream 460 | In some instances, you will have a fork of Git repository that has significantly diverged from the `upstream` original. In this scenario, it is often simplest (or, at least, convenient) to `rebase` the local repository from the `upstream`. Here's how to do this. 461 | 1. Ensure that you have the `upstream` repository configured for your local repository. 462 | ```bash 463 | git remote -v 464 | ``` 465 | This should display something like: 466 | ```bash 467 | upstream .git (fetch) 468 | upstream .git (push) 469 | ``` 470 | If the `upstream` repository is **not** displayed, then it should be added by running: 471 | ```bash 472 | git remote add upstream .git 473 | ``` 474 | 2. Change to your `main` (`master`) branch and fetch from upstream `main`. 475 | ```bash 476 | git checkout main 477 | git fetch upstream main 478 | ``` 479 | 3. Overwrite the current local `main` from the upstream `main`: 480 | ```bash 481 | git rebase upstream/main 482 | ``` 483 | 4. Now, you must decide if you want to merge changes from your **remote** `main` or overwrite them with the rebased update from the `upstream` repository. 484 | a. If you want to merge changes from your **remote** `main`: 485 | ```bash 486 | git pull origin main 487 | ``` 488 | You will be prompted to merge and enter a commit message. If any merge conflicts occur, you must resolve them. 489 | b. If you want to overwrite your **remote** `main` changes: 490 | ```bash 491 | git push -u origin main --force 492 | ``` 493 | 494 | Your local and remote `main` branches forked from `upstream` are now synced with `upstream` and you can proceed with additional work against it. 495 | 496 | [Reference1](https://timonweb.com/misc/how-to-update-a-forked-repo-from-an-upstream-with-git-rebase-or-merge/) 497 | 498 | 499 | ## Extract files from various types of archives at command prompt 500 | In most cases, I prefer to use the [`dtrx`](https://github.com/dtrx-py/dtrx) tool to extract archives. It automatically determines the archive type and extracts the file based on the determined type. However, if you are on a machine that doesn't have `dtrx`, it's useful to know the common commands to extract most archives. 501 | 502 | | Extension | Extract Command | Notes/Comments | 503 | | :-------- | :-------------- | :------------- | 504 | | `tar.gz` | `tar xzf archive.tar.gz` | | 505 | | `tgz` | `tar xzf archive.tgz` | | 506 | | `tar` | `tar xf archive.tar` | | 507 | | `tar.bz2` | `tar xjf archive.tar.bz2` | | 508 | | `tbz2` | `tar xjf archive.tbz2` | | 509 | | `tar.xz` | `tar xf archive.tar.xz` | `tar` will auto-detect compression. | 510 | | `xz` | `unxz archive.xz` | [xz](https://tukaani.org/xz/format.html) format | 511 | | `zip` | `unzip archive.zip` | | 512 | | `tar.zst` | `tar -I=unzstd xf archive.tar.zst` | | 513 | | `zst` | `unzstd archive.zst` | [Zstandard](https://facebook.github.io/zstd/) format | 514 | | `Z` | `uncompress archive.Z` | | 515 | | `7z` | `7z x archive.7z` | [7-Zip](https://7-zip.org/) format | 516 | 517 | Notes: 518 | - The [`tar`](https://man7.org/linux/man-pages/man1/tar.1.html) command can include the `v` option for `verbose` for additional details. For example, `tar xzvf` for verbose option when extracting a `tar.gz` archive. 519 | - These commands will extract the files in the **current** directory. To extract using `tar` into a specific directory use the `-C` option with the desired fully-qualified path. For example, `tar xzf file.tar.gz -C ~/Documents`. 520 | - Typically, `tar` will auto-detect the compression format, if any, used in an archive, so you can usually simply use `tar xf` on most any `tar` archive and it will extract it properly. (The `zstd` format is one notable exception.) 521 | 522 | [Reference1](https://linuxopsys.com/topics/tar-command-in-linux) 523 | [Reference2](https://linuxize.com/post/how-to-create-and-extract-archives-using-the-tar-command-in-linux/) 524 | 525 | ### An `extract()` shell function for decompressing archives 526 | Using the rules specified above, we can build a bash shell function to extract most of the common archives in Linux. Just add this function to your `.bashrc` or `.bash_profile` configure file in your home directory. And ensure that you have the appropriate decompression tools installed; most Linux distributions already have them. Here are the commands to install them on a few common Linux distributions. 527 | - Ubuntu/Debian/Linux Mint 528 | ```bash 529 | sudo apt install -y zlib1g bzip2 zstd xz-utils 7zip unrar-free tar tarlz gzip 530 | ``` 531 | - CentOS/Redhat Linux/Fedora 532 | ```bash 533 | sudo dnf install 534 | ``` 535 | - Archlinux/EndeavourOS 536 | ```bash 537 | sudo pacman - 538 | ``` 539 | 540 | ```bash 541 | # Extract common archive files by file extension 542 | function extract() { 543 | if [ -f $1 ] ; then 544 | case $1 in 545 | # *.tar.gz|*.tgz) tar xzf $1 ;; 546 | # *.tar|*.tar.xz) tar xf $1 ;; 547 | # *.tar.bz2|*.tbz2) tar xjf $1 ;; 548 | # *.xz) unxz $1 ;; 549 | # *.zip) unzip $1 ;; 550 | # *.Z) uncompress $1 ;; 551 | # *.tar.zst) tar -I=unzstd xf $1 ;; 552 | # *.zst) unzstd $1 ;; 553 | # *.7z) 7z x $1 ;; 554 | esac 555 | else 556 | echo "'$1' is not valid archive file." 557 | fi 558 | } 559 | ``` 560 | 561 | ## Best practices for command line `history` 562 | One of the most powerful, but also most hidden features of the Linux/Unix command line is the [`history`](https://www.gnu.org/software/bash/manual/bash.html#Using-History-Interactively) command. The most commonly used features of the command history are: 563 | | Shortcut | Action | 564 | |:---------|:-------| 565 | | 566 | 567 | Generally, the defaults work well, but with a few simple tweaks, you can supercharge 568 | 569 | ## Toggle Synaptics Touchpad On/Off 570 | The Synaptics touchpad can quickly and simply be toggled on and off at the command line using the `synclient` utility. 571 | ```bash 572 | # Disable touchpad 573 | synclient TouchpadOff=1 574 | 575 | # Enable touchpad 576 | synclient TouchpadOff=0 577 | 578 | [Reference](https://askubuntu.com/a/67721) 579 | -------------------------------------------------------------------------------- /custom.conkyrc: -------------------------------------------------------------------------------- 1 | --[[ 2 | #===================================================================================== 3 | # *** Basic Conky Configuration *** 4 | # Date : 10/22/2021 5 | # Author : Tim Jones "tdjones74021@yahoo.com" 6 | # Version : 0.1.0 7 | # License : Distributed under the terms of GNU GPL version 2 or later 8 | # Documentation : N/A 9 | #====================================================================================== 10 | # CONKY 11 | # For commands in conky.config section: 12 | # http://conky.sourceforge.net/config_settings.html 13 | # 14 | # For commands in conky.text section: 15 | # http://conky.sourceforge.net/variables.html 16 | # 17 | # A PDF with all variables is provided 18 | #===================================================================================== 19 | # FONTS 20 | # To avoid copyright infringements you will have to download 21 | # and install the fonts yourself sometimes. 22 | #===================================================================================== 23 | # GENERAL INFO ABOUT FONTS 24 | # Go and look for a nice font on sites like http://www.dafont.com/ 25 | # Download and unzip - double click the font to install it (font-manager must be installed) 26 | # No font-manager then put fonts in ~/.fonts 27 | # Change the font name in the conky 28 | # The name can be known with a command in the terminal: fc-list | grep "part of name" 29 | # Change width and height of the conky according to font 30 | # Reboot your system or fc-cache -fv in terminal 31 | # Enjoy 32 | #===================================================================================== 33 | # FONTS FOR THIS CONKY 34 | # http://www.dafont.com/style-bats.font 35 | #====================================================================================== 36 | # NOTES 37 | #====================================================================================== 38 | # Network interface: eth0 39 | # Disk: sda 40 | # 41 | # To use: 42 | # Save this file to $HOME/.conky directory. 43 | # Terminate any Conky instances: killall conky 44 | # Run Conky with this configuration: conky -c $HOME/.conky/custom.conkyrc & 45 | # Have fun! 46 | #====================================================================================== 47 | 48 | ]] 49 | 50 | conky.config = { 51 | 52 | --Various settings 53 | 54 | background = true, -- forked to background 55 | cpu_avg_samples = 2, -- The number of samples to average for CPU monitoring. 56 | diskio_avg_samples = 10, -- The number of samples to average for disk I/O monitoring. 57 | double_buffer = true, -- Use the Xdbe extension? (eliminates flicker) 58 | if_up_strictness = 'address', -- how strict if testing interface is up - up, link or address 59 | net_avg_samples = 2, -- The number of samples to average for net data 60 | no_buffers = true, -- Subtract (file system) buffers from used memory? 61 | temperature_unit = 'celsius', -- fahrenheit or celsius 62 | text_buffer_size = 2048, -- size of buffer for display of content of large variables - default 256 63 | update_interval = 1, -- update interval 64 | imlib_cache_size = 0, -- disable image cache to get a new spotify cover per song 65 | 66 | 67 | --Placement 68 | 69 | alignment = 'middle_right', -- top_left,top_middle,top_right,bottom_left,bottom_middle,bottom_right, 70 | -- middle_left,middle_middle,middle_right,none 71 | --Arch Duoscreen 72 | --gap_x = -1910, 73 | gap_x = 15, -- pixels between right or left border 74 | gap_y = 0, -- pixels between bottom or left border 75 | minimum_height = 600, -- minimum height of window 76 | minimum_width = 300, -- minimum height of window 77 | maximum_width = 300, -- maximum height of window 78 | 79 | --Graphical 80 | 81 | border_inner_margin = 10, -- margin between border and text 82 | border_outer_margin = 5, -- margin between border and edge of window 83 | border_width = 0, -- border width in pixels 84 | default_bar_width = 80, -- default is 0 - full width 85 | default_bar_height = 10, -- default is 6 86 | default_gauge_height = 25, -- default is 25 87 | default_gauge_width =40, -- default is 40 88 | default_graph_height = 40, -- default is 25 89 | default_graph_width = 0, -- default is 0 - full width 90 | default_shade_color = '#000000', -- default shading colour 91 | default_outline_color = '#000000', -- default outline colour 92 | draw_borders = false, -- draw borders around text 93 | draw_graph_borders = true, -- draw borders around graphs 94 | draw_shades = false, -- draw shades 95 | draw_outline = false, -- draw outline 96 | stippled_borders = 0, -- dashing the border 97 | 98 | --Textual 99 | 100 | extra_newline = false, -- extra newline at the end - for asesome's wiboxes 101 | format_human_readable = true, -- KiB, MiB rather then number of bytes 102 | font = 'Roboto Mono:size=10', -- font for complete conky unless in code defined 103 | max_text_width = 0, -- 0 will make sure line does not get broken if width too smal 104 | max_user_text = 16384, -- max text in conky default 16384 105 | override_utf8_locale = true, -- force UTF8 requires xft 106 | short_units = true, -- shorten units from KiB to k 107 | top_name_width = 21, -- width for $top name value default 15 108 | top_name_verbose = false, -- If true, top name shows the full command line of each process - Default value is false. 109 | uppercase = false, -- uppercase or not 110 | use_spacer = 'none', -- adds spaces around certain objects to align - default none 111 | use_xft = true, -- xft font - anti-aliased font 112 | xftalpha = 1, -- alpha of the xft font - between 0-1 113 | 114 | --Windows 115 | 116 | own_window = true, -- create your own window to draw 117 | own_window_argb_value = 100, -- real transparency - composite manager required 0-255 118 | own_window_argb_visual = true, -- use ARGB - composite manager required 119 | own_window_colour = '#000000', -- set colour if own_window_transparent no 120 | own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager', -- if own_window true - just hints - own_window_type sets it 121 | own_window_transparent = false, -- if own_window_argb_visual is true sets background opacity 0% 122 | own_window_title = 'system_conky', -- set the name manually - default conky "hostname" 123 | own_window_type = 'normal', -- if own_window true options are: normal/override/dock/desktop/panel 124 | 125 | 126 | --Colours 127 | 128 | default_color = '#D9DDE2', -- default color and border color 129 | color1 = '#FF0000', 130 | color2 = '#597AA1', 131 | color3 = '#cccccc', 132 | color4 = '#D9BC83', 133 | color5 = '#00BFFF', 134 | color6 = '#FFFFFF', 135 | 136 | --Signal Colours 137 | color7 = '#1F7411', --green 138 | color8 = '#FFA726', --orange 139 | color9 = '#F1544B', --firebrick 140 | 141 | --Lua 142 | 143 | 144 | }; 145 | 146 | conky.text = [[ 147 | ${color6}${voffset 4}${font GE Inspira:size=36}${alignc}${time %l}:${time %M} ${time %p}${font}${color} 148 | ${color6}${voffset 4}${font GE Inspira:size=12}${alignc}${time %A} ${time %B} ${time %e}, ${time %Y}${font}${color} 149 | 150 | ${color5}${font Roboto:size=10}${voffset 2}S Y S T E M ${hr 2}${font}${color} 151 | ${color2}${voffset 8}Hostname:${color} ${alignr}${nodename} 152 | ${color2}Distro:${color}${alignr}$sysname ${alignr}${execi 6000 lsb_release -a | grep 'Description'|awk {'print $3, $4, $5'}} 153 | ${color2}Kernel:${color}${alignr}${exec uname} ${exec uname -r} 154 | #Nvidia: ${alignr}${execp nvidia-smi --query-supported-clocks=gpu_name --format=csv,noheader} 155 | #Nvidia Driver: ${alignr}${execi 60000 nvidia-smi | grep "Driver Version"| awk {'print $3'}} 156 | ${color2}Uptime:${color} ${alignr}${uptime} 157 | ${color5}${font Roboto:size=10}P R O C E S S O R S ${hr 2}${font}${color} 158 | ${color2}CPU Freq:${color} $alignr${freq}MHz 159 | ${color2}CPU Temp:${color} $alignr${execi 10 sensors | grep 'Core 0' | awk {'print $3'}} 160 | ${color2}History:${color} ${alignr}${cpugraph 8,100} 161 | ${color2}${offset 30}CPU Core 1:${color} ${alignr}${offset -10}${cpu cpu1}%${alignr}${cpubar cpu1} 162 | # ${color2}${offset 30}CPU Core 2:${color} ${alignr}${offset -10}${cpu cpu2}%${alignr}${cpubar cpu2} 163 | # ${color2}${offset 30}CPU Core 3:${color} ${alignr}${offset -10}${cpu cpu3}%${alignr}${cpubar cpu3} 164 | # ${color2}${offset 30}CPU Core 4:${color} ${alignr}${offset -10}${cpu cpu4}%${alignr}${cpubar cpu4} 165 | ${color2}Top Processes${goto 222}cpu%${goto 274}mem%${color} 166 | ${voffset 4} 1 - ${top name 1}${alignr}${goto 170} ${goto 222}${top cpu 1} ${goto 274}${top mem 1} 167 | 2 - ${top name 2}${alignr} ${goto 222}${top cpu 2} ${goto 274}${top mem 2} 168 | 3 - ${top name 3}${alignr} ${goto 222}${top cpu 3} ${goto 274}${top mem 3} 169 | 4 - ${top name 4}${alignr} ${goto 222}${top cpu 4} ${goto 274}${top mem 4} 170 | 5 - ${top name 5}${alignr} ${goto 222}${top cpu 5} ${goto 274}${top mem 5} 171 | ${color5}${font Roboto:size=10}M E M O R Y ${hr 2}${font}${color} 172 | ${color2}${offset 30}RAM: ${color}${alignr}${offset -10}${mem} / ${memmax}${alignr}${membar} 173 | ${color2}${offset 30}Swap:${color} ${alignr}${offset -10}${swap} / ${swapmax}${alignr}${swapbar} 174 | ${color2}Top Processes${goto 222}cpu%${goto 274}mem%${color} 175 | ${voffset 4} 1 - ${top_mem name 1}${alignr}${goto 170} ${goto 222}${top_mem cpu 1} ${goto 274}${top_mem mem 1} 176 | 2 - ${top_mem name 2}${alignr}${goto 170} ${goto 222}${top_mem cpu 2} ${goto 274}${top_mem mem 2} 177 | 3 - ${top_mem name 3}${alignr}${goto 170} ${goto 222}${top_mem cpu 3} ${goto 274}${top_mem mem 3} 178 | 4 - ${top_mem name 4}${alignr}${goto 170} ${goto 222}${top_mem cpu 4} ${goto 274}${top_mem mem 4} 179 | 5 - ${top_mem name 5}${alignr}${goto 170} ${goto 222}${top_mem cpu 5} ${goto 274}${top_mem mem 5} 180 | ${color5}${font Roboto:size=10}D R I V E S ${hr 2}${font}${color} 181 | ${offset 30}${color2}Root:${color} ${alignr}${offset -10}${fs_used /} / ${fs_size /}${alignr}${fs_bar} 182 | ${offset 30}${color2}I/O Read:${color} ${alignr}${offset -10}${diskio_read /dev/sda}${alignr}${diskiograph_read sda 8,100} 183 | ${offset 30}${color2}I/O Write:${color} ${alignr}${offset -10}${diskio_write /dev/sda}${alignr}${diskiograph_write sda 8,100} 184 | 185 | ${color5}${color5}${font Roboto:size=10}N E T W O R K ${hr 2}${font}${color} 186 | ${color2}${offset 30}IP Address: ${color} ${alignr}${offset -10$}${addrs eth0} 187 | ${color2}${offset 30}Eth Up:${color} ${alignr}${offset -10$}${upspeed eth0}${alignr}${upspeedgraph eth0 8,100} 188 | ${color2}${offset 30}Eth Down:${color} ${alignr}${offset -10$}${downspeed eth0}${alignr}${downspeedgraph eth0 8,100} 189 | #${font Roboto:size=10}N V I D I A ${hr 2}${font} 190 | #${font Roboto:size=10,weight:bold}${color5}${execp nvidia-smi --query-supported-clocks=gpu_name --format=csv,noheader}${font} 191 | #${font StyleBats:size=20}u${font}${offset 8}${voffset -12}GPU Temp ${alignr}${execi 60 nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader} °C 192 | #${offset 30}Fan Speed ${alignr}${execi 60 nvidia-settings -q [fan:0]/GPUCurrentFanSpeed -t} % 193 | #${offset 30}GPU Clock ${alignr}${execi 60 nvidia-settings -q GPUCurrentClockFreqs | grep -m 1 Attribute | awk '{print $4}' | sed -e 's/\.//' | cut -d, -f1} MHz 194 | #${offset 30}Mem Clock ${alignr}${execi 86400 nvidia-settings -q all| grep -m 1 GPUCurrentProcessorClockFreqs | awk '{print $4}' | sed 's/.$//'} MHz 195 | #${offset 30}Mem Used ${alignr}${execi 60 nvidia-settings -q [gpu:0]/UsedDedicatedGPUMemory -t} / ${exec nvidia-settings -q [gpu:0]/TotalDedicatedGPUMemory -t} MiB0 196 | ]]; 197 | -------------------------------------------------------------------------------- /export.sh: -------------------------------------------------------------------------------- 1 | 2 | # Make 'less' more powerful 3 | export LESS='--quit-if-one-screen --ignore-case --status-column --LONG-PROMPT --RAW-CONTROL-CHARS --HILITE-UNREAD --tabs=4 --no-init --window=-4' 4 | 5 | # Set colors and text decorations for 'less' output 6 | # From https://wiki.archlinux.org/index.php/Color_output_in_console#less 7 | export LESS_TERMCAP_mb=$'\E[1;31m' # begin bold 8 | export LESS_TERMCAP_md=$'\E[1;36m' # begin blink 9 | export LESS_TERMCAP_me=$'\E[0m' # reset bold/blink 10 | export LESS_TERMCAP_so=$'\E[01;44;33m' # begin reverse video 11 | export LESS_TERMCAP_se=$'\E[0m' # reset reverse video 12 | export LESS_TERMCAP_us=$'\E[1;32m' # begin underline 13 | export LESS_TERMCAP_ue=$'\E[0m' # reset underline -------------------------------------------------------------------------------- /in_progress.sh: -------------------------------------------------------------------------------- 1 | # Install Digital Clock 4 from Sourceforge 2 | APP_NAME=digital_clock_4 3 | APP_VERSION=4.5.5 4 | if $(uname -m | grep '64'); then # Check for 64-bit Linux kernel 5 | ARCH_TYPE=x64 6 | else # Otherwise use version for 32-bit kernel 7 | ARCH_TYPE=x86 8 | fi 9 | curl -o /tmp/${APP_NAME}.tar.xz -J -L https://superb-sea2.dl.sourceforge.net/project/digitalclock4/files/${APP_VERSION}/${APP_NAME}_${ARCH_TYPE}.tar.xz 10 | cd /tmp 11 | dtrx -n ${APP_NAME}.tar.xz 12 | cd ${APP_NAME} 13 | mv "Digital\ Clock\ 4" ${APP_NAME} 14 | sudo mv ${APP_NAME} /opt 15 | sudo ln -s /opt/${APP_NAME}/digital_clock.sh /usr/local/bin/digital_clock 16 | # Create icon in menus 17 | cat > /tmp/${APP_NAME}.desktop << EOF 18 | [Desktop Entry] 19 | Name=Digital Clock 4 20 | Comment=Nice desktop digital clock 21 | GenericName=Clock 22 | Exec=/opt/${APP_NAME}/digital_clock.sh 23 | Icon=/opt/${APP_NAME}/digital_clock.svg 24 | Type=Application 25 | StartupNotify=true 26 | Terminal=false 27 | Categories=Utility;Clock; 28 | Keywords=clock;time;date; 29 | EOF 30 | sudo mv /tmp/${APP_NAME}.desktop /usr/share/applications/ 31 | ln -s /usr/local/share/applications/digital_clock.desktop $HOME/.config/autostart/ 32 | 33 | 34 | 35 | # Install httpress HTTP response checker utility from source 36 | APP_NAME=httpres 37 | APP_VERSION=1.2 38 | curl -o /tmp/${APP_NAME}.tar.bz2 -J -L https://cytranet.dl.sourceforge.net/project/${APP_NAME}/${APP_NAME}-${APP_VERSION}/${APP_NAME}-${APP_VERSION}-src.tar.bz2 39 | 40 | 41 | 42 | sudo apt-get install -y libgtk-3-dev libgtksourceview-3.0-dev libuchardet-dev libxml2-dev 43 | curl -o /tmp/gtef-2.0.1.tar.xz -J -L https://download.gnome.org/sources/gtef/2.0/gtef-2.0.1.tar.xz 44 | 45 | 46 | # Install latest GTK+ and associated libraries from source 47 | # Install prerequisite libraries 48 | sudo apt-get install -y libmount-dev fam libfam-dev libffi-dev 49 | cd /tmp 50 | curl -O -J -L http://ftp.gnome.org/pub/gnome/sources/gtk+/3.22/gtk+-3.22.15.tar.xz 51 | curl -O -J -L http://ftp.gnome.org/pub/gnome/sources/glib/2.52/glib-2.52.2.tar.xz 52 | curl -O -J -L http://ftp.gnome.org/pub/gnome/sources/pango/1.40/pango-1.40.5.tar.xz 53 | curl -O -J -L http://ftp.gnome.org/pub/gnome/sources/gdk-pixbuf/2.36/gdk-pixbuf-2.36.6.tar.xz 54 | curl -O -J -L http://ftp.gnome.org/pub/gnome/sources/atk/2.24/atk-2.24.0.tar.xz 55 | curl -O -J -L http://ftp.gnome.org/pub/gnome/sources/gobject-introspection/1.52/gobject-introspection-1.52.1.tar.xz 56 | dtrx -n glib-2.52.2.tar.xz 57 | cd glib-2.52.2 58 | ./configure && make && sudo make install 59 | cd /tmp 60 | dtrx -n gtk+-3.22.15.tar.xz 61 | cd gtk+-3.22.15 62 | ./configure && make && sudo make install 63 | 64 | 65 | # Install Quite Universal Circuit Simulator (QUCS) Qt-based GUI electronic circuit simulator from source 66 | APP_NAME=QUCS 67 | APP_GUI_NAME="Qt-based GUI electronic circuit simulator." 68 | APP_VERSION=0.0.20-rc2 69 | APP_EXT=tar.gz 70 | FILE_NAME=${APP_NAME,,}-${APP_VERSION} 71 | sudo apt-get install -y automake libtool libtool-bin gperf flex bison libqt4-dev libqt4-qt3support build-essential 72 | # Install dependency ADMS, code generator for electronic device models 73 | curl -o /tmp/adms-2.3.6.tar.gz -J -L https://downloads.sourceforge.net/mot-adms/adms-2.3.6.tar.gz 74 | cd /tmp 75 | dtrx -n /tmp/adms-2.3.6.tar.gz 76 | cd /tmp/adms-2.3.6 77 | ./configure && make && sudo make install 78 | curl -o /tmp/${FILE_NAME}.${APP_EXT} -J -L https://downloads.sourceforge.net/${APP_NAME,,}/${FILE_NAME}.${APP_EXT} 79 | cd /tmp 80 | dtrx -n /tmp/${FILE_NAME}.${APP_EXT} 81 | cd /tmp/${FILE_NAME}/${APP_NAME,,}-0.0.20 82 | mkdir -p build && cd build 83 | qtchooser -run-tool=qmake -qt=5 ../${APP_NAME,,}.pro && make 84 | sudo cp /tmp/${FILE_NAME}/${FILE_NAME,,}/build/${APP_NAME} /usr/local/bin # No 'install' target for make 85 | sudo cp /tmp/${FILE_NAME}/${FILE_NAME,,}/images.d/${APP_NAME,,}.png /usr/local/share/pixmaps/${APP_NAME,,}.png 86 | sudo ln -s -f /usr/local/bin/${APP_NAME} /usr/local/bin/${APP_NAME,,} 87 | cat > /tmp/${APP_NAME,,}.desktop << EOF 88 | [Desktop Entry] 89 | Name=${APP_NAME} 90 | Comment=${APP_GUI_NAME} 91 | GenericName=${APP_NAME} 92 | Path=/usr/local/bin 93 | Exec=/usr/local/bin/${APP_NAME} 94 | Icon=/usr/local/share/pixmaps/${APP_NAME,,}.png 95 | Type=Application 96 | StartupNotify=true 97 | Terminal=false 98 | Categories=Games;Entertainment;Education; 99 | Keywords=Puzzle;Game;Math;Education; 100 | EOF 101 | sudo mv /tmp/${APP_NAME,,}.desktop /usr/share/applications/ 102 | cd $HOME 103 | sudo rm -rf /tmp/${APP_NAME,,}* /tmp/${APP_NAME}* 104 | --------------------------------------------------------------------------------