Linux Comm At
π
2026-06-22 | π Linux
Linux at Command | Rookie Tutorial
[ Linux Command Manual](#)
* * *
`at` is a powerful scheduling tool in Linux systems that allows users to execute one-time tasks at a specified time, unlike `cron` which handles periodic execution.
Compared to `cron`, `at` is more suitable for the following scenarios:
* Tasks that only need to run once
* Tasks scheduled to run at a specific future time
* Temporary system maintenance operations
* * *
## Installation and Basic Usage
### Check Installation
Most Linux distributions come with `at` pre-installed. Check using the following command:
which at
If not installed, use your package manager:
## Example
# Debian/Ubuntu
sudo apt-get install at
# CentOS/RHEL
sudo yum install at
### Start the at Service
After installation, start the `atd` daemon:
## Example
sudo systemctl start atd
sudo systemctl enable atd # Enable auto-start on boot
* * *
## Command Syntax and Parameters
### Basic Syntax
at time
### Common Options
| Option | Description |
| --- | --- |
| `-f file` | Read commands from a specified file instead of standard input |
| `-m` | Send mail to the user after the job completes |
| `-l` | List pending jobs (same as `atq`) |
| `-d job ID` | Delete a specified job (same as `atrm`) |
| `-v` | Show the time when the job will be executed |
### Time Formats
`at` supports various time formats:
1. **Absolute Time**
* `HH:MM` (e.g., 14:30)
* `YYYY-MM-DD` (e.g., 2023-12-25)
* Combined format `HH:MM YYYY-MM-DD`
2. **Relative Time**
* `now + quantity unit` (e.g., `now + 2 hours`)
* Units can be: minutes, hours, days, weeks
3. **Special Keywords**
* `noon` (12:00 PM)
* `midnight` (12:00 AM)
* `teatime` (4:00 PM)
* `tomorrow` (Same time tomorrow)
* * *
## Usage Examples
### Example 1: Basic Usage
## Example
$ at 15:30
warning: commands will be executed using /bin/sh
at>echo"Hello at command"> ~/at_test.txt
at># Press Ctrl+D to end input
job 1 at Tue Jul 18 15:30:00 2023
### Example 2: Reading Commands from a File
Create a script file `myscript.sh`:
## Example
#!/bin/bash
echo"This is a test">>/tmp/at_log
date>>/tmp/at_log
Then use:
at -f myscript.sh now + 5 minutes
### Example 3: Viewing and Deleting Jobs
## Example
$ atq # or at -l
1 Tue Jul 18 15:30:00 2023 a username
$ atrm 1# or at -d 1
* * *
## Advanced Usage
### Setting Environment Variables
## Example
$ at 16:00
at>export MY_VAR="test"
at>echo$MY_VAR> ~/env_test.txt
at>
### Executing Complex Commands
## Example
$ at 17:00 today
at>cd/var/log &&grep"error" syslog > ~/error_log.txt
at>
### Using Here Document
## Example
at 18:00 << 'EOF'
#!/bin/bash
echo "Starting backup..."
tar -czf ~/backup-$(date +%F).tar.gz ~/Documents
EOF
* * *
## Important Notes
1. **Permission Control**
* Access is controlled by `/etc/at.allow` and `/etc/at.deny` files
* If `at.allow` exists, only listed users can use `at`
* If `at.allow` does not exist, check `at.deny`; listed users are denied access
2. **Output Handling**
* By default, command output is mailed to the user
* Use the `-m` option to force sending mail, even if there is no output
3. **Environment Differences**
* The execution environment for `at` may differ from an interactive shell
* Important environment variables should be explicitly set within the commands
4. **Error Handling**
* Check if the `atd` service is running: `systemctl status atd`
* Check system logs for error messages: `journalctl -u atd`
* * *
## Practice Exercises
1. Create a job to append the current date and time to `~/time_log.txt` in 5 minutes
2. Write a script to back up the `/etc` directory and schedule it with `at` to run at 2 AM tomorrow
3. List all current pending `at` jobs, then delete one of them
* * *
## Summary
The `at` command is a powerful tool for managing one-time scheduled tasks in Linux systems. Through this article, you should have learned:
* The basic concepts and installation methods for `at`
* Various ways to specify time formats
* Operations for creating, viewing, and deleting jobs
* Advanced usage and important considerations
For tasks requiring periodic execution, consider using `cron`, but for one-time tasks, `at` is undoubtedly the best choice.
* * Linux Command Manual](#)