Learn how to check if a filesystem supports permissions in Linux, and discover an efficient way to identify incompatible filesystems. --- This video is based on the question https://stackoverflow.com/q/77468962/ asked by the user 'Maestro' ( https://stackoverflow.com/u/435733/ ) and on the answer https://stackoverflow.com/a/77472921/ provided by the user 'Léa Gris' ( https://stackoverflow.com/u/7939871/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions. Visit these links for original content and any more details, such as alternate solutions, comments, revision history etc. For example, the original title of the Question was: How to detect if a filesystem supports permissions? Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l... The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license. If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com. --- How to Detect Filesystem Permissions in Linux When it comes to working with files and folders in Linux, file permissions are a fundamental aspect of user rights management. However, not all filesystems support these permission features equally. Recently, I encountered a significant issue while extracting temporary files via a tar command into a user-specified folder on a USB stick formatted with the exfat filesystem. This encounter raised the question: How can we efficiently determine if a filesystem supports permissions without directly manipulating files? In this guide, we'll break down the problem, explore potential solutions, and introduce a robust Bash function to streamline the detection process. Understanding the Problem When you extract files to a directory in Linux, the filesystem plays a crucial role in managing how permissions are handled. If the target folder uses a filesystem like exfat, the extracted files will lose their permission information. This happens because exfat does not retain Unix-style file permissions, leading to security and accessibility issues. Common Filesystems and Their Permission Support Here's a brief overview of some popular filesystems and their permission management capabilities: Supported Filesystems: ext4 btrfs Unsupported Filesystems: exfat fat ntfs vfat fuse This list highlights the challenge of ensuring that files are managed securely across various formats. But how can we detect this support programmatically? The Solution A practical approach to checking if a filesystem supports permissions without creating temporary files is to verify if permissions can be changed on a test file in the directory. Below is a Bash function that achieves this. Implementing the Permission Check Function [[See Video to Reveal this Text or Code Snippet]] Explanation of the Function Function Definition: The function canChangeWritePermission() takes a directory path as an argument. Directory Check: It verifies whether the provided argument is a directory. Temporary File Creation: A temporary file is created in the specified directory. Permission Checks: It attempts to remove write permissions and checks if the file becomes unwritable. Then it re-adds the write permission and confirms that the file is writable again. Cleanup: After checking, it deletes the temporary file to ensure there are no remnants left in the directory. Return Codes: The function returns different codes based on whether permissions can be changed, if permissions cannot be changed, or if the check fails. Final Thoughts Using the provided function, you can easily detect whether a directory in Linux supports file permissions, making it a valuable tool in any scripter's toolkit. This method reduces the need for maintaining a comprehensive list of filesystems by dynamically testing the capabilities of any directory. Feel free to integrate this check into your scripts to ensure proper permission management across different filesystems. Also, if you encounter any new filesystem types, consider extending the function to improve its robustness. By understanding filesystem permissions, you can prevent potential security risks and ensure that your directories behave as expected. Happy scripting!