Skip to content

Instantly share code, notes, and snippets.

@zoka123
Created August 4, 2016 13:09
Show Gist options
  • Save zoka123/f2b03f19924258d28441fe2d88750145 to your computer and use it in GitHub Desktop.
Save zoka123/f2b03f19924258d28441fe2d88750145 to your computer and use it in GitHub Desktop.
Bash test if directory is writable
# By path
if [ -w "/path/to/dir" ]; then echo "WRITABLE"; else echo "NOT WRITABLE"; fi
# Current dir
if [ -w `pwd` ]; then echo "WRITABLE"; else echo "NOT WRITABLE"; fi
@nomaed
Copy link

nomaed commented Jul 20, 2022

For a quick check, this syntax is shorter:

[ -w "/path/to/dir" ] && echo "WRITEABLE" || echo "NOT WRITEABLE

@wjandrea
Copy link

wjandrea commented Aug 8, 2025

@nomaed yeah but it's not as strict. E.g. if echo "WRITEABLE" fails, you'll get NOT WRITEABLE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment