Shell Script

File exists

With the if statement

FILE=/etc/resolv.conf
if [ -f "$FILE" ]; then
    echo "$FILE exists."
else 
    echo "$FILE does not exist."
fi

With the "&&" operator

[ -f /etc/resolv.conf ] && echo "File exists!"

Folder exists

if [ "$(ls -A /tmp)" ]; then
  echo "Exists and is not Empty"
fi

# Or using `-d`

if ! [ -d "/var/www/html" ] || ! [ -d "/var/www/x-html" ]; then
    echo "Folder not found here - ;("
fi

Or not exists

Find differences between foldes

Show ports in use

Create alias

Insert the line below to your ~/.zsh.rc or ~/.profile

Cheatsheet of multiple commands

Example

Read every line from a file

In the example below read every line from a file and do something.

Log

Basic view of records

To see the logs that the journald daemon has collected, use the journalctl command

Last updated

Was this helpful?