Bash

Bash Commands

Basic Navigation

List command (ls)

Show the contents of the current directory.

ls

Flags

  • -l : long format
  • -a : show hidden files
  • -t : sort by time modified, recently modified first
  • -R : recursively show subdirectories

Usage

ls -al

Specific

  • atom . : Open current directory in Atom
  • code . : Open current directory in Visual Studio Code
  • code <directory> : Open directory in Visual Studio Code
  • open <directory> : Open directory in Finder
  • node (.*).js : Run javascript file in bash

https://tecadmin.net/tutorial/bash-scripting/bash-command-arguments/

  • tail -f <log-file>

Grep

cat file.txt | grep "title"

Bash Snippets

For loop

#!/bin/sh

for x in dog elephant fish; do
	echo $x
done

If-Else statement

#!/bin/sh

if [ $1 = hotdog ]; then
	echo "You typed hotdog"
else
	echo You did NOT type Hotdog
	echo it was '"'$1'"'
fi

Bash commands

#!/bin/sh
#
# This program is going to be awesome

echo "Progam is starting..."
ls -la

Bash Tutorial

Cheatsheet

Full Handbook