Bash: How to get the directory of the current file
27 October 2023 (Updated 10 December 2025)
current_dir=$(dirname "$0")
echo '--------------------------------------------------'
echo "The directory of the current file is $current_dir"
echo '-------------------------------------------------------'
Tagged:
Bash recipes
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment