5 Useful Bash Aliases And Functions
Aug 13, 2017
5 Useful Bash Aliases and Functions For Lazy Bioinformaticians
Continuing on our theme of making bioinformatics more sexy with buzzfeed-esque blog post titles, here are 5 useful bash aliases and functions so you can remember fewer non-intuitive options, type fewer keys for the same output, and overall be more productive and efficient in your bioinformatics analysis :D ie. have more time to look at dank memes.
I’ll try to keep to aliases and functions that may be more niche to bioinformatics and ones I haven’t seen frequently included in other “useful bash aliases and functions” lists such as alias ..='cd ..'
. There are many more general lists of useful bash aliases and functions such as this one by Justin Ellingwood and this one by Gulshan Singh.
1. Tar and compress (and untar) all those fastq, csv, vcf, and other files
I can never remember the flags…so let’s just make an easy to understand function called targz to tar.gz a file or folder and likewise for extracting. Note this is a bash function so it should be put into your .profile
or another dedicated .bash_functions
file to be sourced from your .bashrc
.
Functions:
# create .tar.gz
targz() { tar -zcvf $1.tar.gz $1; rm -r $1; }
# extra .tar.gz
untargz() { tar -zxvf $1; rm -r $1; }
Usage:
> targz test
a test
a test/test.txt
untargz test.tar.gz
x test/
x test/test.txt
2. Count number of files in a directory
This is very useful for counting the number of fastq or other dataset files you have.
Function:
numfiles() {
N="$(ls $1 | wc -l)";
echo "$N files in $1";
}
Usage:
> numfiles test
10 files in test
3. Search through your command history
If I’ve typed out the same command more than once, then I’ve typed it out too many times.
Note, aliases should be added to your .bash_aliases
file.
Alias:
alias hs='history | grep'
Usage:
> hs test
1883 emacs test.R
1900 less test.R
2003 history | grep test
2008 hs test
(now you can use !2008
to repeat command #2008)
4. Navigate more easily
This is a simply one, but I use it very frequently. If you work on a shared cluster, your group will likely have a group directory at some obscure path. You will essentially be cd-ing to it all the time. So why not just make a fast alias.
Alias:
# navigation
alias 2pklab='cd /groups/pklab/jfan/'
5. Make a folder and go into it
Another simple one but very helpful. If I make a directory, I often want to cd
into it. So why not just make one command for that?
Function:
mkcd() { mkdir -p $1; cd $1 }
And there you have it. Here is my cat tax for posting a less-than-professional post: (my dog Foxxy)
Want to join in on the fun but don’t know what to blog about? Get inspired with my random buzzfeed-inspired title generator (bioinformatics grad student edition). With inspirational creations like “The 12 Most Beloved Nature Papers Of Your Childhood” and “40 Figures That Will Make Your Skin Crawl”, your next big hit is waiting to be generated.
- Older
- Newer
RECENT POSTS
- Impact of normalizing spatial transcriptomics data in dimensionality reduction and clustering versus deconvolution analysis with STdeconvolve on 04 May 2023
- Aligning Spatial Transcriptomics Data With Stalign on 16 April 2023
- 3D animation of the brain in R on 08 November 2022
- Ethical Challenges in Biomedical Engineering - Data Collection, Analysis, and Interpretation on 15 October 2022
- I use R to (try to) figure out the cost of medical procedures by analyzing insurance data from the Transparency in Coverage Final Rule on 12 September 2022
- Annotating STdeconvolve Cell-Types with ASCT+B Tables on 30 August 2022
- Deconvolution vs Clustering Analysis: An exploration via simulation on 11 July 2022
- Coloring SVGs in R on 17 June 2022
- Deconvolution vs Clustering Analysis for Multi-cellular Pixel-Resolution Spatially Resolved Transcriptomics Data on 03 May 2022
- Exploring UMAP parameters in visualizing single-cell spatially resolved transcriptomics data on 19 January 2022