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
- 1Use mkdir -p to create directories without error if they exist
- 2In scripts, check existence first: [ -d /path ] || mkdir /path
- 3For lock files, check and remove stale locks before creating
- 4Use ln -sf to force-create symlinks even if they exist
- 5In C/C++, handle EEXIST in error handling after system calls
Tags
linuxerrnoeexistfile-existsmkdir
More in Errno
linux-errno-1-epermLinux errno 1 (EPERM) — Operation Not Permitted
Warninglinux-errno-2-enoentLinux errno 2 (ENOENT) — No Such File or Directory
Warninglinux-errno-5-eioLinux errno 5 (EIO) — Input/Output Error
Errorlinux-errno-11-eagainLinux errno 11 (EAGAIN) — Resource Temporarily Unavailable
Informationallinux-errno-12-enomemLinux errno 12 (ENOMEM) — Out of Memory
Criticallinux-errno-13-eaccesLinux errno 13 (EACCES) — Permission Denied
WarningFrequently Asked Questions
On Linux and most POSIX systems, yes. It is defined in errno.h as 17.