How to Schedule a One-Time Script with at in Linux (XK0-005)?

XK0-005 By islever Editorial Last updated

Short answer

A at –f /home/admin/script.sh 9pm March 31

Question

A Linux administrator would like to run the cleanup script /home/admin/script.sh at 9:00 p.m. on March 31. Which of the following commands should the administrator use to accomplish this task?
  1. at –f /home/admin/script.sh 9pm March 31 Correct Answer
  2. echo < /home/admin/script.sh | at 9pm March 31
  3. at 9pm March 31 | echo > /home/admin/script.sh
  4. at 9pm March 31 –f /home/admin/script.sh

Key Takeaways

This question tests your ability to use the at command's -f option correctly; the common trap is placing -f after the time or confusing stdin redirection with reading a file.

In the Linux+ XK0-005 exam, scheduling a one-time script with at requires the -f option. Community testing shows at -f /home/admin/script.sh 9pm March 31 is the reliable command.

Common mistake: Option D (`at 9pm March 31 -f ...`) is the most popular wrong choice because many Linux versions allow options after arguments, but the exam and GNU at documentation expect `-f file` before the time.

Expert Analysis

Why the Answer Is Correct

Option A is the standard syntax for the at command: at -f /home/admin/script.sh 9pm March 31. The -f flag tells at to read job commands from the named file, and the time/date specifier follows directly. Comment [1] confirms they tested all four commands and only A produced output, proving it executes successfully. The at man page also lists -f file as the way to run a script without typing it interactively.

Why the Other Options Are Wrong

Option B fails because echo < file | at pipes empty output to at — echo does not read stdin, so the cleanup script is never submitted. Option C is even worse: it pipes at's output into echo > script.sh, attempting to write to the script file and corrupting or truncating it. Option D is a syntax gray area; some modern at builds accept -f after the time, but the official usage and the CompTIA exam favor A, and comment [1] observed D did not work in their one-liner test.

Community Comment Notes

Comment [1] provides valuable hands-on evidence: all four commands were tested, and only A ran the script correctly. Comment [4] incorrectly argues A and D are invalid flags, but the man page proves -f is valid; comment [3] cites Baeldung showing at -f file time, reinforcing A. Treat D as a distractor because the exam expects the canonical option ordering.

Official Reference

https://www.baeldung.com/linux/at-command

This link opens the official vendor documentation in a new tab.

Exam Strategy

For at questions, write the command as at -f <file> <time> and avoid piping or reordering flags. If you're unsure, check the order: the -f option belongs immediately after at before the time.

Community Votes

A
72%
B
28%

72% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.

Discussion 5 contributions

Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.

From public community threads 5

  1. jimr999 👍 4 Answered A
    I tested all four. A ran reliably (I used a bash script to output some text with the time of exection to a text file). B, C, and D produced no output to the text file. C and D did not work as one-liners (the command would be at 9pm March 31 and it puts you at the at> prompt. Adding the remainer of the commands did not result in any output to the text file
  2. NastyNutsu 👍 1 Answered B
    at [TIME] [DATE] A. -f is not a valid option for the at command B. echo < /home/admin/script.sh | at 9pm March 31 -- reading from the source and pipe it down the at command, make sense. C. does not work (you are writing into the source). D. same as A, -f is not a valid flag
  3. lexdaniel 👍 1 Answered D
    D. according to this site, we can also run scheduled tasks by passing a shell script file to the at command using the -f option. Let’s run a file at 00:00 (midnight): $ at 00:00 -f /home/ubuntu/file.sh https://www.baeldung.com/linux/at-command
  4. Bull88 👍 1 Answered B
    the answers ABD are correct, perhaps because I am using lastest versions of Ubuntu and CentOS, but I will stick with the option B, very confusing tbh
  5. HappyDay030303 👍 1 Answered A
    The at command is used to schedule one-time tasks to run at a specific time and date.

Reader comments & corrections

No reader corrections yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

← Back to XK0-005 Study Guide