futimes - Linux
Overview
futimes is a powerful command used to update the access and modification times of a file or symbolic link. It allows fine-grained control over the timestamps associated with files, enabling users to set specific dates and times to accurately record file usage or modify metadata.
Syntax
futimes <file> <atime> <mtime>
Parameters:
<file>
: The path to the file or symbolic link whose timestamps should be modified.<atime>
: A timestamp in seconds since the epoch, specifying the new access time.<mtime>
: A timestamp in seconds since the epoch, specifying the new modification time.
Options/Flags
futimes does not support any options or flags.
Examples
Example 1: Set the access and modification times to the current time:
futimes myfile $(date +%s) $(date +%s)
Example 2: Set the access time to January 1, 2023, and the modification time to July 4, 2022:
futimes myfile 1640995200 1657041600
Example 3: Modify the timestamps of multiple files simultaneously:
find mydir -type f -exec futimes {} $(date +%s) {} \;
Common Issues
- Permission Denied: Ensure you have write permissions on the file or directory.
- Invalid Timestamps: Verify that the provided timestamps are valid and within the range of supported values (e.g., not negative).
- File Not Found: Check that the specified file or symbolic link exists.
Integration
futimes can be combined with other commands for advanced operations:
- touch -r: Update the timestamps of a file based on an existing file’s timestamps.
- stat: Display the file’s current timestamps for comparison.
- find: Perform bulk operations on multiple files using futimes in a loop.
Related Commands
- touch
- date
- stat
For more information, refer to the official Linux man pages or online documentation.