Error Codes Wiki

Linux errno 17 EEXIST — File Exists Error

Warningerrno

Overview

Linux errno 17 (EEXIST) occurs when a program tries to create a file or directory that already exists, common with mkdir, link, and mkfifo system calls.

Key Details

  • EEXIST is errno 17 on most Linux systems
  • Triggered by system calls that expect to create a new object
  • mkdir() fails with EEXIST if the directory already exists
  • open() with O_CREAT | O_EXCL fails if the file exists
  • Common in scripts that do not check existence before creation

Common Causes

  • Script running mkdir without checking if directory exists
  • Race condition where multiple processes create the same file
  • Package installation trying to create existing directories
  • Symlink creation when target already exists
  • Lock file already present from a previous process

Steps

  1. 1Use mkdir -p to create directories without error if they exist
  2. 2In scripts, check existence first: [ -d /path ] || mkdir /path
  3. 3For lock files, check and remove stale locks before creating
  4. 4Use ln -sf to force-create symlinks even if they exist
  5. 5In C/C++, handle EEXIST in error handling after system calls

Tags

linuxerrnoeexistfile-existsmkdir

More in Errno

Frequently Asked Questions

On Linux and most POSIX systems, yes. It is defined in errno.h as 17.