nerdexam
Linux_Foundation

LFCS · Question #844

If the current directory is /root and the kernel source is located in /usr/src/linux, which of the following commands should be used to apply the patch /tmp/foopatch?

The correct answer is D. cd /usr/src/linux; patch -p1 < /tmp/foopatch. To apply a patch, navigate to the target directory and use the patch command, specifying the patch level and redirecting the patch file as input.

Submitted by khalil_dz· Apr 18, 2026Essential Commands

Question

If the current directory is /root and the kernel source is located in /usr/src/linux, which of the following commands should be used to apply the patch /tmp/foopatch?

Options

  • Acd /usr/src/linux; cat /tmp/foopatch | patch
  • Bcd /usr/src/linux; cat /tmp/foopatch | patch -p0
  • Ccd /usr/src/linux; patch -p1 > /tmp/foopatch
  • Dcd /usr/src/linux; patch -p1 < /tmp/foopatch
  • Ecat /tmp/foopatch | patch -p0

How the community answered

(60 responses)
  • A
    3% (2)
  • B
    10% (6)
  • C
    2% (1)
  • D
    83% (50)
  • E
    2% (1)

Why each option

To apply a patch, navigate to the target directory and use the `patch` command, specifying the patch level and redirecting the patch file as input.

Acd /usr/src/linux; cat /tmp/foopatch | patch

`patch` without `-p` might fail due to incorrect path matching, and piping `cat` output is less direct than input redirection.

Bcd /usr/src/linux; cat /tmp/foopatch | patch -p0

`patch -p0` would expect file paths in the patch file to be relative to the current directory *without* stripping any directory components, which is less common for kernel patches.

Ccd /usr/src/linux; patch -p1 > /tmp/foopatch

`patch -p1 > /tmp/foopatch` would attempt to write the *output* of the `patch` command to `/tmp/foopatch`, not apply the patch from it.

Dcd /usr/src/linux; patch -p1 < /tmp/foopatchCorrect

D is correct because `cd /usr/src/linux` changes to the directory where the patch needs to be applied, and `patch -p1 < /tmp/foopatch` then applies the patch. The `-p1` option tells `patch` to strip one leading directory component from the file paths in the patch file, which is common for patches generated from a `diff -uprN` command, and `< /tmp/foopatch` redirects the patch file content as input to the `patch` command.

Ecat /tmp/foopatch | patch -p0

Applying the patch from `/root` without changing directory would likely result in "File not found" errors for the paths within the patch.

Concept tested: Applying patches (`patch` command)

Source: https://man7.org/linux/man-pages/man1/patch.1.html

Topics

#patch command#input redirection#file system navigation#patch levels

Community Discussion

No community discussion yet for this question.

Full LFCS Practice