0

I am trying to find reason behind this happening and also a solution .

When I try to run below command on Unix directory which has around 16 files and also one of the application process which keeps removing or renaming the files from this same directory. The issue happens when I invoke the command and at the same time one or more files are moved from this location by the application process running.

ls -al |wc -l
ls: 'file_which_has_removed.txt': No such file or directory

I also find same issue while firing find command.

find . -maxdepth 1 -atime +15
/bin/find: '/u1/bruce/File_removed.txt': No such file or directory

The solution ism trying to find is , I s there any way we can avoid this error, _ want to run this find command and then use -delete to remove these old files from directory without stopping the application process.

3
  • man find has an option specifically for this; for ls you could pipe stederr to /dev/null
    – cutrightjm
    Commented Nov 29, 2021 at 2:09
  • Great ...I found this option -ignore_readdir_race which looks like solution to this problem for find . Will test it and confirm Commented Nov 29, 2021 at 6:11
  • unfortunately this is not working . Not sure if this is bug Commented Dec 2, 2021 at 14:16

1 Answer 1

0

In both cases you hit a race condition:

strace ls -l tmpdir/
[...]
openat(AT_FDCWD, "tmpdir/", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
newfstatat(3, "", {st_mode=S_IFDIR|0755, st_size=34, ...}, AT_EMPTY_PATH) = 0
getdents64(3, 0x562392b64920 /* 8 entries */, 32768) = 200

statx(AT_FDCWD, "tmpdir/1.", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW, STATX_MODE|STATX_NLINK|STATX [...]
lgetxattr("tmpdir/1.", "security.selinux", 0x562392b6c930, 255) = -1 ENODATA (Keine Daten verfügbar)
getxattr("tmpdir/1.", "system.posix_acl_access", NULL, 0) = -1 ENODATA (Keine Daten verfügbar)

First the program reads a list of the names of the content of the directory. Later for each of those names the details are requested. If the object has been renamed in the meantime then the error occurs.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .