Overview
touch-a changes the access time of a file to the current time or sets it to a specified time. It does not touch the modification time of the file, and if the file does not exist, it creates a new empty file.
Key Features
- Updates only the access time of the file
- Creates an empty file if it does not exist
- Does not change the modification time
Key Options
The touch-a command is specialized for updating file access times and allows for fine-grained control of its behavior using the following additional options:
Behavior Control
Generated command:
Try combining the commands.
Description:
`touch-a` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Explore various scenarios for managing file access times using the touch-a command.
Update File Access Time
touch-a myfile.txt
Updates the access time of the specified file to the current time. If the file does not exist, it will be created.
Update Access Time Without Creating File
touch-a -c existing_file.txt
If the file does not exist, it will not be created; only the access time of the existing file will be updated.
Reference Access Time of Another File
touch-a -r reference.txt target.txt
Applies the access time of reference.txt to target.txt.
Set Access Time to a Specific Time
touch-a -t 2312312359.59 myfile.txt
Sets the access time of myfile.txt to December 31, 2023, 23:59:59.
Installation
touch-a is not included by default in standard Linux distributions. You can achieve the same functionality using the `-a` option of the `touch` command. If you wish to use the command named `touch-a`, you can set up a shell alias or create a simple shell script.
Setting Alias in Bash/Zsh
echo 'alias touch-a="touch -a"' >> ~/.bashrc
source ~/.bashrc
Add the following line to your `.bashrc` or `.zshrc` file to create the `touch-a` alias.
Creating a Simple Shell Script
echo '#!/bin/bash\ntouch -a "$@"' > /usr/local/bin/touch-a
chmod +x /usr/local/bin/touch-a
You can create an executable script named `touch-a` for use.
Tips & Notes
Useful tips and points to note when using the touch-a command.
Relationship with touch -a
touch-a is essentially an alias or wrapper script for the `touch -a` command. The `touch` command can be used with a combination of `-a` (access time) and `-m` (modification time) options. touch-a is considered to have the `-a` option applied by default.
- `touch -a` performs the same function as `touch-a`.
- `touch -m` only changes the modification time.
- `touch` (without options) changes both access and modification times.
Checking File Times
File access time (Access), modification time (Modify), and change time (Change) can be checked using the `stat` command.
- Check detailed time information with the `stat filename.txt` command.
- You can check the access time with `ls -lu filename.txt` and the modification time with `ls -l filename.txt`.