Skip to content

Instantly share code, notes, and snippets.

@jlant
Last active July 26, 2017 16:05
Show Gist options
  • Save jlant/ed852b1d94d77f455183 to your computer and use it in GitHub Desktop.
Save jlant/ed852b1d94d77f455183 to your computer and use it in GitHub Desktop.
Bash - unix and linux reference

Unix and Linux reference

References

https://github.com/jlevy/the-art-of-command-line
http://www.quora.com/What-are-the-most-useful-Swiss-army-knife-one-liners-on-Unix
http://www.quora.com/What-are-some-lesser-known-but-useful-Unix-commands
http://www.quora.com/Shell-Scripting/What-are-some-time-saving-tips-that-every-Linux-user-should-know

Update then Upgrade

$ sudo apt-get update
$ sudo apt-get upgrade

apt-get update - updates the list of available packages and their versions, but it does not install or upgrade any packages.
apt-get upgrade - installs newer versions of the packages you have. After updating the lists, the package manager knows
about available updates for the software you have installed.

Reference: https://askubuntu.com/questions/94102/what-is-the-difference-between-apt-get-update-and-upgrade

Install a .deb package

$ sudo dpkg -i path/to/*.deb
$ sudo apt-get install -f

The above commands installs a .deb package and then installs any dependencies that the .deb package needs.

Header template

#!/bin/bash
 
# Name:
#   <script-name>.sh -- short description
#
# Usage:
#   <script-name>.sh [options] params
#
# Parameters:
#   FILETYPE    [[-d | --daily ] | [-u | --unit]]  
#   FILES       list of data file(s) to process
#
# Options:
#   numpeaks    number of peaks to find 
#
# Description:
#   The <script-name> script ... long description
#
# Example:
#   <script-name>.sh 

Stopwatch - hit enter to stop

$ time read

.bashrc for Linux

export PATH=/home/jeremiah/anaconda/bin:$PATH
export PATH=/opt/sublime_text/:$PATH

# colored prompt - solarized grayish
#PS1="${debian_chroot:+($debian_chroot)}\n\[\033[01;32m\]\u at \h in\[\033[01;34m\] \w \n\$ \[\033[00m\]"

# colored prompt - [green]\u \h in [blue]\w [grayish]<rest of prompt> 
PS1="${debian_chroot:+($debian_chroot)}\n\[\033[32m\]\u at \h in\[\033[34m\] \w \n\[\033[00m\]$ \[\033[00m\]"

# colored prompt - [green]\u [grayish]at [green]\h [grayish]in [blue]\w [grayish]<rest of prompt> 
#PS1="${debian_chroot:+($debian_chroot)}\n\[\033[32m\]\u \[\033[00m\]at \[\033[32m\]\h \[\033[00m\]in\[\033[34m\] \w \n\[\033[00m\]$ \[\033[00m\]"

.bash_profile for Mac

# added by Anaconda 2.0.1 installer
export PATH="/Users/jeremiahlant/anaconda/bin:$PATH"

# adding Linux colors to shell
export CLICOLOR=1
export LSCOLORS="ExGxBxDxCxEgEdxbxgxcxd"

# adding personal bin directory to path
export PATH="$PATH:/Users/jeremiahlant/bin"

# adding new prompt - jeremiahlant at Ashleys-Air in ~
PS1="\u at \h in \w \n$ "

.bashrc on Windows with GitBash

alias sublime="/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe"
alias tree="cmd //c tree"
export PATH="$PATH:/c/MinGW/bin"
export PATH="$PATH:/c/MinGW/msys/1.0/bin"
export PS1="\[\033]0;$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]\n\[\033[32m\]\u at \h in \[\033[33m\]\w$(__git_ps1)\[\033[0m\]\n$ "

tar - tape archive

tar (Tape Archive) - used to archive files; puts multiple files into one tar file
gzip - used to compress files to smaller size; one type of compression
bzip2 - used to compress files to smaller size; one type of compression

Arguments

x - extract
v - verbose 
f - read from a file
z - filter the archive through gzip
j - filter the archive through bzip2

Uncompress tar.gz

tar zxvf file.tar.gz

Uncompress tar.gz and put into a different directory

tar zxvf file.tar.gz -C /path/to/directory

Uncompress first and untar second

gunzip file.tar.gz
tar xvf file.tar

Uncompress tar.bz2

tar xvjf file.tar.bz2

Clean / remove old kernel versions to clean up the boot menu

http://askubuntu.com/questions/2793/how-do-i-remove-old-kernel-versions-to-clean-up-the-boot-menu

Open terminal and check your current kernel:

uname -r 

DO NOT REMOVE THIS KERNEL!

Next, type the command below to view/list all installed kernels on your system.

dpkg --list | grep linux-image 

Find all the kernels that lower than your current kernel. When you know which kernel to remove, continue below to remove it. Run the commands below to remove the kernel you selected.

sudo apt-get purge linux-image-x.x.x.x-generic 

Finally, run the commands below to update grub2

sudo update-grub2 

Reboot your system.

Debug Fortran code

Get fortran compiler and debugger

sudo apt-get install gfortran
sudo apt-get install gdb

Use the -g flag when compiling code

gfortran -g <your-main-program>.f95 -o debug-version
gdb debug-version

Steps

  1. break main # run code until the first executable point
  2. run # start the execution of the code
  3. step # run line by line, steps into subroutines
  4. print <variable> # show the variable value
  5. where # show the line that the gdb is debugging
  6. quit

Other commands step or s - steps into subroutines
next or n - execute next line, will execute entire function/subroutine, steps over functions/subroutines
list or l - list source code around the line you are on while debugging
break <function-name> - set a breakpoint at the beginning of the function
break <filename>.f95:<line-number> - set a breakpoint at a specified line number and specified file
break <line-number> - set a breakpoint at the specified line number of the current file
continue or c - continue until next breakpoint
print <variable-name> = <new-value> - assigns a new value to the variable
info locals - prints information regarding all inscope local variables
info b - prints information regarding all breakpoints
disable - disables all breakpoints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment