Useful bash commands

Life is short but jobs are infinite.

This is a summary of some useful commands. Be careful about “space” usage in command line.


Example: Show current time:

date +"%T"

Example: count the number of files in certain folder:

# go to certain folder
cd /folder_of_interest/
# count the number of files
ls | wc -l

Example: Bash arithmetic expansion: The builtin shell expansion allows you to use the parentheses ((…)) to do math calculations.

# initiate a value for x and output it with 'echo'
x=3 && echo $x
# calculation using ((...))
echo $((x+2))