#!/usr/bin/env bash

SEP="########################################################################"

# Listing files
echo "you can list all regular files:"
ls

printf "\n%s\n" "$SEP"

echo "add -a to see hidden files and -l to format output as a list:"
ls -al

printf "\n%s\n" "$SEP"

echo "and keep adding flags till you're happy. Run 'man ls' to read more."
ls -altrh

printf "\n%s\n" "$SEP"

# List files, trimming off the first line (Total count) and return lines 2-5
echo "Current dir is $(pwd)"
echo "First four items:"
ls -al . | head -n5 | tail -n4

printf "\n%s\n" "$SEP"

# Change directory using cd
echo "Changing dir"
cd ../../
echo "Current dir is $(pwd)"
echo "Last 5 modified items:"
ls -altrh | tail -n5

printf "\n%s\n" "$SEP"

# Return to last dir
echo "Returning to last dir"
cd - > /dev/null || exit
echo "Current dir is $(pwd)"

printf "\n%s\n" "$SEP"

# Change directory using pushd/popd
pushd ../../ > /dev/null || exit
echo "Current dir is $(pwd)"
pushd ../ > /dev/null || exit
echo "Current dir is $(pwd)"
popd > /dev/null
echo "Current dir is $(pwd)"
popd > /dev/null
echo "Current dir is $(pwd)"

printf "\n%s\n" "$SEP"

# Find files by extension
echo "Finding all txt files:"
find . -name "*.txt"
