Bash

Basic

Save the output of a command to a variable :

a=$(echo xyz); echo $a

>>> xyz

Write the output to a file :

Get the last several characters of a string :

a=my.fits; echo "${a: -5}"

Get the characters of a string before several charactors :

a=my.fits; echo "${a: :-5}".sdf

For loop :

for i in *; do echo $i; done

Check if a file exist or not (more file test operators):

if [ -e ${file_name} ]; then echo ${file_name}; fi

Find out the number of files in a folder:

ls | wc -l
Note 1 : a folder is one file no matter how much files in it
Note 2 : ls -l | wc -l will give (the number of files + 1)

Generate a random number between 0 and N (not include), where N is an integer :

echo $(( RANDOM % N )) 

Extract substring :

b=${a:2:3}

Unpack (unzip, untar) files

Unpack a .tar file :

tar -xvf filename.tar
Note: .tar is the extension for the source files downloaded from the arXiv.org 

Unpack a .tar.gz file :

tar -zxvf file.tar.gz

Unpack a .gz file:

gunzip file.gz

Errors

syntax error: unexpected end of file