{"id":15026174,"url":"https://github.com/onceupon/bash-oneliner","last_synced_at":"2025-05-14T02:09:44.442Z","repository":{"id":37405749,"uuid":"61099017","full_name":"onceupon/Bash-Oneliner","owner":"onceupon","description":"A collection of handy Bash One-Liners and terminal tricks for data processing and Linux system maintenance.","archived":false,"fork":false,"pushed_at":"2025-04-03T02:55:32.000Z","size":941,"stargazers_count":10423,"open_issues_count":7,"forks_count":628,"subscribers_count":114,"default_branch":"master","last_synced_at":"2025-04-08T22:19:44.773Z","etag":null,"topics":["bash","data-processing","grep","hardware","linux","linux-administration","one-liners","oneliner-commands","shell","shell-oneliner","system","terminal","variables","xargs","xwindow"],"latest_commit_sha":null,"homepage":"http://onceupon.github.io/Bash-Oneliner/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onceupon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-14T06:52:21.000Z","updated_at":"2025-04-08T21:37:07.000Z","dependencies_parsed_at":"2022-07-09T19:46:08.668Z","dependency_job_id":"f8c9f230-f692-4f29-a9ed-86694ed4f553","html_url":"https://github.com/onceupon/Bash-Oneliner","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onceupon%2FBash-Oneliner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onceupon%2FBash-Oneliner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onceupon%2FBash-Oneliner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onceupon%2FBash-Oneliner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onceupon","download_url":"https://codeload.github.com/onceupon/Bash-Oneliner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254053297,"owners_count":22006717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","data-processing","grep","hardware","linux","linux-administration","one-liners","oneliner-commands","shell","shell-oneliner","system","terminal","variables","xargs","xwindow"],"created_at":"2024-09-24T20:03:56.276Z","updated_at":"2025-05-14T02:09:39.430Z","avatar_url":"https://github.com/onceupon.png","language":null,"readme":"# Bash-Oneliner\nI am glad that you are here! I was working on bioinformatics a few years ago and was amazed by those single-word bash commands which are much faster than my dull scripts, time saved through learning command-line shortcuts and scripting. Recent years I am working on cloud computing and I keep recording those useful commands here. Not all of them is oneliner, but i put effort on making them brief and swift. I am mainly using Ubuntu, Amazon Linux, RedHat, Linux Mint, Mac and CentOS, sorry if the commands don't work on your system.\n\nThis blog will focus on simple bash commands for parsing data and Linux system maintenance that i acquired from work and LPIC exam. I apologize that there are no detailed citation for all the commands, but they are probably from dear Google and Stack Overflow.\n\nEnglish and bash are not my first language, please correct me anytime, thank you.\nIf you know other cool commands, please teach me!\n\nHere's a more stylish version of [Bash-Oneliner](https://onceupon.github.io/Bash-Oneliner/)~\n\n## Handy Bash one-liners\n\n- [Terminal Tricks](#terminal-tricks)\n- [Variable](#variable)\n- [Math](#math)\n- [Grep](#grep)\n- [Sed](#sed)\n- [Awk](#awk)\n- [Xargs](#xargs)\n- [Find](#find)\n- [Condition and Loop](#condition-and-loop)\n- [Time](#time)\n- [Download](#download)\n- [Random](#random)\n- [Xwindow](#xwindow)\n- [System](#system)\n- [Hardware](#hardware)\n- [Networking](#networking)\n- [Data Wrangling](#data-wrangling)\n- [Others](#others)\n\n## Terminal Tricks\n\n#####  Using Ctrl keys\n```\nCtrl + a : move to the beginning of line.\nCtrl + d : if you've type something, Ctrl + d deletes the character under the cursor, else, it escapes the current shell.\nCtrl + e : move to the end of line.\nCtrl + k : delete all text from the cursor to the end of line.\nCtrl + l : equivalent to clear.\nCtrl + n : same as Down arrow.\nCtrl + p : same as Up arrow.\nCtrl + q : to resume output to terminal after Ctrl + s.\nCtrl + r : begins a backward search through command history.(keep pressing Ctrl + r to move backward)\nCtrl + s : to stop output to terminal.\nCtrl + t : transpose the character before the cursor with the one under the cursor, press Esc + t to transposes the two words before the cursor.\nCtrl + u : cut the line before the cursor; then Ctrl + y paste it\nCtrl + w : cut the word before the cursor; then Ctrl + y paste it\nCtrl + x + backspace : delete all text from the beginning of line to the cursor.\nCtrl + x + Ctrl + e : launch editor defined by $EDITOR to input your command. Useful for multi-line commands.\nCtrl + z : stop current running process and keep it in background. You can use `fg` to continue the process in the foreground, or `bg` to continue the process in the background.\nCtrl + _ : undo typing.\n```\n##### Change case\n```bash\nEsc + u\n# converts text from cursor to the end of the word to uppercase.\nEsc + l\n# converts text from cursor to the end of the word to lowercase.\nEsc + c\n# converts letter under the cursor to uppercase, rest of the word to lowercase.\n```\n\n##### Run history number (e.g. 53)\n```bash\n!53\n```\n\n##### Run last command\n```bash\n!!\n# run the previous command using sudo\nsudo !!\n```\n\n##### Run last command and change some parameter using caret substitution (e.g. last command: echo 'aaa' -\u003e rerun as: echo 'bbb')\n```bash\n# last command: echo 'aaa'\n^aaa^bbb\n\n#echo 'bbb'\n#bbb\n\n# Notice that only the first aaa will be replaced, if you want to replace all 'aaa', use ':\u0026' to repeat it:\n^aaa^bbb^:\u0026\n# or\n!!:gs/aaa/bbb/\n\n```\n\n##### Run past command that began with (e.g. cat filename)\n```bash\n!cat\n# or\n!c\n# run cat filename again\n```\n\n##### Bash globbing\n```bash\n# '*' serves as a \"wild card\" for filename expansion.\n/etc/pa*wd    #/etc/passwd\n\n# '?' serves as a single-character \"wild card\" for filename expansion.\n/b?n/?at      #/bin/cat\n\n# '[]' serves to match the character from a range.\nls -l [a-z]*   #list all files with alphabet in its filename.\n\n# '{}' can be used to match filenames with more than one patterns\nls *.{sh,py}   #list all .sh and .py files\n```\n\n##### Some handy environment variables\n```\n$0   :name of shell or shell script.\n$1, $2, $3, ... :positional parameters.\n$#   :number of positional parameters.\n$?   :most recent foreground pipeline exit status.\n$-   :current options set for the shell.\n$$   :pid of the current shell (not subshell).\n$!   :is the PID of the most recent background command.\n$_   :last argument of the previously executed command, or the path of the bash script.\n\n$DESKTOP_SESSION     current display manager\n$EDITOR   preferred text editor.\n$LANG   current language.\n$PATH   list of directories to search for executable files (i.e. ready-to-run programs)\n$PWD    current directory\n$SHELL  current shell\n$USER   current username\n$HOSTNAME   current hostname\n```\n\n##### Using vi-mode in your shell\n```bash\nset -o vi\n# change bash shell to vi mode\n# then hit the Esc key to change to vi edit mode (when `set -o vi` is set)\nk\n# in vi edit mode - previous command\nj\n# in vi edit mode - next command\n0\n# in vi edit mode - beginning of the command\nR\n# in vi edit mode - replace current characters of command\n2w\n# in vi edit mode - next to 2nd word\nb\n# in vi edit mode - previous word\ni\n# in vi edit mode - go to insert mode\nv\n# in vi edit mode - edit current command in vi\nman 3 readline\n# man page for complete readline mapping\n```\n\n## Variable\n[[back to top](#handy-bash-one-liners)]\n##### Variable substitution within quotes\n```bash\n# foo=bar\necho $foo\n# bar\necho \"$foo\"\n# bar\n# single quotes cause variables to not be expanded\necho '$foo'\n# $foo\n# single quotes within double quotes will not cancel expansion and will be part of the output\necho \"'$foo'\"\n# 'bar'\n# doubled single quotes act as if there are no quotes at all\necho ''$foo''\n# bar\n```\n##### Get the length of variable\n```bash\nvar=\"some string\"\necho ${#var}\n# 11\n```\n##### Get the first character of the variable\n```bash\nvar=string\necho \"${var:0:1}\"\n#s\n\n# or\necho ${var%%\"${var#?}\"}\n```\n\n##### Remove the first or last string from variable\n```bash\nvar=\"some string\"\necho ${var:2}\n#me string\n```\n\n##### Replacement (e.g. remove the first leading 0 )\n```bash\nvar=\"0050\"\necho ${var[@]#0}\n#050\n```\n\n##### Replacement (e.g. replace 'a' with ',')\n```bash\n{var/a/,}\n```\n\n##### Replace all (e.g. replace all 'a' with ',')\n```bash\n{var//a/,}\n```\n\n##### Grep lines with strings from a file (e.g. lines with 'stringA or 'stringB' or 'stringC')\n```bash\n# with grep\ntest=\"stringA stringB stringC\"\ngrep ${test// /\\\\\\|} file.txt\n# turning the space into 'or' (\\|) in grep\n```\n\n##### To change the case of the string stored in the variable to lowercase (Parameter Expansion)\n```bash\nvar=HelloWorld\necho ${var,,}\nhelloworld\n```\n\n##### Expand and then execute variable/argument\n```bash\ncmd=\"bar=foo\"\neval \"$cmd\"\necho \"$bar\" # foo\n```\n\n##### Record a terminal session\n```bash\n# https://github.com/asciinema/asciinema\nasciinema rec demo.cast\n```\n\n## Math\n[[back to top](#handy-bash-one-liners)]\n##### Arithmetic Expansion in Bash (Operators: +, -, *, /, %, etc)\n```bash\necho $(( 10 + 5 ))  #15\nx=1\necho $(( x++ )) #1 , notice that it is still 1, since it's post-increment\necho $(( x++ )) #2\necho $(( ++x )) #4 , notice that it is not 3 since it's pre-increment\necho $(( x-- )) #4\necho $(( x-- )) #3\necho $(( --x )) #1\nx=2\ny=3\necho $(( x ** y )) #8\n```\n\n##### Print out the prime factors of a number (e.g. 50)\n```bash\nfactor 50\n# 50: 2 5 5\n```\n##### Sum up input list (e.g. seq 10)\n```bash\nseq 10|paste -sd+|bc\n```\n\n##### Sum up a file (each line in file contains only one number)\n```bash\nawk '{s+=$1} END {print s}' filename\n```\n\n##### Column subtraction\n```bash\ncat file| awk -F '\\t' 'BEGIN {SUM=0}{SUM+=$3-$2}END{print SUM}'\n```\n\n##### Simple math with expr\n```bash\nexpr 10+20 #30\nexpr 10\\*20 #600\nexpr 30 \\\u003e 20 #1 (true)\n```\n\n##### More math with bc\n```bash\n# Number of decimal digit/ significant figure\necho \"scale=2;2/3\" | bc\n#.66\n\n# Exponent operator\necho \"10^2\" | bc\n#100\n\n# Using variables\necho \"var=5;--var\"| bc\n#4\n```\n\n\n## Grep\n[[back to top](#handy-bash-one-liners)]\n\n#####  Type of grep\n```bash\ngrep = grep -G # Basic Regular Expression (BRE)\nfgrep = grep -F # fixed text, ignoring meta-characters\negrep = grep -E # Extended Regular Expression (ERE)\nrgrep = grep -r # recursive\ngrep -P # Perl Compatible Regular Expressions (PCRE)\n```\n\n#####  Grep and count number of empty lines\n```bash\ngrep -c \"^$\"\n```\n\n#####  Grep and return only integer\n```bash\ngrep -o '[0-9]*'\n# or\ngrep -oP '\\d*'\n```\n#####  Grep integer with certain number of digits (e.g. 3)\n```bash\ngrep '[0-9]\\{3\\}'\n# or\ngrep -E '[0-9]{3}'\n# or\ngrep -P '\\d{3}'\n```\n\n#####  Grep only IP address\n```bash\ngrep -Eo '[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}'\n# or\ngrep -Po '\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}'\n```\n\n#####  Grep whole word (e.g. 'target')\n```bash\ngrep -w 'target'\n\n# or using RE\ngrep '\\btarget\\b'\n```\n#####  Grep returning lines before and after match (e.g. 'bbo')\n```bash\n# return also 3 lines after match\ngrep -A 3 'bbo'\n\n# return also 3 lines before match\ngrep -B 3 'bbo'\n\n# return also 3 lines before and after match\ngrep -C 3 'bbo'\n```\n\n#####  Grep string starting with (e.g. 'S')\n```bash\ngrep -o 'S.*'\n```\n\n##### Extract text between words (e.g. w1,w2)\n```bash\ngrep -o -P '(?\u003c=w1).*(?=w2)'\n```\n\n##### Grep lines without word (e.g. 'bbo')\n```bash\ngrep -v bbo filename\n```\n\n##### Grep lines not begin with string (e.g. #)\n```bash\ngrep -v '^#' file.txt\n```\n\n##### Grep variables with space within it (e.g. myvar=\"some strings\")\n```bash\ngrep \"$myvar\" filename\n# remember to quote the variable!\n```\n\n##### Grep only one/first match (e.g. 'bbo')\n```bash\ngrep -m 1 bbo filename\n```\n\n##### Grep and return number of matching line(e.g. 'bbo')\n```bash\ngrep -c bbo filename\n```\n\n##### Count occurrence (e.g. three times a line count three times)\n```bash\ngrep -o bbo filename |wc -l\n```\n\n##### Case insensitive grep (e.g. 'bbo'/'BBO'/'Bbo')\n```bash\ngrep -i \"bbo\" filename\n```\n\n##### COLOR the match (e.g. 'bbo')!\n```bash\ngrep --color bbo filename\n```\n\n##### Grep search all files in a directory(e.g. 'bbo')\n```bash\ngrep -R bbo /path/to/directory\n# or\ngrep -r bbo /path/to/directory\n```\n\n##### Search all files in directory, do not ouput the filenames (e.g. 'bbo')\n```bash\ngrep -rh bbo /path/to/directory\n```\n\n##### Search all files in directory, output ONLY the filenames with matches(e.g. 'bbo')\n```bash\ngrep -rl bbo /path/to/directory\n```\n\n##### Grep OR (e.g. A or B or C or D)\n```\ngrep 'A\\|B\\|C\\|D'\n```\n\n##### Grep AND (e.g. A and B)\n```bash\ngrep 'A.*B'\n```\n\n##### Regex any single character (e.g. ACB or AEB)\n```bash\ngrep 'A.B'\n```\n\n##### Regex with or without a certain character (e.g. color or colour)\n```bash\ngrep 'colou\\?r'\n```\n\n##### Grep all content of a fileA from fileB\n```bash\ngrep -f fileA fileB\n```\n\n##### Grep a tab\n```bash\ngrep $'\\t'\n```\n\n##### Grep variable from variable\n```bash\n$echo \"$long_str\"|grep -q \"$short_str\"\nif [ $? -eq 0 ]; then echo 'found'; fi\n# grep -q will output 0 if match found\n# remember to add space between []!\n```\n\n##### Grep strings between a bracket()\n```bash\ngrep -oP '\\(\\K[^\\)]+'\n```\n\n##### Grep number of characters with known strings in between(e.g. AAEL000001-RA)\n```bash\ngrep -o -w \"\\w\\{10\\}\\-R\\w\\{1\\}\"\n# \\w word character [0-9a-zA-Z_] \\W not word character\n```\n\n##### Skip directory (e.g. 'bbo')\n```bash\ngrep -d skip 'bbo' /path/to/files/*\n```\n\n\n\n## Sed\n[[back to top](#handy-bash-one-liners)]\n##### Remove the 1st line\n```bash\nsed 1d filename\n```\n\n##### Remove the first 100 lines (remove line 1-100)\n```bash\nsed 1,100d filename\n```\n\n##### Remove lines with string (e.g. 'bbo')\n```bash\nsed \"/bbo/d\" filename\n# case insensitive:\nsed \"/bbo/Id\" filename\n```\n\n##### Remove lines whose nth character not equal to a value (e.g. 5th character not equal to 2)\n```bash\nsed -E '/^.{5}[^2]/d'\n#aaaa2aaa (you can stay)\n#aaaa1aaa (delete!)\n```\n\n##### Edit infile (edit and save to file), (e.g. deleting the lines with 'bbo' and save to file)\n```bash\nsed -i \"/bbo/d\" filename\n```\n\n##### When using variable (e.g. $i), use double quotes \" \"\n```bash\n# e.g. add \u003e$i to the first line (to make a bioinformatics FASTA file)\nsed \"1i \u003e$i\"\n# notice the double quotes! in other examples, you can use a single quote, but here, no way!\n# '1i' means insert to first line\n```\n\n##### Using environment variable and end-of-line pattern at the same time.\n```bash\n# Use backslash for end-of-line $ pattern, and double quotes for expressing the variable\nsed -e \"\\$s/\\$/\\n+--$3-----+/\"\n```\n\n##### Delete/remove empty lines\n```bash\nsed '/^\\s*$/d'\n\n# or\n\nsed '/^$/d'\n```\n##### Delete/remove last line\n```bash\nsed '$d'\n```\n\n##### Delete/remove last character from end of file\n```bash\nsed -i '$ s/.$//' filename\n```\n\n##### Add string to beginning of file (e.g. \"\\[\")\n```bash\nsed -i '1s/^/[/' filename\n```\n\n##### Add string at certain line number (e.g. add 'something' to line 1 and line 3)\n```bash\nsed -e '1isomething' -e '3isomething'\n```\n\n##### Add string to end of file (e.g. \"]\")\n```bash\nsed '$s/$/]/' filename\n```\n##### Add newline to the end\n```bash\nsed '$a\\'\n```\n\n##### Add string to beginning of every line (e.g. 'bbo')\n```bash\nsed -e 's/^/bbo/' filename\n```\n\n##### Add string to end of each line (e.g. \"}\")\n```bash\nsed -e 's/$/\\}\\]/' filename\n```\n\n##### Add \\n every nth character (e.g. every 4th character)\n```bash\nsed 's/.\\{4\\}/\u0026\\n/g'\n```\n\n##### Add a line after the line that matches the pattern (e.g. add a new line with \"world\" after the line with \"hello\")\n```bash\nsed '/hello*/a world' filename\n# hello\n# world\n```\n\n##### Concatenate/combine/join files with a separator and next line (e.g separate by \",\")\n```bash\nsed -s '$a,' *.json \u003e all.json\n```\n\n##### Substitution (e.g. replace A by B)\n```bash\nsed 's/A/B/g' filename\n```\n\n##### Substitution with wildcard (e.g. replace a line start with aaa= by aaa=/my/new/path)\n```bash\nsed \"s/aaa=.*/aaa=\\/my\\/new\\/path/g\"\n```\n\n##### Select lines start with string (e.g. 'bbo')\n```bash\nsed -n '/^@S/p'\n```\n##### Delete lines with string (e.g. 'bbo')\n```bash\nsed '/bbo/d' filename\n```\n\n##### Print/get/trim a range of line (e.g. line 500-5000)\n```bash\nsed -n 500,5000p filename\n```\n\n##### Print every nth lines\n```bash\nsed -n '0~3p' filename\n\n# catch 0: start; 3: step\n```\n\n##### Print every odd # lines\n```bash\nsed -n '1~2p'\n```\n##### Print every third line including the first line\n```bash\nsed -n '1p;0~3p'\n```\n##### Remove leading whitespace and tabs\n```bash\nsed -e 's/^[ \\t]*//'\n# Notice a whitespace before '\\t'!!\n```\n\n##### Remove only leading whitespace\n```bash\nsed 's/ *//'\n\n# notice a whitespace before '*'!!\n```\n\n##### Remove ending commas\n```bash\nsed 's/,$//g'\n```\n\n##### Add a column to the end\n```bash\nsed \"s/$/\\t$i/\"\n# $i is the valuable you want to add\n\n# To add the filename to every last column of the file\nfor i in $(ls); do sed -i \"s/$/\\t$i/\" $i; done\n```\n\n##### Add extension of filename to last column\n```bash\nfor i in T000086_1.02.n T000086_1.02.p; do sed \"s/$/\\t${i/*./}/\" $i; done \u003eT000086_1.02.np\n```\n\n##### Remove newline\\ nextline\n```bash\nsed ':a;N;$!ba;s/\\n//g'\n```\n\n##### Print a particular line (e.g. 123th line)\n```bash\nsed -n -e '123p'\n```\n\n##### Print a number of lines (e.g. line 10th to line 33 rd)\n```bash\nsed -n '10,33p' \u003cfilename\n```\n\n##### Change delimiter\n```bash\nsed 's=/=\\\\/=g'\n```\n\n##### Replace with wildcard (e.g A-1-e or A-2-e or A-3-e....)\n```bash\nsed 's/A-.*-e//g' filename\n```\n\n##### Remove last character of file\n```bash\nsed '$ s/.$//'\n```\n\n##### Insert character at specified position of file (e.g. AAAAAA --\u003e AAA#AAA)\n```bash\nsed -r -e 's/^.{3}/\u0026#/' filename\n```\n\n\n## Awk\n[[back to top](#handy-bash-one-liners)]\n\n##### Set tab as field separator\n```bash\nawk -F $'\\t'\n```\n\n##### Output as tab separated (also as field separator)\n```bash\nawk -v OFS='\\t'\n```\n\n##### Pass variable\n```bash\na=bbo;b=obb;\nawk -v a=\"$a\" -v b=\"$b\" \"$1==a \u0026\u0026 $10=b\" filename\n```\n\n##### Print line number and number of characters on each line\n```bash\nawk '{print NR,length($0);}' filename\n```\n\n##### Find number of columns\n```bash\nawk '{print NF}'\n```\n\n##### Reverse column order\n```bash\nawk '{print $2, $1}'\n```\n\n##### Check if there is a comma in a column (e.g. column $1)\n```bash\nawk '$1~/,/ {print}'\n```\n\n##### Split and do for loop\n```bash\nawk '{split($2, a,\",\");for (i in a) print $1\"\\t\"a[i]}' filename\n```\n\n##### Print all lines before nth occurrence of a string (e.g stop print lines when 'bbo' appears 7 times)\n```bash\nawk -v N=7 '{print}/bbo/\u0026\u0026 --N\u003c=0 {exit}'\n```\n\n##### Print filename and last line of all files in directory\n```bash\nls|xargs -n1 -I file awk '{s=$0};END{print FILENAME,s}' filename\n```\n\n##### Add string to the beginning of a column (e.g add \"chr\" to column $3)\n```bash\nawk 'BEGIN{OFS=\"\\t\"}$3=\"chr\"$3'\n```\n\n##### Remove lines with string (e.g. 'bbo')\n```bash\nawk '!/bbo/' filename\n```\n\n##### Remove last column\n```bash\nawk 'NF{NF-=1};1' filename\n```\n\n##### Usage and meaning of NR and FNR\n```bash\n# For example there are two files:\n# fileA:\n# a\n# b\n# c\n# fileB:\n# d\n# e\nawk 'print FILENAME, NR,FNR,$0}' fileA fileB\n# fileA    1    1    a\n# fileA    2    2    b\n# fileA    3    3    c\n# fileB    4    1    d\n# fileB    5    2    e\n```\n\n##### AND gate\n```bash\n# For example there are two files:\n# fileA:\n# 1    0\n# 2    1\n# 3    1\n# 4    0\n# fileB:\n# 1    0\n# 2    1\n# 3    0\n# 4    1\n\nawk -v OFS='\\t' 'NR=FNR{a[$1]=$2;next} NF {print $1,((a[$1]=$2)? $2:\"0\")}' fileA fileB\n# 1    0\n# 2    1\n# 3    0\n# 4    0\n```\n\n##### Round all numbers of file (e.g. 2 significant figure)\n```bash\nawk '{while (match($0, /[0-9]+\\[0-9]+/)){\n    \\printf \"%s%.2f\", substr($0,0,RSTART-1),substr($0,RSTART,RLENGTH)\n    \\$0=substr($0, RSTART+RLENGTH)\n    \\}\n    \\print\n    \\}'\n```\n\n##### Give number/index to every row\n```bash\nawk '{printf(\"%s\\t%s\\n\",NR,$0)}'\n```\n\n##### Break combine column data into rows\n```bash\n# For example, separate the following content:\n# David    cat,dog\n# into\n# David    cat\n# David    dog\n\nawk '{split($2,a,\",\");for(i in a)print $1\"\\t\"a[i]}' filename\n\n# Detail here:　http://stackoverflow.com/questions/33408762/bash-turning-single-comma-separated-column-into-multi-line-string\n```\n\n##### Average a file (each line in file contains only one number)\n```bash\nawk '{s+=$1}END{print s/NR}'\n```\n\n##### Print field start with string (e.g Linux)\n```bash\nawk '$1 ~ /^Linux/'\n```\n\n##### Sort a row (e.g. 1 40  35  12  23  --\u003e 1 12    23  35  40)\n```bash\nawk ' {split( $0, a, \"\\t\" ); asort( a ); for( i = 1; i \u003c= length(a); i++ ) printf( \"%s\\t\", a[i] ); printf( \"\\n\" ); }'\n```\n\n##### Subtract previous row values (add column6 which equal to column4 minus last column5)\n```bash\nawk '{$6 = $4 - prev5; prev5 = $5; print;}'\n```\n\n## Xargs\n[[back to top](#handy-bash-one-liners)]\n\n##### Set tab as delimiter (default:space)\n```bash\nxargs -d\\t\n```\n\n##### Prompt commands before running commands\n```bash\nls|xargs -L1 -p head\n```\n\n##### Display 3 items per line\n```bash\necho 1 2 3 4 5 6| xargs -n 3\n# 1 2 3\n# 4 5 6\n\n```\n##### Prompt before execution\n```bash\necho a b c |xargs -p -n 3\n```\n\n##### Print command along with output\n```bash\nxargs -t abcd\n# bin/echo abcd\n# abcd\n\n```\n##### With find and rm\n```bash\nfind . -name \"*.html\"|xargs rm\n\n# when using a backtick\nrm `find . -name \"*.html\"`\n```\n\n##### Delete files with whitespace in filename (e.g. \"hello 2001\")\n```bash\nfind . -name \"*.c\" -print0|xargs -0 rm -rf\n```\n\n##### Show limits on command-line length\n```bash\nxargs --show-limits\n# Output from my Ubuntu:\n# Your environment variables take up 3653 bytes\n# POSIX upper limit on argument length (this system): 2091451\n# POSIX smallest allowable upper limit on argument length (all systems): 4096\n# Maximum length of command we could actually use: 2087798\n# Size of command buffer we are actually using: 131072\n# Maximum parallelism (--max-procs must be no greater): 2147483647\n```\n\n##### Move files to folder\n```bash\nfind . -name \"*.bak\" -print 0|xargs -0 -I {} mv {} ~/old\n\n# or\nfind . -name \"*.bak\" -print 0|xargs -0 -I file mv file ~/old\n```\n\n##### Move first 100th files to a directory (e.g. d1)\n```bash\nls |head -100|xargs -I {} mv {} d1\n```\n\n##### Parallel\n```bash\ntime echo {1..5} |xargs -n 1 -P 5 sleep\n\n# a lot faster than:\ntime echo {1..5} |xargs -n1 sleep\n```\n\n##### Copy all files from A to B\n```bash\nfind /dir/to/A -type f -name \"*.py\" -print 0| xargs -0 -r -I file cp -v -p file --target-directory=/path/to/B\n\n# v: verbose|\n# p: keep detail (e.g. owner)\n\n```\n\n##### With sed\n```bash\nls |xargs -n1 -I file sed -i '/^Pos/d' filename\n```\n\n##### Add the file name to the first line of file\n```bash\nls |sed 's/.txt//g'|xargs -n1 -I file sed -i -e '1 i\\\u003efile\\' file.txt\n```\n\n##### Count all files\n```bash\nls |xargs -n1 wc -l\n```\n\n##### Turn output into a single line\n```bash\nls -l| xargs\n```\n\n##### Count files within directories\n```bash\necho mso{1..8}|xargs -n1 bash -c 'echo -n \"$1:\"; ls -la \"$1\"| grep -w 74 |wc -l' --\n# \"--\" signals the end of options and display further option processing\n```\n\n##### Count lines in all file, also count total lines\n```bash\nls|xargs wc -l\n```\n##### Xargs and grep\n```bash\ncat grep_list |xargs -I{} grep {} filename\n```\n\n##### Xargs and sed (replace all old ip address with new ip address under /etc directory)\n```bash\ngrep -rl '192.168.1.111' /etc | xargs sed -i 's/192.168.1.111/192.168.2.111/g'\n```\n\n\n## Find\n[[back to top](#handy-bash-one-liners)]\n##### List all sub directory/file in the current directory\n```bash\nfind .\n```\n\n##### List all files under the current directory\n```bash\nfind . -type f\n```\n\n##### List all directories under the current directory\n```bash\nfind . -type d\n```\n\n##### Edit all files under current directory (e.g. replace 'www' with 'ww')\n```bash\nfind . -name '*.php' -exec sed -i 's/www/w/g' {} \\;\n\n# if there are no subdirectory\nreplace \"www\" \"w\" -- *\n# a space before *\n```\n##### Find and output only filename (e.g. \"mso\")\n```bash\nfind mso*/ -name M* -printf \"%f\\n\"\n```\n\n##### Find large files in the system (e.g. \u003e4G)\n```bash\nfind / -type f -size +4G\n```\n\n##### Find and delete file with size less than (e.g. 74 byte)\n```bash\nfind . -name \"*.mso\" -size -74c -delete\n\n# M for MB, etc\n```\n\n##### Find empty (0 byte) files\n```bash\nfind . -type f -empty\n# to further delete all the empty files\nfind . -type f -empty -delete\n```\n\n##### Recursively count all the files in a directory\n```bash\nfind . -type f | wc -l\n```\n\n## Condition and loop\n[[back to top](#handy-bash-one-liners)]\n\n##### If statement\n```bash\n# if and else loop for string matching\nif [[ \"$c\" == \"read\" ]]; then outputdir=\"seq\"; else outputdir=\"write\" ; fi\n\n# Test if myfile contains the string 'test':\nif grep -q hello myfile; then echo -e \"file contains the string!\" ; fi\n\n# Test if mydir is a directory, change to it and do other stuff:\nif cd mydir; then\n  echo 'some content' \u003emyfile\nelse\n  echo \u003e\u00262 \"Fatal error. This script requires mydir.\"\nfi\n\n# Check if a variable is null\nif [ -z \"$var\" ]; then echo \"NULL\"; else echo \"Not NULL\"; fi\n# or \n[ -z \"$var\" ] \u0026\u0026 echo \"NULL\"\n\n# Using test command (same as []), to test if the length of variable is nonzero\ntest -n \"$myvariable\" \u0026\u0026 echo myvariable is \"$myvariable\" || echo myvariable is not set\n\n# Test if file exist\nif [ -e 'filename' ]\nthen\n  echo -e \"file exists!\"\nfi\n\n# Test if file exist but also including symbolic links:\nif [ -e myfile ] || [ -L myfile ]\nthen\n  echo -e \"file exists!\"\nfi\n\n# Test if the value of x is greater or equal than 5\nif [ \"$x\" -ge 5 ]; then echo -e \"greater or equal than 5!\" ; fi\n\n# Test if the value of x is greater or equal than 5, in bash/ksh/zsh:\nif ((x \u003e= 5)); then echo -e \"greater or equal than 5!\" ; fi\n\n# Use (( )) for arithmetic operation\nif ((j==u+2)); then echo -e \"j==u+2!!\" ; fi\n\n# Use [[ ]] for comparison\nif [[ $age -gt 21 ]]; then echo -e \"forever 21!!\" ; fi\n\n```\n\n[More if commands](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html)\n\n##### For loop\n```bash\n# Echo the file name under the current directory\nfor i in $(ls); do echo file $i; done\n# or\nfor i in *; do echo file $i; done\n\n# Make directories listed in a file (e.g. myfile)\nfor dir in $(\u003cmyfile); do mkdir $dir; done\n\n# Press any key to continue each loop\nfor i in $(cat tpc_stats_0925.log |grep failed|grep -o '\\query\\w\\{1,2\\}'); do cat ${i}.log; read -rsp $'Press any key to continue...\\n' -n1 key; done\n\n# Print a file line by line when a key is pressed,\noifs=\"$IFS\"; IFS=$'\\n'; for line in $(cat myfile); do ...; done\nwhile read -r line; do ...; done \u003cmyfile\n\n# If only one word a line, simply\nfor line in $(cat myfile); do echo $line; read -n1; done\n\n# Loop through an array\nfor i in \"${arrayName[@]}\"; do echo $i; done\n\n```\n\n##### While loop,\n```bash\n# Column subtraction of a file (e.g. a 3 columns file)\nwhile read a b c; do echo $(($c-$b)); done \u003c \u003c(head filename)\n#there is a space between the two '\u003c's\n\n# Sum up column subtraction\ni=0; while read a b c; do ((i+=$c-$b)); echo $i; done \u003c \u003c(head filename)\n\n# Keep checking a running process (e.g. perl) and start another new process (e.g. python) immediately after it. (BETTER use the wait command! Ctrl+F 'wait')\nwhile [[ $(pidof perl) ]]; do echo f; sleep 10; done \u0026\u0026 python timetorunpython.py\n```\n\n##### switch (case in bash)\n```bash\nread type;\ncase $type in\n  '0')\n    echo 'how'\n    ;;\n  '1')\n    echo 'are'\n    ;;\n  '2')\n    echo 'you'\n    ;;\nesac\n```\n\n## Time\n[[back to top](#handy-bash-one-liners)]\n\n##### Find out the time require for executing a command\n```bash\ntime echo hi\n```\n\n##### Wait for some time (e.g 10s)\n```bash\nsleep 10\n```\n\n##### Print date with formatting\n```bash\ndate +%F\n# 2020-07-19\n\n# or\ndate +'%d-%b-%Y-%H:%M:%S'\n# 10-Apr-2020-21:54:40\n\n# Returns the current time with nanoseconds.\ndate +\"%T.%N\"\n# 11:42:18.664217000  \n\n# Get the seconds since epoch (Jan 1 1970) for a given date (e.g Mar 16 2021)\ndate -d \"Mar 16 2021\" +%s\n# 1615852800\n# or\ndate -d \"Tue Mar 16 00:00:00 UTC 2021\"  +%s\n# 1615852800  \n\n# Convert the number of seconds since epoch back to date\ndate --date @1615852800\n# Tue Mar 16 00:00:00 UTC 2021\n\n```\n\n##### Print current time point for N days ago or N days after\n```bash\n# print current date first (for the following example)\ndate +\"%F %H:%M:%S\"\n# 2023-03-11 16:17:09\n\n# print the time that is 1 day ago\ndate -d\"1 day ago\" +\"%F %H:%M:%S\"\n# 2023-03-10 16:17:09\n\n# print the time that is 7 days ago\ndate -d\"7 days ago\" +\"%F %H:%M:%S\"\n# 2023-03-04 16:17:09\n\n# print the time that is a week ago\ndate -d\"1 week ago\" +\"%F %H:%M:%S\"\n# 2023-03-04 16:17:09\n\n# add 1 day to date\ndate -d\"-1 day ago\" +\"%F %H:%M:%S\"\n# 2023-03-12 16:17:09\n```\n\n##### wait for random duration (e.g. sleep 1-5 second, like adding a jitter)\n```bash\nsleep $[ ( $RANDOM % 5 ) + 1 ]\n```\n\n##### Log out your account after a certain period of time (e.g 10 seconds)\n```bash\nTMOUT=10\n#once you set this variable, logout timer start running!\n```\n\n##### Set how long you want to run a command\n```bash\n# This will run the command 'sleep 10' for only 1 second.\ntimeout 1 sleep 10\n```\n\n##### Set when you want to run a command (e.g 1 min from now)\n```bash\nat now + 1min  #time-units can be minutes, hours, days, or weeks\nwarning: commands will be executed using /bin/sh\nat\u003e echo hihigithub \u003e~/itworks\nat\u003e \u003cEOT\u003e   # press Ctrl + D to exit\njob 1 at Wed Apr 18 11:16:00 2018\n```\n\n\n## Download\n[[back to top](#handy-bash-one-liners)]\n\n##### Download the content of this README.md (the one your are viewing now)\n```bash\ncurl https://raw.githubusercontent.com/onceupon/Bash-Oneliner/master/README.md | pandoc -f markdown -t man | man -l -\n\n# or w3m (a text based web browser and pager)\ncurl https://raw.githubusercontent.com/onceupon/Bash-Oneliner/master/README.md | pandoc | w3m -T text/html\n\n# or using emacs (in emac text editor)\nemacs --eval '(org-mode)' --insert \u003c(curl https://raw.githubusercontent.com/onceupon/Bash-Oneliner/master/README.md | pandoc -t org)\n\n# or using emacs (on terminal, exit using Ctrl + x then Ctrl + c)\nemacs -nw --eval '(org-mode)' --insert \u003c(curl https://raw.githubusercontent.com/onceupon/Bash-Oneliner/master/README.md | pandoc -t org)\n```\n\n##### Download all from a page\n```bash\nwget -r -l1 -H -t1 -nd -N -np -A mp3 -e robots=off http://example.com\n\n# -r: recursive and download all links on page\n# -l1: only one level link\n# -H: span host, visit other hosts\n# -t1: numbers of retries\n# -nd: don't make new directories, download to here\n# -N: turn on timestamp\n# -nd: no parent\n# -A: type (separate by ,)\n# -e robots=off: ignore the robots.txt file which stop wget from crashing the site, sorry example.com\n```\n\n##### Upload a file to web and download (https://transfer.sh/)\n```bash\n#  Upload a file (e.g. filename.txt):\ncurl --upload-file ./filename.txt https://transfer.sh/filename.txt\n# the above command will return a URL, e.g: https://transfer.sh/tG8rM/filename.txt\n\n# Next you can download it by:\ncurl https://transfer.sh/tG8rM/filename.txt -o filename.txt\n```\n\n##### Download file if necessary\n```bash\ndata=file.txt\nurl=http://www.example.com/$data\nif [ ! -s $data ];then\n    echo \"downloading test data...\"\n    wget $url\nfi\n```\n\n##### Wget to a filename (when a long name)\n```bash\nwget -O filename \"http://example.com\"\n```\n\n##### Wget files to a folder\n```bash\nwget -P /path/to/directory \"http://example.com\"\n```\n\n##### Instruct curl to follow any redirect until it reaches the final destination:\n```bash\ncurl -L google.com\n```\n\n## Random\n[[back to top](#handy-bash-one-liners)]\n##### Random generate password (e.g. generate 5 password each of length 13)\n```bash\nsudo apt install pwgen\npwgen 13 5\n#sahcahS9dah4a xieXaiJaey7xa UuMeo0ma7eic9 Ahpah9see3zai acerae7Huigh7\n```\n\n##### Random pick 100 lines from a file\n```bash\nshuf -n 100 filename\n```\n\n##### Random order (lucky draw)\n```bash\nfor i in a b c d e; do echo $i; done | shuf\n```\n\n##### Echo series of random numbers between a range (e.g. shuffle numbers from 0-100, then pick 15 of them randomly)\n```bash\nshuf -i 0-100 -n 15\n```\n\n##### Echo a random number\n```bash\necho $RANDOM\n```\n\n##### Random from 0-9\n```bash\necho $((RANDOM % 10))\n```\n\n##### Random from 1-10\n```bash\necho $(((RANDOM %10)+1))\n```\n\n## Xwindow\n[[back to top](#handy-bash-one-liners)]\n\nX11 GUI applications! Here are some GUI tools for you if you get bored by the text-only environment.\n\n##### Enable X11 forwarding,in order to use graphical application on servers\n```bash\nssh -X user_name@ip_address\n\n# or setting through xhost\n# --\u003e Install the following for Centos:\n# xorg-x11-xauth\n# xorg-x11-fonts-*\n# xorg-x11-utils\n```\n\n##### Little xwindow tools\n```bash\nxclock\nxeyes\nxcowsay\n```\n\n##### Open pictures/images from ssh server\n```bash\n1. ssh -X user_name@ip_address\n2. apt-get install eog\n3. eog picture.png\n```\n\n##### Watch videos on server\n```bash\n1. ssh -X user_name@ip_address\n2. sudo apt install mpv\n3. mpv myvideo.mp4\n```\n\n##### Use gedit on server (GUI editor)\n```bash\n1. ssh -X user_name@ip_address\n2. apt-get install gedit\n3. gedit filename.txt\n```\n\n##### Open PDF file from ssh server\n```bash\n1. ssh -X user_name@ip_address\n2. apt-get install evince\n3. evince filename.pdf\n```\n\n##### Use google-chrome browser from ssh server\n```bash\n1. ssh -X user_name@ip_address\n2. apt-get install libxss1 libappindicator1 libindicator7\n3. wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb\n4. sudo apt-get install -f\n5. dpkg -i google-chrome*.deb\n6. google-chrome\n ```\n\n\n## System\n[[back to top](#handy-bash-one-liners)]\n\n##### Work with yum history\n```bash\n# List yum history (e.g install, update)\nsudo yum history\n# Example output:\n# Loaded plugins: extras_suggestions, langpacks, priorities, update-motd\n# ID     | Login user               | Date and time    | Action(s)      | Altered\n# -------------------------------------------------------------------------------\n#     11 |  ... \u003cmyuser\u003e       | 2020-04-10 10:57 | Install        |    1 P\u003c\n#     10 |  ... \u003cmyuser\u003e       | 2020-03-27 05:21 | Install        |    1 \u003eP\n#      9 |  ... \u003cmyuser\u003e       | 2020-03-05 11:57 | I, U           |   56 *\u003c\n# ...\n\n# Show more details of a yum history (e.g. history #11)\nsudo yum history info 11\n\n# Undo a yum history (e.g. history #11, this will uninstall some packages)\nsudo yum history undo 11\n```\n\n##### Audit files to see who made changes to a file [RedHat based system only]\n```bash\n# To audit a directory recursively for changes (e.g. myproject)\nauditctl -w /path/to/myproject/ -p wa\n\n# If you delete a file name \"VIPfile\", the deletion is recorded in /var/log/audit/audit.log\nsudo grep VIPfile /var/log/audit/audit.log\n#type=PATH msg=audit(1581417313.678:113): item=1 name=\"VIPfile\" inode=300115 dev=ca:01 mode=0100664 ouid=1000 ogid=1000 rdev=00:00 nametype=DELETE cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0\n```\n\n##### Check out whether SELinux is enabled\n```bash\nsestatus\n# SELinux status:                 enabled\n# SELinuxfs mount:                /sys/fs/selinux\n# SELinux root directory:         /etc/selinux\n# Loaded policy name:             targeted\n# Current mode:                   enforcing\n# Mode from config file:          enforcing\n# Policy MLS status:              enabled\n# Policy deny_unknown status:     allowed\n# Max kernel policy version:      31\n```\n\n##### Generate public key from private key\n```bash\nssh-keygen -y -f ~/.ssh/id_rsa \u003e ~/.ssh/id_rsa.pub\n```\n\n##### Copy your default public key to remote user\n```bash\nssh-copy-id \u003cuser_name\u003e@\u003cserver_IP\u003e\n# then you need to enter the password\n# and next time you won't need to enter password when ssh to that user\n```\n\n##### Copy default public key to remote user using the required private key (e.g. use your mykey.pem key to copy your id_rsa.pub to the remote user)\n```bash\n# before you need to use mykey.pem to ssh to remote user.\nssh-copy-id -i ~/.ssh/id_rsa.pub -o \"IdentityFile ~/Downloads/mykey.pem\" \u003cuser_name\u003e@\u003cserver_IP\u003e\n# now you don't need to use key to ssh to that user.\n```\n\n##### SSH Agent Forwarding\n```bash\n# To bring your key with you when ssh to serverA, then ssh to serverB from serverA using the key.\nssh-agent\nssh-add /path/to/mykey.pem\nssh -A \u003cusername\u003e@\u003cIP_of_serverA\u003e\n# Next you can ssh to serverB\nssh \u003cusername\u003e@\u003cIP_of_serverB\u003e\n```\n\n##### Set the default user and key for a host when using SSH\n```bash\n# add the following to ~/.ssh/config\nHost myserver\n  User myuser\n  IdentityFile ~/path/to/mykey.pem\n\n# Next, you could run \"ssh myserver\" instead of \"ssh -i ~/path/to/mykey.pem myuser@myserver\"\n```\n\n##### Follow the most recent logs from service\n```bash\njournalctl -u \u003cservice_name\u003e -f\n```\n\n##### Eliminate the zombie\n```bash\n# A zombie is already dead, so you cannot kill it. You can eliminate the zombie by killing its parent.\n# First, find PID of the zombie\nps aux| grep 'Z'\n# Next find the PID of zombie's parent\npstree -p -s \u003czombie_PID\u003e\n# Then you can kill its parent and you will notice the zombie is gone.\nsudo kill 9 \u003cparent_PID\u003e\n```\n###### Show memory usage\n```bash\nfree -c 10 -mhs 1\n# print 10 times, at 1 second interval\n```\n\n##### Display CPU and IO statistics for devices and partitions.\n```bash\n# refresh every second\niostat -x -t 1\n```\n\n##### Display bandwidth usage on an network interface (e.g. enp175s0f0)\n```bash\niftop -i enp175s0f0\n```\n\n##### Tell how long the system has been running and number of users\n```bash\nuptime\n```\n\n##### Check if it's root running\n```bash\nif [ \"$EUID\" -ne 0 ]; then\n        echo \"Please run this as root\"\n        exit 1\nfi\n```\n##### Change shell of a user (e.g. bonnie)\n```bash\nchsh -s /bin/sh bonnie\n# /etc/shells: valid login shells\n```\n\n##### Change root / fake root / jail (e.g. change root to newroot)\n```bash\nchroot /home/newroot /bin/bash\n\n# To exit chroot\nexit\n```\n##### Display file status (size; access, modify and change time, etc) of a file (e.g. filename.txt)\n```bash\nstat filename.txt\n```\n\n##### Snapshot of the current processes\n```bash\nps aux\n```\n\n##### List processes by top memory usage\n```bash\nps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head\n```\n\n##### Display a tree of processes\n```bash\npstree\n\n# or\nps aux --forest\n```\n\n##### Find maximum number of processes\n```bash\ncat /proc/sys/kernel/pid_max\n```\n\n##### Print or control the kernel ring buffer\n```bash\ndmesg\n```\n\n##### Show IP address\n```bash\n$ip add show\n\n# or\nifconfig\n```\n\n##### Print previous and current SysV runlevel\n```bash\nrunlevel\n\n# or\nwho -r\n```\n\n##### Change SysV runlevel (e.g. 5)\n```bash\ninit 5\n# or\ntelinit 5\n```\n\n##### Display all available services in all runlevels,\n```bash\nchkconfig --list\n# update-rc.d equivalent to chkconfig in ubuntu\n```\n\n##### Check system version\n```bash\ncat /etc/*-release\n```\n\n##### Linux Programmer's Manuel: hier- description of the filesystem hierarchy\n```bash\nman hier\n```\n\n##### Control the systemd system and service manager\n```bash\n# e.g. check the status of cron service\nsystemctl status cron.service\n\n# e.g. stop cron service\nsystemctl stop cron.service\n```\n\n##### List job\n```bash\njobs -l\n```\n\n##### Run a program with modified priority (e.g. ./test.sh)\n```bash\n# nice value is adjustable from -20 (most favorable) to +19\n# the nicer the application, the lower the priority\n# Default niceness: 10; default priority: 80\n\nnice -10 ./test.sh\n```\n\n##### Export PATH\n```bash\nexport PATH=$PATH:~/path/you/want\n```\n\n##### Make file executable\n```bash\nchmod +x filename\n# you can now ./filename to execute it\n```\n\n##### Print system information\n```bash\nuname -a\n\n# Check system hardware-platform (x86-64)\nuname -i\n```\n\n##### Surf the net\n```bash\nlinks www.google.com\n```\n\n##### Add user, set passwd\n```bash\nuseradd username\npasswd username\n```\n\n##### Edit PS1 variable for bash (e.g. displaying the whole path)\n```bash\n1. vi ~/.bash_profile\n2. export PS1='\\u@\\h:\\w\\$'\n# $PS1 is a variable that defines the makeup and style of the command prompt\n# You could use emojis and add timestamp to every prompt using the following value:\n# export PS1=\"\\t@🦁:\\w\\$ \"\n3. source ~/.bash_profile\n```\n\n##### Edit environment setting (e.g. alias)\n```bash\n1. vi ~/.bash_profile\n2. alias pd=\"pwd\" //no more need to type that 'w'!\n3. source ~/.bash_profile\n```\n##### Print all alias\n```bash\nalias -p\n```\n\n##### Unalias (e.g. after alias ls='ls --color=auto')\n```bash\nunalias ls\n```\n\n##### Set and unset shell options\n```bash\n# print all shell options\nshopt\n\n# to unset (or stop) alias\nshopt -u expand_aliases\n\n# to set (or start) alias\nshopt -s expand_aliases\n```\n\n##### List environment variables (e.g. PATH)\n```bash\necho $PATH\n# list of directories separated by a colon\n```\n##### List all environment variables for current user\n```bash\nenv\n```\n##### Unset environment variable (e.g. unset variable 'MYVAR')\n```bash\nunset MYVAR\n```\n\n##### Show partition format\n```bash\nlsblk\n```\n\n##### Inform the OS of partition table changes\n```bash\npartprobe\n```\n\n##### Soft link program to bin\n```bash\nln -s /path/to/program /home/usr/bin\n# must be the whole path to the program\n```\n\n##### Show hexadecimal view of data\n```bash\nhexdump -C filename.class\n```\n\n##### Jump to different node\n```bash\nrsh node_name\n```\n\n##### Check port (active internet connection)\n```bash\nnetstat -tulpn\n```\n\n##### Print resolved symbolic links or canonical file names\n```bash\nreadlink filename\n```\n\n##### Find out the type of command and where it link to (e.g. python)\n```bash\ntype python\n# python is /usr/bin/python\n# There are 5 different types, check using the 'type -f' flag\n# 1. alias    (shell alias)\n# 2. function (shell function, type will also print the function body)\n# 3. builtin  (shell builtin)\n# 4. file     (disk file)\n# 5. keyword  (shell reserved word)\n\n# You can also use `which`\nwhich python\n# /usr/bin/python\n```\n\n##### List all functions names\n```bash\ndeclare -F\n```\n\n##### List total size of a directory\n```bash\ndu -hs .\n\n# or\ndu -sb\n```\n\n##### Copy directory with permission setting\n```bash\ncp -rp /path/to/directory\n```\n\n##### Store current directory\n```bash\npushd .\n\n# then pop\npopd\n\n# or use dirs to display the list of currently remembered directories.\ndirs -l\n```\n\n##### Show disk usage\n```bash\ndf -h\n\n# or\ndu -h\n\n# or\ndu -sk /var/log/* |sort -rn |head -10\n```\n\n##### check the Inode utilization\n```\ndf -i\n# Filesystem      Inodes  IUsed   IFree IUse% Mounted on\n# devtmpfs        492652    304  492348    1% /dev\n# tmpfs           497233      2  497231    1% /dev/shm\n# tmpfs           497233    439  496794    1% /run\n# tmpfs           497233     16  497217    1% /sys/fs/cgroup\n# /dev/nvme0n1p1 5037976 370882 4667094    8% /\n# tmpfs           497233      1  497232    1% /run/user/1000\n```\n\n##### Show all file system type\n```bash\ndf -TH\n```\n\n##### Show current runlevel\n```bash\nrunlevel\n```\n\n##### Switch runlevel\n```bash\ninit 3\n\n# or\ntelinit 3\n```\n\n##### Permanently modify runlevel\n```bash\n1. edit /etc/init/rc-sysinit.conf\n2. env DEFAULT_RUNLEVEL=2\n```\n\n##### Become root\n```bash\nsu\n```\n\n##### Become somebody\n```bash\nsu somebody\n```\n\n##### Report user quotes on device\n```bash\nrepquota -auvs\n```\n\n##### Get entries in a number of important databases\n```bash\ngetent database_name\n\n# (e.g. the 'passwd' database)\ngetent passwd\n# list all user account (all local and LDAP)\n\n# (e.g. fetch list of grop accounts)\ngetent group\n# store in database 'group'\n```\n\n##### Change owner of file\n```bash\nchown user_name filename\nchown -R user_name /path/to/directory/\n# chown user:group filename\n```\n\n##### Mount and unmount\n```bash\n# e.g. Mount /dev/sdb to /home/test\nmount /dev/sdb /home/test\n\n# e.g. Unmount /home/test\numount /home/test\n```\n\n##### List current mount detail\n```bash\nmount\n# or\ndf\n```\n\n##### List current usernames and user-numbers\n```bash\ncat /etc/passwd\n```\n\n##### Get all username\n```bash\ngetent passwd| awk '{FS=\"[:]\"; print $1}'\n```\n\n##### Show all users\n```bash\ncompgen -u\n```\n\n##### Show all groups\n```bash\ncompgen -g\n```\n\n##### Show group of user\n```bash\ngroup username\n```\n\n##### Show uid, gid, group of user\n```bash\nid username\n\n# variable for UID\necho $UID\n```\n\n##### Check if it's root\n```bash\nif [ $(id -u) -ne 0 ];then\n    echo \"You are not root!\"\n    exit;\nfi\n# 'id -u' output 0 if it's not root\n```\n\n##### Find out CPU information\n```bash\nmore /proc/cpuinfo\n\n# or\nlscpu\n```\n\n##### Set quota for user (e.g. disk soft limit: 120586240; hard limit: 125829120)\n```bash\nsetquota username 120586240 125829120 0 0 /home\n```\n\n##### Show quota for user\n```bash\nquota -v username\n```\n\n##### Display current libraries from the cache\n```bash\nldconfig -p\n```\n\n##### Print shared library dependencies (e.g. for 'ls')\n```bash\nldd /bin/ls\n```\n\n##### Check the most recent login of all users\n```bash\nlastlog\n```\n##### Check last reboot history\n```bash\nlast reboot\n```\n\n##### Edit path for all users\n```bash\njoe /etc/environment\n# edit this file\n```\n\n##### Show and set user limit\n```bash\nulimit -u\n```\n\n##### Print out number of cores/ processors\n```bash\nnproc --all\n```\n\n##### Check status of each core\n```\n1. top\n2. press '1'\n```\n\n##### Show jobs and PID\n```bash\njobs -l\n```\n\n##### List all running services\n```bash\nservice --status-all\n```\n\n##### Schedule shutdown server\n```bash\nshutdown -r +5 \"Server will restart in 5 minutes. Please save your work.\"\n```\n\n##### Cancel scheduled shutdown\n```bash\nshutdown -c\n```\n\n##### Broadcast to all users\n```bash\nwall -n hihi\n```\n\n##### Kill all process of a user\n```bash\npkill -U user_name\n```\n\n##### Kill all process of a program\n```bash\nkill -9 $(ps aux | grep 'program_name' | awk '{print $2}')\n```\n\n##### Set gedit preference on server\n```\n# You might have to install the following:\n\napt-get install libglib2.0-bin;\n# or\nyum install dconf dconf-editor;\nyum install dbus dbus-x11;\n\n# Check list\ngsettings list-recursively\n\n# Change some settings\ngsettings set org.gnome.gedit.preferences.editor highlight-current-line true\ngsettings set org.gnome.gedit.preferences.editor scheme 'cobalt'\ngsettings set org.gnome.gedit.preferences.editor use-default-font false\ngsettings set org.gnome.gedit.preferences.editor editor-font 'Cantarell Regular 12'\n```\n##### Add user to a group (e.g add user 'nice' to the group 'docker', so that he can run docker without sudo)\n```bash\nsudo gpasswd -a nice docker\n```\n\n##### Pip install python package without root\n```bash\n1. pip install --user package_name\n2. You might need to export ~/.local/bin/ to PATH: export PATH=$PATH:~/.local/bin/\n```\n\n##### Removing old linux kernels (when /boot almost full...)\n```bash\n1. uname -a  #check current kernel, which should NOT be removed\n2. sudo apt-get purge linux-image-X.X.X-X-generic  #replace old version\n```\n\n\n##### Change hostname\n```bash\nsudo hostname your-new-name\n\n# if not working, do also:\nhostnamectl set-hostname your-new-hostname\n# then check with:\nhostnamectl\n# Or check /etc/hostname\n\n# If still not working..., edit:\n/etc/sysconfig/network\n/etc/sysconfig/network-scripts/ifcfg-ensxxx\n#add HOSTNAME=\"your-new-hostname\"\n ```\n\n##### List installed packages\n```bash\napt list --installed\n\n# or on Red Hat:\nyum list installed\n```\n\n##### Check for package update\n```bash\napt list --upgradeable\n\n# or\nsudo yum check-update\n```\n\n##### Run yum update excluding a package (e.g. do not update php packages)\n```bash\nsudo yum update --exclude=php*\n```\n\n##### Check which file make the device busy on umount\n```bash\nlsof /mnt/dir\n```\n\n##### When sound not working\n```bash\nkillall pulseaudio\n# then press Alt-F2 and type in pulseaudio\n```\n\n##### List information about SCSI devices\n```bash\nlsscsi\n```\n\n##### Tutorial for setting up your own DNS server\nhttp://onceuponmine.blogspot.tw/2017/08/set-up-your-own-dns-server.html\n\n##### Tutorial for creating a simple daemon\nhttp://onceuponmine.blogspot.tw/2017/07/create-your-first-simple-daemon.html\n\n##### Tutorial for using your gmail to send email\nhttp://onceuponmine.blogspot.tw/2017/10/setting-up-msmtprc-and-use-your-gmail.html\n\n##### Using telnet to test open ports, test if you can connect to a port (e.g 53) of a server (e.g 192.168.2.106)\n```bash\ntelnet 192.168.2.106 53\n```\n\n##### Change network maximum transmission unit (mtu) (e.g. change to 9000)\n```bash\nifconfig eth0 mtu 9000\n```\n\n##### Get pid of a running process (e.g python)\n```bash\npidof python\n\n# or\nps aux|grep python\n```\n\n##### Check status of a process using PID\n```bash\nps -p \u003cPID\u003e\n\n# or\ncat /proc/\u003cPID\u003e/status\ncat /proc/\u003cPID\u003e/stack\ncat /proc/\u003cPID\u003e/stat\n```\n\n##### NTP\n```bash\n# Start ntp:\nntpd\n\n# Check ntp:\nntpq -p\n```\n\n##### Remove unnecessary files to clean your server\n```bash\nsudo apt-get autoremove\nsudo apt-get clean\nsudo rm -rf ~/.cache/thumbnails/*\n\n# Remove old kernal:\nsudo dpkg --list 'linux-image*'\nsudo apt-get remove linux-image-OLDER_VERSION\n```\n\n##### Increase/ resize root partition (root partition is an LVM logical volume)\n```bash\npvscan\nlvextend -L +130G /dev/rhel/root -r\n# Adding -r will grow filesystem after resizing the volume.\n```\n\n##### Create a UEFI Bootable USB drive (e.g. /dev/sdc1)\n```bash\nsudo dd if=~/path/to/isofile.iso of=/dev/sdc1 oflag=direct bs=1048576\n```\n\n##### Locate and remove a package\n```bash\nsudo dpkg -l | grep \u003cpackage_name\u003e\nsudo dpkg --purge \u003cpackage_name\u003e\n```\n\n##### Create a ssh tunnel\n```bash\nssh -f -L 9000:targetservername:8088 root@192.168.14.72 -N\n#-f: run in background; -L: Listen; -N: do nothing\n# the 9000 of your computer is now connected to the 8088 port of the targetservername through 192.168.14.72\n# so that you can see the content of targetservername:8088 by entering localhost:9000 from your browser.\n```\n##### Get process ID of a process (e.g. sublime_text)\n```bash\n# pidof\npidof sublime_text\n\n# pgrep, you don't have to type the whole program name\npgrep sublim\n\n# pgrep, echo 1 if process found, echo 0 if no such process\npgrep -q sublime_text \u0026\u0026 echo 1 || echo 0\n\n# top, takes longer time\ntop|grep sublime_text\n```\n\n##### Some benchmarking tools for your server\n[aio-stress](https://openbenchmarking.org/test/pts/aio-stress) - AIO benchmark.  \n[bandwidth](https://zsmith.co/bandwidth.html) - memory bandwidth benchmark.  \n[bonnie++](https://www.coker.com.au/bonnie++/) - hard drive and file system performance benchmark.  \n[dbench](https://dbench.samba.org/) -  generate I/O workloads to either a filesystem or to a networked CIFS or NFS server.  \n[dnsperf](https://www.dnsperf.com/) - authorative and recursing DNS servers.  \n[filebench](https://github.com/filebench/filebench) - model based file system workload generator.  \n[fio](https://linux.die.net/man/1/fio) - I/O  benchmark.  \n[fs_mark](https://github.com/josefbacik/fs_mark) - synchronous/async file creation benchmark.  \n[httperf](https://github.com/httperf/httperf) - measure web server performance.  \n[interbench](https://github.com/ckolivas/interbench) - linux interactivity  benchmark.  \n[ioblazer](https://labs.vmware.com/flings/ioblazer) - multi-platform storage stack micro-benchmark.  \n[iozone](http://www.iozone.org/) - filesystem benchmark.  \n[iperf3](https://iperf.fr/iperf-download.php) - measure TCP/UDP/SCTP performance.  \n[kcbench](https://github.com/knurd/kcbench) - kernel compile benchmark, compiles a kernel and measures the time it takes.  \n[lmbench](http://www.bitmover.com/lmbench/) - Suite of simple, portable benchmarks.  \n[netperf](https://github.com/HewlettPackard/netperf) - measure network performance, test unidirectional throughput, and end-to-end latency.  \n[netpipe](https://linux.die.net/man/1/netpipe) - network protocol independent performance evaluator.  \n[nfsometer](http://wiki.linux-nfs.org/wiki/index.php/NFSometer) - NFS performance framework.  \n[nuttcp](https://www.nuttcp.net/Welcome%20Page.html) - measure network performance.  \n[phoronix-test-suite](https://www.phoronix-test-suite.com/) - comprehensive automated testing and benchmarking platform.  \n[seeker](https://github.com/fidlej/seeker) - portable disk seek benchmark.  \n[siege](https://github.com/JoeDog/siege) - http load tester and benchmark.  \n[sockperf](https://github.com/Mellanox/sockperf) - network benchmarking utility over socket API.  \n[spew](https://linux.die.net/man/1/spew) - measures I/O performance and/or generates I/O load.  \n[stress](https://people.seas.harvard.edu/~apw/stress/) - workload generator for POSIX systems.  \n[sysbench](https://github.com/akopytov/sysbench) - scriptable database and system performance benchmark.  \n[tiobench](https://github.com/mkuoppal/tiobench) - threaded IO benchmark.  \n[unixbench](https://github.com/kdlucas/byte-unixbench) - the original BYTE UNIX benchmark suite, provide a basic indicator of the performance of a Unix-like system.  \n[wrk](https://github.com/wg/wrk) - HTTP benchmark.  \n\n\n##### Performance monitoring tool - sar\n```bash\n# installation\n# It collects the data every 10 minutes and generate its report daily. crontab file (/etc/cron.d/sysstat) is responsible for collecting and generating reports.\nyum install sysstat\nsystemctl start sysstat\nsystemctl enable sysstat\n\n# show CPU utilization 5 times every 2 seconds.\nsar 2 5\n\n# show memory  utilization 5 times every 2 seconds.\nsar -r 2 5\n\n# show paging statistics 5 times every 2 seconds.\nsar -B 2 5\n\n# To generate all network statistic:\nsar -n ALL\n\n# reading SAR log file using -f\nsar -f /var/log/sa/sa31|tail\n```\n\n##### Reading from journal file\n```bash\njournalctl --file ./log/journal/a90c18f62af546ccba02fa3734f00a04/system.journal  --since \"2020-02-11 00:00:00\"\n```\n\n##### Show a listing of last logged in users\n```bash\nlast\n```\n\n##### Show a listing of unsuccessful (bad) login attempts \n```bash\nlastb\n```\n\n##### Show a listing of current logged in users, print information of them\n```bash\nwho\n```\n##### Show who is logged on and what they are doing\n```bash\nw\n```\n\n##### Print the user names of users currently logged in to the current host.\n```bash\nusers\n```\n\n##### Stop tailing a file on program terminate\n```bash\ntail -f --pid=\u003cPID\u003e filename.txt\n# replace \u003cPID\u003e with the process ID of the program.\n```\n\n##### List all enabled services\n```bash\nsystemctl list-unit-files|grep enabled\n```\n\n\n## Hardware\n[[back to top](#handy-bash-one-liners)]\n\n##### Collect and summarize all hardware info of your machine\n```bash\nlshw -json \u003ereport.json\n# Other options are: [ -html ]  [ -short ]  [ -xml ]  [ -json ]  [ -businfo ]  [ -sanitize ] ,etc\n```\n\n##### Finding Out memory device detail\n```bash\nsudo dmidecode -t memory\n```\n\n##### Print detail of CPU hardware\n```bash\ndmidecode -t 4\n#          Type   Information\n#          0   BIOS\n#          1   System\n#          2   Base Board\n#          3   Chassis\n#          4   Processor\n#          5   Memory Controller\n#          6   Memory Module\n#          7   Cache\n#          8   Port Connector\n#          9   System Slots\n#         11   OEM Strings\n#         13   BIOS Language\n#         15   System Event Log\n#         16   Physical Memory Array\n#         17   Memory Device\n#         18   32-bit Memory Error\n#         19   Memory Array Mapped Address\n#         20   Memory Device Mapped Address\n#         21   Built-in Pointing Device\n#         22   Portable Battery\n#         23   System Reset\n#         24   Hardware Security\n#         25   System Power Controls\n#         26   Voltage Probe\n#         27   Cooling Device\n#         28   Temperature Probe\n#         29   Electrical Current Probe\n#         30   Out-of-band Remote Access\n#         31   Boot Integrity Services\n#         32   System Boot\n#         34   Management Device\n#         35   Management Device Component\n#         36   Management Device Threshold Data\n#         37   Memory Channel\n#         38   IPMI Device\n#         39   Power Supply\n```\n##### Count the number of Segate hard disks\n```bash\nlsscsi|grep SEAGATE|wc -l\n# or\nsg_map -i -x|grep SEAGATE|wc -l\n```\n\n##### Get UUID of a disk (e.g. sdb)\n```bash\nlsblk -f /dev/sdb\n\n# or\nsudo blkid /dev/sdb\n```\n\n##### Generate an UUID\n```bash\nuuidgen\n```\n\n##### Print detail of all hard disks\n```bash\nlsblk -io KNAME,TYPE,MODEL,VENDOR,SIZE,ROTA\n#where ROTA means rotational device / spinning hard disks (1 if true, 0 if false)\n```\n\n##### List all PCI (Peripheral Component Interconnect) devices\n```bash\nlspci\n# List information about NIC\nlspci | egrep -i --color 'network|ethernet'\n```\n\n##### List all USB devices\n```bash\nlsusb\n```\n\n##### Linux modules\n```bash\n# Show the status of modules in the Linux Kernel\nlsmod\n\n# Add and remove modules from the Linux Kernel\nmodprobe\n\n# or\n# Remove a module\nrmmod\n\n# Insert a module\ninsmod\n```\n\n##### Controlling IPMI-enabled devices (e.g. BMC)\n```bash\n# Remotely finding out power status of the server\nipmitool -U \u003cbmc_username\u003e -P \u003cbmc_password\u003e -I lanplus -H \u003cbmc_ip_address\u003e power status\n\n# Remotely switching on server\nipmitool -U \u003cbmc_username\u003e -P \u003cbmc_password\u003e -I lanplus -H \u003cbmc_ip_address\u003e power on\n\n# Turn on panel identify light (default 15s)\nipmitool chassis identify 255\n\n# Found out server sensor temperature\nipmitool sensors |grep -i Temp\n\n# Reset BMC\nipmitool bmc reset cold\n\n# Prnt BMC network\nipmitool lan print 1\n\n# Setting BMC network\nipmitool -I bmc lan set 1 ipaddr 192.168.0.55\nipmitool -I bmc lan set 1 netmask 255.255.255.0\nipmitool -I bmc lan set 1 defgw ipaddr 192.168.0.1\n```\n\n\n## Networking\n[[back to top](#handy-bash-one-liners)]\n\n##### Resolve a domain to IP address(es)\n```bash\ndig +short www.example.com\n\n# or\nhost www.example.com\n```\n\n##### Check public IP address\n```bash\ncurl http://checkip.amazonaws.com\n```\n\n##### Get DNS TXT record a of domain\n```bash\ndig -t txt www.example.com\n\n# or\nhost -t txt www.example.com\n```\n\n##### Send a ping with a limited TTL to 10 (TTL: Time-To-Live, which is the maximum number of hops that a packet can travel across the Internet before it gets discarded.)\n```bash\nping 8.8.8.8 -t 10\n```\n\n##### Print the route packets trace to network host\n```bash\ntraceroute google.com\n```\n\n##### Check connection to host (e.g. check connection to port 80 and 22 of google.com)\n```bash\nnc -vw5 google.com 80\n# Connection to google.com 80 port [tcp/http] succeeded!\n\nnc -vw5 google.com 22\n# nc: connect to google.com port 22 (tcp) timed out: Operation now in progress\n# nc: connect to google.com port 22 (tcp) failed: Network is unreachable\n```\n\n##### Nc as a chat tool!\n```bash\n# From server A:\n$ sudo nc -l 80\n# then you can connect to the 80 port from another server (e.g. server B):\n# e.g. telnet \u003cserver A IP address\u003e 80\n# then type something in server B\n# and you will see the result in server A!\n```\n\n##### Check which ports are listening for TCP connections from the network\n```bash\n# note that some companies might not like you using nmap\nnmap -sT -O localhost\n\n# check port 0-65535\nnmap  -p0-65535 localhost\n```\n##### Check if a host is up and scan for open ports, also skip host discovery.\n```bash\n# skips checking if the host is alive. this may sometimes cause a false positive, stopping the scan.\n$ nmap google.com -Pn\n\n# Example output:\n# Starting Nmap 7.01 ( https://nmap.org ) at 2020-07-18 22:59 CST\n# Nmap scan report for google.com (172.217.24.14)\n# Host is up (0.013s latency).\n# Other addresses for google.com (not scanned): 2404:6800:4008:802::200e\n# rDNS record for 172.217.24.14: tsa01s07-in-f14.1e100.net\n# Not shown: 998 filtered ports\n# PORT    STATE SERVICE\n# 80/tcp  open  http\n# 443/tcp open  https\n#\n# Nmap done: 1 IP address (1 host up) scanned in 3.99 seconds\n```\n##### Scan for open ports and OS and version detection (e.g. scan the domain \"scanme.nmap.org\")\n```bash\n$ nmap -A -T4 scanme.nmap.org\n# -A to enable OS and version detection, script scanning, and traceroute; -T4 for faster execution\n```\n\n##### Look up website information (e.g. name server), searches for an object in a RFC 3912 database\n```bash\nwhois google.com\n```\n\n##### Show the SSL certificate of a domain\n```bash\nopenssl s_client -showcerts -connect www.example.com:443\n```\n\n##### Display network interfaces and their associated IP addresses\n```bash\nip a\n```\n\n##### Display route table\n```bash\nip r\n```\n\n##### Display ARP cache (ARP cache displays the MAC addresses of device in the same network that you have connected to)\n```bash\nip n\n```\n\n##### Add transient IP addres (reset after reboot) (e.g. add 192.168.140.3/24 to device eno16777736)\n```bash\nip address add 192.168.140.3/24 dev eno16777736\n```\n\n##### Persisting network configuration changes\n```bash\nsudo vi /etc/sysconfig/network-scripts/ifcfg-enoxxx\n# then edit the fields: BOOTPROT, DEVICE, IPADDR, NETMASK, GATEWAY, DNS1 etc\n```\n##### Refresh NetworkManager\n```bash\nsudo nmcli c reload\n```\n\n##### Restart all interfaces\n```bash\nsudo systemctl restart network.service\n```\n\n##### To view hostname, OS, kernal, architecture at the same time!\n```bash\nhostnamectl\n```\n\n##### Set hostname (set all transient, static, pretty hostname at once)\n```bash\nhostnamectl set-hostname \"mynode\"\n```\n\n##### Find out the web server (e.g Nginx or Apache) of a website\n```bash\ncurl -I http://example.com/\n# HTTP/1.1 200 OK\n# Server: nginx\n# Date: Thu, 02 Jan 2020 07:01:07 GMT\n# Content-Type: text/html\n# Content-Length: 1119\n# Connection: keep-alive\n# Vary: Accept-Encoding\n# Last-Modified: Mon, 09 Sep 2019 10:37:49 GMT\n# ETag: \"xxxxxx\"\n# Accept-Ranges: bytes\n# Vary: Accept-Encoding\n```\n##### Find out the time spent between request and response\n```\ncurl -v -o /dev/null -s -w 'Total: %{time_total}s\\n' google.com\n```\n\n##### Find out the http status code of a URL\n```bash\ncurl -s -o /dev/null -w \"%{http_code}\" https://www.google.com\n```\n\n##### Unshorten a shortended URL\n```bash\ncurl -s -o /dev/null -w \"%{redirect_url}\" https://bit.ly/34EFwWC\n```\n\n##### Perform network throughput tests\n```bash\n# server side:\n$ sudo iperf -s -p 80\n\n# client side:\niperf -c \u003cserver IP address\u003e --parallel 2 -i 1 -t 2 -p 80\n```\n\n##### To block port 80 (HTTP server) using iptables.\n```bash\nsudo iptables -A INPUT -p tcp --dport 80 -j DROP\n\n# only block connection from an IP address\nsudo iptables –A INPUT –s \u003cIP\u003e -p tcp –dport 80 –j DROP\n```\n\n## Data wrangling\n[[back to top](#handy-bash-one-liners)]\n\n##### Print some words that start with a particular string (e.g. words start with 'phy')\n```bash\n# If file is not specified, the file /usr/share/dict/words is used.\nlook phy|head -n 10\n# phycic\n# Phyciodes\n# phycite\n# Phycitidae\n# phycitol\n# phyco-\n# phycochrom\n# phycochromaceae\n# phycochromaceous\n# phycochrome\n```\n\n##### Repeat printing string n times (e.g. print 'hello world' five times)\n```bash\nprintf 'hello world\\n%.0s' {1..5}\n```\n##### Do not echo the trailing newline\n```bash\nusername=`echo -n \"bashoneliner\"`\n```\n\n##### Copy a file to multiple files (e.g copy fileA to file(B-D))\n```bash\ntee \u003cfileA fileB fileC fileD \u003e/dev/null\n```\n\n##### Delete all non-printing characters\n```bash\ntr -dc '[:print:]' \u003c filename\n```\n\n##### Remove newline / nextline\n```bash\ntr --delete '\\n' \u003cinput.txt \u003eoutput.txt\n```\n##### Replace newline\n```bash\ntr '\\n' ' ' \u003cfilename\n```\n\n##### To uppercase/lowercase\n```bash\ntr /a-z/ /A-Z/\n\n```\n##### Translate a range of characters (e.g. substitute a-z into a)\n```bash\necho 'something' |tr a-z a\n# aaaaaaaaa\n```\n\n##### Compare two files (e.g. fileA, fileB)\n\n```bash\ndiff fileA fileB\n# a: added; d:delete; c:changed\n\n# or\nsdiff fileA fileB\n# side-to-side merge of file differences\n```\n\n##### Compare two files, strip trailing carriage return/ nextline (e.g. fileA, fileB)\n```bash\ndiff fileA fileB --strip-trailing-cr\n```\n\n##### Find common/differing lines\n```bash\n# having two sorted and uniqed files (for example after running `$ sort -uo fileA fileA` and same for fileB):\n# ------\n# fileA:\n# ------\n# joey\n# kitten\n# piglet\n# puppy\n# ------\n# fileB:\n# ------\n# calf\n# chick\n# joey\n# puppy\n#\n# Find lines in both files\ncomm -12 fileA fileB\n# joey\n# puppy\n#\n# Find lines in fileB that are NOT in fileA\ncomm -13 fileA fileB\n# calf\n# chick\n#\n# Find lines in fileA that are NOT in fileB\ncomm -23 fileA fileB\n# kitten\n# piglet\n```\n\n##### Number a file (e.g. fileA)\n\n```bash\nnl fileA\n\n# or\nnl -nrz fileA\n# add leading zeros\n\n# or\nnl -w1 -s ' '\n# making it simple, blank separate\n```\n\n##### Join two files field by field with tab (default join by the first column of both file, and default separator is space)\n```bash\n# fileA and fileB should have the same ordering of lines.\njoin -t '\\t' fileA fileB\n\n# Join using specified field (e.g. column 3 of fileA and column 5 of fileB)\njoin -1 3 -2 5 fileA fileB\n```\n\n##### Combine/ paste two or more files into columns (e.g. fileA, fileB, fileC)\n```bash\npaste fileA fileB fileC\n# default tab separate\n```\n\n##### Group/combine rows into one row\n```bash\n# e.g.\n# AAAA\n# BBBB\n# CCCC\n# DDDD\ncat filename|paste - -\n# AAAABBBB\n# CCCCDDDD\ncat filename|paste - - - -\n# AAAABBBBCCCCDDDD\n```\n\n##### Fastq to fasta (fastq and fasta are common file formats for bioinformatics sequence data)\n```bash\ncat file.fastq | paste - - - - | sed 's/^@/\u003e/g'| cut -f1-2 | tr '\\t' '\\n' \u003efile.fa\n```\n\n##### Reverse string\n```bash\necho 12345| rev\n```\n\n##### Generate sequence 1-10\n```bash\nseq 10\n```\n\n##### Find average of input list/file of integers\n```bash\ni=`wc -l filename|cut -d ' ' -f1`; cat filename| echo \"scale=2;(`paste -sd+`)/\"$i|bc\n```\n\n##### Generate all combination (e.g. 1,2)\n```bash\necho {1,2}{1,2}\n# 1 1, 1 2, 2 1, 2 2\n```\n\n##### Generate all combination (e.g. A,T,C,G)\n```bash\nset = {A,T,C,G}\ngroup= 5\nfor ((i=0; i\u003c$group; i++)); do\n    repetition=$set$repetition; done\n    bash -c \"echo \"$repetition\"\"\n```\n\n##### Read file content to variable\n```bash\nfoo=$(\u003ctest1)\n```\n\n##### Echo size of variable\n```bash\necho ${#foo}\n```\n\n##### Echo a tab\n```bash\necho -e ' \\t '\n```\n\n##### Split file into smaller file\n```bash\n# Split by line (e.g. 1000 lines/smallfile)\nsplit -d -l 1000 largefile.txt\n\n# Split by byte without breaking lines across files\nsplit -C 10 largefile.txt\n```\n\n##### Create a large amount of dummy files (e.g 100000 files, 10 bytes each):\n```bash\n#1. Create a big file\ndd if=/dev/zero of=bigfile bs=1 count=1000000\n\n#2. Split the big file to 100000 10-bytes files\n split -b 10 -a 10 bigfile\n```\n\n##### Rename all files (e.g. remove ABC from all .gz files)\n```bash\nrename 's/ABC//' *.gz\n```\n\n##### Remove file extension (e.g remove .gz from filename.gz)\n```bash\nbasename filename.gz .gz\n\nzcat filename.gz\u003e $(basename filename.gz .gz).unpacked\n```\n\n##### Add file extension to all file(e.g add .txt)\n```bash\nrename s/$/.txt/ *\n# You can use rename -n s/$/.txt/ * to check the result first, it will only print sth like this:\n# rename(a, a.txt)\n# rename(b, b.txt)\n# rename(c, c.txt)\n```\n\n##### Squeeze repeat patterns (e.g. /t/t --\u003e /t)\n```bash\ntr -s \"/t\" \u003c filename\n```\n\n##### Do not print nextline with echo\n```bash\necho -e 'text here \\c'\n```\n\n##### View first 50 characters of file\n```bash\nhead -c 50 filename\n```\n\n##### Cut and get last column of a file\n```bash\ncat file|rev | cut -d/ -f1 | rev\n```\n\n##### Add one to variable/increment/ i++ a numeric variable (e.g. $var)\n```bash\n((var++))\n# or\nvar=$((var+1))\n\n```\n##### Cut the last column\n```bash\ncat filename|rev|cut -f1|rev\n```\n\n##### Create or replace a file with contents\n```bash\ncat \u003emyfile\nlet me add sth here\n# exit with ctrl+d\n\n# or using tee\ntee myfile\nlet me add sth else here\n# exit with ctrl+d\n```\n\n##### Append to a file with contents\n```bash\ncat \u003e\u003emyfile\nlet me add sth here\n# exit with ctrl+d\n\n# or\ncat \u003c\u003c EoF \u003e\u003e filename\n\u003e add something here\n\u003e EoF \n\n# or using tee\ntee -a myfile\nlet me add sth else here\n# exit with ctrl+d\n```\n\n##### Clear the contents of a file (e.g. filename)\n```bash\n\u003efilename\n```\n\n##### Append to file (e.g. hihi)\n```bash\necho 'hihi' \u003e\u003efilename\n```\n\n##### Working with json data\n```bash\n# Install the useful jq package\n# sudo apt-get install jq\n# e.g. to get all the values of the 'url' key, simply pipe the json to the following jq command(you can use .[]. to select inner json, i.e jq '.[].url')\ncat file.json | jq '.url'\n```\n\n##### Decimal to Binary (e.g get binary of 5)\n```bash\nD2B=({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1})\necho -e ${D2B[5]}\n#00000101\necho -e ${D2B[255]}\n#11111111\n```\n\n##### Wrap each input line to fit in specified width (e.g 4 integers per line)\n```bash\necho \"00110010101110001101\" | fold -w4\n# 0011\n# 0010\n# 1011\n# 1000\n# 1101\n```\n\n##### Sort a file by column and keep the original order\n```bash\nsort -k3,3 -s\n```\n\n##### Right align a column (right align the 2nd column)\n```bash\ncat file.txt|rev|column -t|rev\n```\n\n##### To both view and store the output\n```bash\necho 'hihihihi' | tee outputfile.txt\n# use '-a' with tee to append to file.\n```\n\n##### Show non-printing (Ctrl) characters with cat\n```bash\ncat -v filename\n```\n\n##### Convert tab to space\n```bash\nexpand filename\n```\n\n##### Convert space to tab\n```bash\nunexpand filename\n```\n\n##### Display file in octal ( you can also use od to display hexadecimal, decimal, etc)\n```bash\nod filename\n```\n\n##### Reverse cat a file\n```bash\ntac filename\n```\n\n##### Reverse the result from `uniq -c`\n```bash\nwhile read a b; do yes $b |head -n $a ; done \u003ctest.txt\n```\n\n\n## Others\n[[back to top](#handy-bash-one-liners)]\n\n##### Describe the format and characteristics of image files\n```bash\nidentify myimage.png\n#myimage.png PNG 1049x747 1049x747+0+0 8-bit sRGB 1.006MB 0.000u 0:00.000\n```\n\n##### Bash auto-complete (e.g. show options \"now tomorrow never\" when you press'tab' after typing \"dothis\")\n[More examples](https://iridakos.com/tutorials/2018/03/01/bash-programmable-completion-tutorial.html)\n```bash\ncomplete -W \"now tomorrow never\" dothis\n# ~$ dothis  \n# never     now       tomorrow\n# press 'tab' again to auto-complete after typing 'n' or 't'\n```\n##### Displays a calendar\n```bash\n# print the current month, today will be highlighted.\ncal\n# October 2019      \n# Su Mo Tu We Th Fr Sa  \n#    1  2  3  4  5  \n# 6  7  8  9 10 11 12  \n# 13 14 15 16 17 18 19  \n# 20 21 22 23 24 25 26  \n# 27 28 29 30 31  \n\n# only display November\ncal -m 11\n```\n\n##### Convert the hexadecimal MD5 checksum value into its base64-encoded format.\n```bash\nopenssl md5 -binary /path/to/file| base64\n# NWbeOpeQbtuY0ATWuUeumw==\n```\n\n##### Forces applications to use the default language for output\n```bash\nexport LC_ALL=C\n\n# to revert:\nunset LC_ALL\n```\n##### Encode strings as Base64 strings\n```bash\necho test|base64\n#dGVzdAo=\n```\n\n##### Get parent directory of current directory\n```bash\ndirname `pwd`\n```\n\n##### Read .gz file without extracting\n\n```bash\nzmore filename\n\n# or\nzless filename\n```\n\n##### Run command in background, output error file\n```bash\nsome_commands  \u0026\u003elog \u0026\n\n# or\nsome_commands 2\u003elog \u0026\n\n# or\nsome_commands 2\u003e\u00261| tee logfile\n\n# or\nsome_commands |\u0026 tee logfile\n\n# or\nsome_commands 2\u003e\u00261 \u003e\u003eoutfile\n#0: standard input; 1: standard output; 2: standard error\n```\n\n##### Run multiple commands in background\n```bash\n# run sequentially\n(sleep 2; sleep 3) \u0026\n\n# run parallelly\nsleep 2 \u0026 sleep 3 \u0026\n```\n\n##### Run process even when logout (immune to hangups, with output to a non-tty)\n```bash\n# e.g. Run myscript.sh even when log out.\nnohup bash myscript.sh\n```\n\n##### Send mail\n```bash\necho 'heres the content'| mail -a /path/to/attach_file.txt -s 'mail.subject' me@gmail.com\n# use -a flag to set send from (-a \"From: some@mail.tld\")\n```\n\n##### Convert .xls to csv\n```bash\nxls2csv filename\n```\n\n##### Make BEEP sound\n```bash\nspeaker-test -t sine -f 1000 -l1\n```\n\n##### Set beep duration\n```bash\n(speaker-test -t sine -f 1000) \u0026 pid=$!;sleep 0.1s;kill -9 $pid\n```\n\n##### Editing your history\n```bash\nhistory -w\nvi ~/.bash_history\nhistory -r\n\n# or\nhistory -d [line_number]\n```\n\n##### Interacting with history\n```bash\n# list 5 previous command (similar to `history |tail -n 5` but wont print the history command itself)\nfc -l -5\n```\n\n##### Delete current bash command\n```bash\nCtrl+U\n\n# or\nCtrl+C\n\n# or\nAlt+Shift+#\n# to make it to history\n```\n\n##### Add something to history (e.g. \"addmetohistory\")\n```bash\n# addmetodistory\n# just add a \"#\" before~~\n```\n\n##### Get last history/record filename\n```bash\nhead !$\n```\n\n##### Clean screen\n```bash\nclear\n# or simply Ctrl+l\n```\n\n##### Backup with rsync\n```bash\nrsync -av filename filename.bak\nrsync -av directory directory.bak\nrsync -av --ignore_existing directory/ directory.bak\nrsync -av --update directory directory.bak\n\nrsync -av directory user@ip_address:/path/to/directory.bak\n# skip files that are newer on receiver (i prefer this one!)\n```\n\n##### Create a temporary directory and `cd` into it\n```bash\ncd $(mktemp -d)\n# for example, this will create a temporary directory \"/tmp/tmp.TivmPLUXFT\"\n```\n\n##### Make all directories at one time!\n```bash\nmkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat}\n# -p: make parent directory\n# this will create:\n# project/\n# project/bin/\n# project/demo/\n# project/demo/stat/\n# project/doc/\n# project/doc/html/\n# project/doc/info/\n# project/doc/pdf/\n# project/lib/\n# project/lib/ext/\n# project/src/\n#\n# project/\n# ├── bin\n# ├── demo\n# │   └── stat\n# ├── doc\n# │   ├── html\n# │   ├── info\n# │   └── pdf\n# ├── lib\n# │   └── ext\n# └── src\n```\n\n##### Run command only if another command returns zero exit status (well done)\n```bash\ncd tmp/ \u0026\u0026 tar xvf ~/a.tar\n```\n\n##### Run command only if another command returns non-zero exit status (not finish)\n```bash\ncd tmp/a/b/c ||mkdir -p tmp/a/b/c\n```\n\n##### Use backslash \"\\\" to break long command\n```bash\ncd tmp/a/b/c \\\n\u003e || \\\n\u003emkdir -p tmp/a/b/c\n```\n\n##### List file type of file (e.g. /tmp/)\n```bash\nfile /tmp/\n# tmp/: directory\n```\n\n##### Writing Bash script ('#!'' is called shebang )\n```bash\n#!/bin/bash\nfile=${1#*.}\n# remove string before a \".\"\n```\n\n##### Python simple HTTP Server\n```bash\npython -m SimpleHTTPServer\n# or when using python3:\npython3 -m http.server\n```\n\n##### Read user input\n```bash\nread input\necho $input\n```\n\n##### Array\n```bash\ndeclare -a array=()\n\n# or\ndeclare array=()\n\n# or associative array\ndeclare -A array=()\n```\n\n##### Send a directory\n```bash\nscp -r directoryname user@ip:/path/to/send\n```\n\n##### Fork bomb\n```bash\n# Don't try this at home!\n# It is a function that calls itself twice every call until you run out of system resources.\n# A '# ' is added in front for safety reason, remove it when seriously you are testing it.\n# :(){:|:\u0026};:\n```\n\n##### Trigger kernel crash\n```bash\n# Don't try this at home! \necho c \u003e /proc/sysrq-trigger\n```\n\n##### Use the last argument\n```bash\n!$\n```\n\n##### Check last exit code\n```bash\necho $?\n```\n\n##### Extract .xz\n```\nunxz filename.tar.xz\n# then\ntar -xf filename.tar\n```\n\n##### Unzip tar.bz2 file (e.g. file.tar.bz2)\n```bash\ntar xvfj file.tar.bz2\n```\n\n##### Unzip tar.xz file (e.g. file.tar.xz)\n```bash\nunxz file.tar.xz\ntar xopf file.tar\n```\n##### Extract to a path\n```bash\ntar xvf -C /path/to/directory filename.gz\n```\n\n##### Zip the content of a directory without including the directory itself\n```bash\n# First cd to the directory, they run:\nzip -r -D ../myzipfile .\n# you will see the myzipfile.zip in the parent directory (cd ..)\n```\n\n##### Output a y/n repeatedly until killed\n```bash\n# 'y':\nyes\n\n# or 'n':\nyes n\n\n# or 'anything':\nyes anything\n\n# pipe yes to other command\nyes | rm -r large_directory\n```\n\n##### Create large dummy file of certain size instantly (e.g. 10GiB)\n```bash\nfallocate -l 10G 10Gigfile\n```\n\n##### Create dummy file of certain size (e.g. 200mb)\n```bash\ndd if=/dev/zero of=/dev/shm/200m bs=1024k count=200\n# or\ndd if=/dev/zero of=/dev/shm/200m bs=1M count=200\n\n# Standard output:\n# 200+0 records in\n# 200+0 records out\n# 209715200 bytes (210 MB) copied, 0.0955679 s, 2.2 GB/s\n```\n\n##### Keep /repeatedly executing the same command (e.g Repeat 'wc -l filename' every 1 second)\n```bash\nwatch -n 1 wc -l filename\n```\n\n##### Use Bash Strict Mode\n```bash\n# These options can make your code safer but, depending on how your pipeline is written, it might be too aggressive \n# or it might not catch the errors that you are interested in\n\n# for reference see https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425\n#               and https://mywiki.wooledge.org/BashPitfalls#set_-euo_pipefail\n\nset -o errexit      # exit immediately if a pipeline returns a non-zero status\nset -o errtrace     # trap ERR from shell functions, command substitutions, and commands from subshell\nset -o nounset      # treat unset variables as an error\nset -o pipefail     # pipe will exit with last non-zero status, if applicable\nset -Eue -o pipefail  # shorthand for above (pipefail has no short option)\n```\n\n##### Print commands and their arguments when execute (e.g. echo `expr 10 + 20 `)\n```bash\nset -x; echo `expr 10 + 20 `\n# or\nset -o xtrace; echo `expr 10 + 20 `\n\n# to turn it off..\nset +x\n```\n\n##### Print some meaningful sentences to you (install fortune first)\n```bash\nfortune\n```\n\n##### Colorful (and useful) version of top (install htop first)\n```bash\nhtop\n```\n\n##### Press any key to continue\n```bash\nread -rsp $'Press any key to continue...\\n' -n1 key\n```\n\n##### Run sql-like command on files from terminal\n```bash\n# download:\n# https://github.com/harelba/q\n# example:\nq -d \",\" \"select c3,c4,c5 from /path/to/file.txt where c3='foo' and c5='boo'\"\n```\n\n##### Using Screen for multiple terminal sessions\n```bash\n# Create session and attach:\nscreen\n\n# Create a screen and name it 'test'\nscreen -S test\n\n# Create detached session foo:\nscreen -S foo -d -m\n\n# Detached session foo:\nscreen: ^a^d\n\n# List sessions:\nscreen -ls\n\n# Attach last session:\nscreen -r\n\n# Attach to session foo:\nscreen -r foo\n\n# Kill session foo:\nscreen -r foo -X quit\n\n\n# Scroll:\n# Hit your screen prefix combination (C-a / control+A), then hit Escape.\n# Move up/down with the arrow keys (↑ and ↓).  \n\n# Redirect output of an already running process in Screen:\n# (C-a / control+A), then hit 'H'  \n\n# Store screen output for Screen:\n# Ctrl+A, Shift+H  \n# You will then find a screen.log file under current directory.  \n```\n\n##### Using Tmux for multiple terminal sessions\n```bash\n# Create session and attach:\ntmux\n\n# Attach to session foo:\ntmux attach -t foo\n\n# Detached session foo:\n^bd\n\n# List sessions:\ntmux ls\n\n# Attach last session:\ntmux attach\n\n# Kill session foo:\ntmux kill-session -t foo\n\n# Create detached session foo:\ntmux new -s foo -d\n\n# Send command to all panes in tmux:\nCtrl-B\n:setw synchronize-panes\n\n# Some tmux pane control commands:\nCtrl-B\n#   Panes (splits), Press Ctrl+B, then input the following symbol:\n#   %  horizontal split\n#   \"  vertical split\n#   o  swap panes\n#   q  show pane numbers\n#   x  kill pane\n#   space - toggle between layouts\n\n#   Distribute Vertically (rows):\nselect-layout even-vertical\n#   or\nCtrl+b, Alt+2\n\n# Distribute horizontally (columns):\nselect-layout even-horizontal\n#   or\nCtrl+b, Alt+1\n\n# Scroll\nCtrl-b then \\[ then you can use your normal navigation keys to scroll around.\nPress q to quit scroll mode.\n```\n\n##### Pass password to ssh\n```bash\nsshpass -p mypassword ssh root@10.102.14.88 \"df -h\"\n```\n\n##### Wait for a pid (job) to complete\n```bash\nwait %1\n# or\nwait $PID\nwait ${!}\n#wait ${!} to wait till the last background process ($! is the PID of the last background process)\n```\n\n##### Convert pdf to txt\n```bash\nsudo apt-get install poppler-utils\npdftotext example.pdf example.txt\n```\n\n##### List only directory\n```bash\nls -d */\n```\n\n##### List one file per line.\n```bash\nls -1\n# or list all, do not ignore entries starting with .\nls -1a\n```\n\n##### Capture/record/save terminal output (capture everything you type and output)\n```bash\nscript output.txt\n# start using terminal\n# to logout the screen session (stop saving the contents), type exit.\n```\n\n##### List contents of directories in a tree-like format.\n```bash\ntree\n# go to the directory you want to list, and type tree (sudo apt-get install tree)\n# output:\n# home/\n# └── project\n#     ├── 1\n#     ├── 2\n#     ├── 3\n#     ├── 4\n#     └── 5\n#\n\n# set level directories deep (e.g. level 1)\ntree -L 1\n# home/\n# └── project\n```\n\n##### Set up virtualenv(sandbox) for python\n```bash\n# 1. install virtualenv.\nsudo apt-get install virtualenv\n# 2. Create a directory (name it .venv or whatever name your want) for your new shiny isolated environment.\nvirtualenv .venv\n# 3. source virtual bin\nsource .venv/bin/activate\n# 4. you can check check if you are now inside a sandbox.\ntype pip\n# 5. Now you can install your pip package, here requirements.txt is simply a txt file containing all the packages you want. (e.g tornado==4.5.3).\npip install -r requirements.txt\n# 6. Exit virtual environment\ndeactivate\n```\n\n\n\n\u003e More coming!!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonceupon%2Fbash-oneliner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonceupon%2Fbash-oneliner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonceupon%2Fbash-oneliner/lists"}