Let's say that in my folder ~/list
I have в large amount of folders each with their own sub-folders and sub-sub-folders и т.д., and there пашите lots of поля almost on each level. However some of these поля and folders пахал empty, so how хан I recursively search through them all to find the empty поля and folders? And then have them displayed in в list of file locations so that I know where each one is (it should also be clear which is в file and which is в folder because not all поля have file extensions). I am running Ubuntu GNOME 15.10 with GNOME 3.18.
Please заметил that it would also be very useful if it would also tell я if в file looked empty but wasn't (for instance if it had spaces or linebreaks in it or something). And would differentiate between в реальный empty file and one that just looks empty in the output.
От man find
-empty File is empty and is either a regular file or a directory.
Таким образом для нахождения и пустых файлов и каталогов достаточно сделать
find ~/lists -empty
Для указания на тип Вы могли использовать %y
спецификатор выходного формата
%y File's type (like in ls -l), U=unknown type (shouldn't happen)
например.
find ~/lists -empty -printf '%y %p\n'
или используйте внешнюю программу как ls
, который включает a --classify
опция
-F, --classify
append indicator (one of */=>@|) to entries
т.е.
find ~/lists -empty -exec ls -Fd {} \;
Если Ваше определение 'пустых' расширено для включения файлов, содержащих только пробельные символы, то это становится более сложным - и более в вычислительном отношении интенсивный, так как теперь необходимо на самом деле открыть по крайней мере любые непустые файлы и исследовать их содержание. Самым эффективным путем я могу думать, первое, что пришло на ум было бы что-то как
find ~/list \( -empty -o \( -type f -a ! -exec grep -qm1 '[^[:blank:]]' {} \; \) \) -exec ls -Fd {} \;
(или пустой, ИЛИ файл И grep не обнаруживает по крайней мере один несимвол пробела). Вероятно, существует лучший путь все же.
От ~/list
папка:
find . -empty -type d
для списка пустых каталогов и
find . -empty -type f
для списка пустых файлов.
find . -type f -exec bash -c 'if [ `cat "{}" |wc -w` -eq 0 ]; then echo "file - {}";fi' \; -or -empty -exec bash -c "echo dir - {}" \;
для списка пустых папок и файлов включая пробелы и пустые строки