If I am reading a file stored on an NTFS filesystem, and I try to move/rename that file while it is still being read, I am prevented from doing so. If I try this on a UNIX filesystem such as EXT3, it succeeds, and the process doing the reading is unaffected. I can even rm the file and reading processes are unaffected. How does this work? Could somebody explain to me why this behaviour is supported under UNIX filesystems but not NTFS? I have a vague feeling it has to do with hard links and inodes, but I would appreciate a good explanation.
How do the UNIX commands mv and rm work with open files?
8.4k Views Asked by jl6 At
2
There are 2 best solutions below
0
Erik
On
On unix, a filename is simply a link to the actual file(inode). Opening a file also creates a (temporary) link to the actual file. When all links to a file have disappeared (rm and close()) then the file is removed.
On NTFS, logically the filename is the file. There's no indirection layer from the filename to the file metainfo, they're the same object. If you open it, it's in use and can't be removed, just as the actual file(inode) on unix can't be removed while it's in use.
Unix: Filename ➜ FileInfo ➜ File Data
NTFS: FileName + FileInfo ➜ File Data
Related Questions in UNIX
- Reading & Writing to the same file from terminal
- `df` command not capturing entire output in perl
- Why is it that when I pass certain directory names to `ls`, sometimes it does not list their contents?
- Detect Mouse Clicks; Terminate Program on Scroll Wheel Movement
- grep expression behaving weird (unix/mac) while reading a conf file
- Unix sub path creation and copy files
- Ignoring folders in The Silver Searcher `ag`
- struct nameidata-Linux Kernel Module
- telegraf service not able to retrieve data using the journalctl commands
- Order of options in Unix sed for editing files in-place
- Trying to echo line variable along with another variable inside a while read loop
- failed to handshake with xxx: authentication error?
- UDP socket client not able to receive data
- Invalid SCA token in unix
- How can I keep randomized UNIX timestamp in specific hour range in SQL?
Related Questions in FILESYSTEMS
- Where exactly is the first data sector on a FAT file system?
- `df` command not capturing entire output in perl
- Is it possible to mount a logical volume without wiping the data?
- Speed up search of remote directories
- How to change the directory file system without losing files?
- Flutter SDK: Files Deleted Automatically (e.g., dart.exe), Errors in Android Studio
- How to store metadata for a UTF-8 text file cross-platform?
- fsck error on boot: dev/mapper/ubuntu--vg-ubuntu--lv: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY
- rouble with mounting Python code to FUSE: No response and prolonged processing ---
- mkfs.erofs erofs: failed to lookup selabel
- How to deny user access MacFuse file system by the really path
- Is it faster to read a file on an NVMe using threads?
- list folders containing mp3 files using the Capacitor Filesystem
- How to use xdg-open in bwrap environment to open dir in the unsandboxed filesystem
- How to provide content of (locally) encrypted files to the iOS and macOS system
Related Questions in NTFS
- How to obfuscate windows long filenames without exceeding max length
- How to integrate the SMB Core Protocol into your own application?
- How to pre-allocate file on Windows (NTFS) without writing the whole file
- On Windows, can you create a file without any name?
- "$Bitmap size is smaller than expected" when shrinking a partition image with ntfsresize
- What is the binary format of NTFS timestamp?
- How to open $MFT in Python?
- Netatalk NTFS-3G TRANSFER TO RASPBERRY PI HDD - NOT ENOUGH DISK SPACE
- Folder Last Modified Date Discrepancy in Windows Explorer due to Subfolder Changes
- My powershell script to assign permissions to network share has to be run multiple times?
- How do you set the NTFS permissions for an append-only log, and append to it in VB6?
- Fastest way to delete folder that has complex structure
- NTFS change journal USN v3 close record added every 30 min
- NTFS Change Journal - range tracking chunk size for big files
- Win32 filesystem "FILE_SUPPORTS_POSIX_UNLINK_RENAME" - what does it do?
Related Questions in MV
- mv: cannot move No such file or directory
- Unresolvable merge conflicts following moving files
- Linux: Unzip archive and rename contents to archive name followed by an incrementing number
- UWSGI Binary is not in '/usr/local/bin'
- bash: excluding found files located in the subdirs
- How to save an ls of my desktop onto a folder on my desktop as a txt file? In one line/step
- Access denied for mv command in Git
- mv command Increment a numeric char at the start of folders names that start with >1
- Renaming multiple files in bash by removing prefix and suffix containing special characters %?=
- Linux command to move a directory into another directory
- Move All Files to Another Folder Except a Specific One in Bash
- How to capture and modify digits recognized by regex in bash
- Renaming files in a directory and its subdirectories
- ls and mv problem. File could be listed but when trying to move system says no such file
- rename files in sub directories
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Unix filesystems use reference counting and a two-layer architecture for finding files.
The filename refers to something called an inode, for information node or index node. The inode stores (a pointer to) the file contents as well as some metadata, such as the file's type (ordinary, directory, device, etc.) and who owns it.
Multiple filenames can refer to the same inode; they are then called hard links. In addition, a file descriptor (fd) refers to an inode. An fd is the type of object a process gets when it opens a file.
A file in a Unix filesystem only disappears when the last reference to it is gone, so when there are no more names (hard links) or fd's referencing it. So,
rmdoes not actually remove a file; it removes a reference to a file.This filesystem setup may seem confusing and it sometimes poses problems (esp. with NFS), but it has the benefit that locking is not necessary for a lot of applications. Many Unix programs also use the situation to their advantage by opening a temporary file and deleting it immediately after. As soon as they terminate, even if they crash, the temporary file is gone.