The most basic operations that programs can perform on a file are: • Create a new file • Change the
access permissions and
attributes of a file •
Open a file, which makes the file contents available to the program •
Read data from a file •
Write data to a file •
Delete a file •
Close a file, terminating the association between it and the program •
Truncate a file, shortening it to a specified size within the file system without rewriting any content • Allocate space to a file without writing any content. Not supported by some file systems. Files on a computer can be created, moved, modified, grown, shrunk (
truncated), and deleted. In most cases, computer programs that are executed on the computer handle these operations, but the user of a computer can also manipulate files if necessary. For instance,
Microsoft Word files are normally created and modified by the Microsoft Word program in response to user commands, but the user can also move,
rename, or
delete these files directly by using a
file manager program such as
Windows Explorer (on Windows computers) or by
command lines (CLI). In
Unix-like systems,
user space programs do not operate directly, at a low level, on a file. Only the
kernel deals with files, and it handles all user-space interaction with files in a manner that is transparent to the user-space programs. The
operating system provides a level of
abstraction, which means that interaction with a file from user-space is simply through its filename (instead of its
inode). For example,
rm filename will not delete the file itself, but only a
link to the file. There can be many links to a file, but when they are all removed, the
kernel considers that file's memory space free to be reallocated. This
free space is commonly considered a security risk (due to the existence of
file recovery software). Any secure-deletion program uses kernel-space (system) functions to wipe the file's data. File moves within a file system complete almost immediately because the data content does not need to be rewritten. Only the paths need to be changed.
Moving methods When moving files between devices or partitions, some file managing software deletes each selected file from the source directory
individually after being transferred, while other software deletes
all files at once only after every file has been transferred. For example, the
mv command uses the former method when moving files individually with
wildcards (example: mv -n sourcePath/* targetPath), but uses the latter method when moving entire directories (example: mv -n sourcePath targetPath). Microsoft
Windows Explorer also varies its approach: it uses the former method for
mass storage file moves, but uses the latter method when transferring files via
Media Transfer Protocol, as described in . The former method (individual deletion from source) has the benefit that space is released from the source device or partition imminently after the transfer has begun, meaning after the first file is finished. With the latter method, space is only freed after the transfer of the entire selection has finished. If an incomplete file transfer with the latter method is aborted unexpectedly, perhaps due to an unexpected power-off, system halt or disconnection of a device, no space will have been freed up on the source device or partition. The user would need to merge the remaining files from the source, including the incompletely written (truncated) last file. With the individual deletion method, the file moving software also does not need to cumulatively keep track of all files finished transferring for the case that a user manually aborts the file transfer. A file manager using the latter (afterwards deletion) method will have to only delete the files from the source directory that have already finished transferring. ==Identifying and organizing==