Otago Study Group SYSKA

The OtagoStudyGroup Stuff You Should Know About blog

bash translate

tr or “translate or delete characters” is a super useful program on the command line. My most common usage is to convert delimiters in files, such as tab separated to comma separated: tr "\t" "," < tab_separated_file.tsv or to work out how many columns I have by taking the first line of a file and converting the delimiters to new lines and then counting the number of lines: echo -e "col1\tcol2\tcol3" > file. Read more →

Case-insensitive Completion in Bash

Have you ever been annoyed by having to re-type a file you are looking for, just because the filename contains capital letter(s)? Tab-completion can get you closer to the correct filename without knowing what the actual filename is, but it’s not quite smart enough to account for uppercase and lowercase letters (i.e. it’s case-sensitive). For example, if you type coolfile and hit tab to complete the filename coolFile.txt, tab-completion won’t work. Read more →

Using less more effectively

If you’ve ever used bash terminal before, you would have come across the less command at some point. For anyone who is not familiar with less, less is a “paging” command that allows you to view file(s) of interest on your terminal. It is usually the default “pager” (program used to view a document) for a terminal environment that comes with your Unix/Linux operating system. Now, you might ask “why bother using less when you can open it up on a text editor, or even better, point and click on the file”? Read more →

Bash history

One of the most useful additions to my .bashrc file that I have found is the addition of this command to save all the commands that I run into a log file. export PROMPT_COMMAND='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log; fi' This is super useful because it saves a new file for each day of all of the timestamped commands that I have run and the directory I was in when I ran them. Read more →