Skip to content

Instantly share code, notes, and snippets.

@abelcallejo
Last active August 26, 2020 10:27
Show Gist options
  • Save abelcallejo/6f4781317497d8ba4284cb7f32476514 to your computer and use it in GitHub Desktop.
Save abelcallejo/6f4781317497d8ba4284cb7f32476514 to your computer and use it in GitHub Desktop.
Bash file management

Bash file management

Listing all the files

find . -name "*"

or more advanced

find . -print | grep -E -- 'jpg|png'

Foreach

for candidate in `find . -print | grep -E -- 'jpg|png'`; do
  echo "the next file is $candidate"
done

Getting the file size of a file

size=$(wc -c < file.txt)

This is in bytes.

Getting the content-type of a file

type=$(file -b --mime-type file.txt)

Notes

image/jpeg
image/png

Bash comparisons

Numeric

if (( $size >= 614400 )); then
  echo 'hello world'
fi

String

if [ "$a" = "$b" ]; then
  echo 'hello world'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment