Skip to content

Instantly share code, notes, and snippets.

@TAM360
Last active October 9, 2021 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TAM360/ace095e14cca5aee812ebba4bbae493d to your computer and use it in GitHub Desktop.
Save TAM360/ace095e14cca5aee812ebba4bbae493d to your computer and use it in GitHub Desktop.
list of helpful bash commands
Legend
| symbol | used for |
|=============|=====================|
| - | command description |
| # | comments |
| $ | actual command |
| [] | command's output |
| <> | command's arguments |
|========================================================================================================================|
- display git branch inside terminal by configuring .bashrc file
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ [ \1]/'
}
export PS1="\[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] λ "
- run previously executed command using double bangs (!!)
$ date [Wed Nov 27 21:11:03 PKT 2019]
$ !! [Wed Nov 27 21:11:03 PKT 2019]
- go back to root directory using tilda (~)
$ cd ~ [/home/tam101]
- go back to previous directory using hyphen (-)
$ cd -
- check differences between contents of 2 files using diff side by side.
Assume file text_1 containing "hello world" as text and text_2
contatining "hello" only. use --color flag to highlight the text.
$ diff text_1 text_2 --side-by-side [hello world | hello]
- use double dots (..) to go back to immediate parent directory
$ cd ../
- display calender on ternimal using cal
$ cal <year>
- create multiple files using {..} operator
$ touch text_{1..3} # creates files with names text_1, text_2 & text_3
- check the port # which is currently being used in 2 ways
1. using netstat
# netstart -pant | grep ":<port #>"
$ sudo netstat -pant | grep ":8080" [tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 28967/node]
2. using lsof
# lsof -i | grep <command/process name>
$ lsof -i | grep firefox [firefox 27535 in01-nbk-567 346u IPv4 545324 0t0 TCP in01nbk567-Latitude-5591:33784->52.114.77.38:https (ESTABLISHED)]
- kill a process which is binded to a particular port number
# lsof -i:<port number>
$ lsof -i:8080
- adjusting brightness of external monitor using xrandr
# xrandr --output <port name)> --brightness <0.0 - 1.0>
$ xrandr --output HDMI1 --brightness 0.6
- check path of specific python's installation
$ which python3 [/usr/bin/python3]
- creating python virtual-environment with specific python verion
# virtualenv --python=<path/to/python/installation/folder> <path/to/new/virtualenv/>
$ virtualenv --python=/usr/bin/python3.6 code_repository
- using new SSH key pair instead of HTTP for Github repository authentication
1. create new SSH private-public key pair. replace dummy email id with the one used in Github account
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
2. next, press Enter for default location (/home/you/.ssh/id_rsa) for saving the keys
3. next, enter passphrase for the SSH key (empty for no passphrase). re-confirm it by enterting it again.
4. now add the private key to SSH agent
$ eval "$(ssh-agent -s)" # starts the SSH agent
$ ssh-add ~/.ssh/id_rsa
5. finally, add the public SSH key to the Github account
a. install xclip utility 1st in bash
$ sudo apt install xclip
b. copy the contents of key using xclip
$ xclip -sel clip < ~/.ssh/id_rsa.pub
c. got to github account settings and click on "SSH and GPG key" sidebar
d. click on "new SSH key", give key a meaningful name and paste the contents in the box.
- setting up postgres in ubuntu/linux-mint
1. update the repository list
$ sudo apt-get update
2. install postgres & postgres-contrib
$ sudo apt install postgresql postgresql-contrib
- unblock bluetooth device using rfkill
$ rfkill list
# rfkill unblock <ID>
$ rfkill unblock 1
- custom aliases
alias install="sudo apt-get install "
alias update="sudo apt-get update "
alias upgrade="sudo apt-get upgrade "
alias automremove="sudo apt-get autoremove "
alias purge="sudo apt-get purge"
alias snit="sudo snap install "
alias snrp="sudo snap remove "
alias kt="microk8s kubectl "
alias sbr1="xrandr --output HDMI-1 --brightness "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment