Главная > Linux > linux — очистить все файлы в папке

linux — очистить все файлы в папке

find ./ -type f -exec sh -c 'cat /dev/null > {}' \;
Categories: Linux Tags:
  1. Konstantin Krylov
    26 августа,2018 в 01:40 | #1

    @Alex
    В моем случае необходимо было обнулить размер всех файлов в папке, а не удалить их.

  2. Alex
    25 августа,2018 в 21:25 | #2

    Опция -delete уже поддерживается find.

    root@L2246:/mnt/c/Users/alexander# ls -l temp/file{1..3}
    -rwxrwxrwx 1 root root 0 Aug 25 20:22 temp/file1
    -rwxrwxrwx 1 root root 0 Aug 25 20:22 temp/file2
    -rwxrwxrwx 1 root root 0 Aug 25 20:22 temp/file3

    root@L2246:/mnt/c/Users/alexander# find temp/ -type f -delete

    root@L2246:/mnt/c/Users/alexander# ls -l temp/
    total 0

    root@L2246:/mnt/c/Users/alexander# find —version
    find (GNU findutils) 4.4.2
    Copyright (C) 2007 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

    Written by Eric B. Decker, James Youngman, and Kevin Dalley.
    Built using GNU gnulib version e5573b1bad88bfabcda181b9e0125fb0c52b7d3b
    Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS() CBO(level=0)

Похожие публикации