> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bash Newer Than

The `-nt` (newer than) operator is a binary file test operator in Bash used to compare the modification timestamps (`mtime`) of two files. It evaluates to true (exit status `0`) if the first file was modified more recently than the second file, or if the first file exists and the second file does not.

## Syntax and Variable Quoting

The operator is evaluated using either the `test` command (`[`), or the Bash extended test construct (`[[`).

```bash theme={"dark"}
[ "$file1" -nt "$file2" ]
```

```bash theme={"dark"}
[[ $file1 -nt $file2 ]]
```

When using the `[` command, variables **must be quoted**. If an unquoted variable evaluates to an empty string or contains spaces, word splitting alters the number of arguments passed to `[`, resulting in a syntax error (e.g., `[: -nt: unary operator expected`). The Bash extended test construct (`[[`) safely handles unquoted variables because it suppresses word splitting and pathname expansion during evaluation.

## Portability

While the `[` command is a standard POSIX utility, the `-nt` operator is historically a Bash and KornShell (ksh) extension. Although `-nt` was recently formalized in the POSIX.1-2024 standard, using `[ "$file1" -nt "$file2" ]` is not universally portable. Executing this operator in older or strictly POSIX-compliant shells (such as `yash` or older `dash`/`ash` environments) may result in an evaluation failure or syntax error.

## Evaluation Logic

The operator returns a boolean exit status based on the following matrix:

| State of `file1` | State of `file2` | Condition                      | Exit Status |
| :--------------- | :--------------- | :----------------------------- | :---------- |
| Exists           | Exists           | `mtime(file1) > mtime(file2)`  | `0` (True)  |
| Exists           | Exists           | `mtime(file1) <= mtime(file2)` | `1` (False) |
| Exists           | Does not exist   | N/A                            | `0` (True)  |
| Does not exist   | Exists           | N/A                            | `1` (False) |
| Does not exist   | Does not exist   | N/A                            | `1` (False) |

## Technical Characteristics

* **Timestamp Resolution:** The precision of the `-nt` comparison is strictly bound by the underlying filesystem. Modern filesystems (like `ext4`, `xfs`, or `zfs`) support nanosecond precision, allowing `-nt` to differentiate between files created fractions of a second apart. Older filesystems (like `FAT32`) may only support 2-second resolution, which can result in a false negative (`1`) if two files are modified within the same resolution window.
* **Symlink Dereferencing:** The `-nt` operator automatically dereferences symbolic links. It compares the `mtime` of the ultimate target file, not the inode of the symlink itself. If a symlink is broken (points to a non-existent target), Bash evaluates it as a non-existent file according to the logic matrix above.
* **Directory Handling:** Directories are treated as standard files. The operator evaluates the `mtime` of the directory's inode, which is updated only when the directory's direct contents are modified (e.g., a file is created, deleted, or renamed within it), not when the contents of files within the directory are modified.
* **Strict Inequality:** The operator performs a strictly greater-than comparison. If `file1` and `file2` have the exact same `mtime`, `-nt` evaluates to false (`1`).

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Bash Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
