所有文件的递归文件列表,包含路径名,类型,大小,创建数据,修改日期的列表 [英] Recursive file list of all files, list containing path+name, type, size, creation data, modification date

查看:84
本文介绍了所有文件的递归文件列表,包含路径名,类型,大小,创建数据,修改日期的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经在stackoverflow上四处查看,用google搜索...但是什么都不适合我的要求... :-)我想要/需要的是一个平面txt文件,其中包含有关特定dir和subdirs中文件的信息.有一些方法可以通过第三方程序以及从终端/unix进行.两种方式对我来说都很好.但是...我需要文件上的以下所有信息:

Have looked around on stackoverflow, googled ... but nothing fits my requirement... :-) What I want/need is a flat txt file containing info on files in a certain dir and subdirs. There are ways to do this with 3rd party programs and from terminal/unix. Both ways would be fine by me. BUT ... I need all of the following info on the file:

路径和文件名 输入(我们在这里谈论的是macintosh,所以它可能来自资源分支,许多非常旧的文件,可以追溯到90年代中期!)

Path and filename Type (we are talking macintosh here, so it might come from the resource fork, many very old files, back to mid 90's!)

文件大小

创建日期

修改日期(这不是必需的,只是需要拥有).

Modification date (this is not essential to have, just good to have).

有什么好主意吗?如前所述,它可能是终端向文件写入的单一形式,也可能是对可以执行此操作的小型应用程序的建议.

Any good ideas? As mentioned, it could be a one-liner for the terminal that writes to a file or suggestion for a small app that can do it.

预先感谢:-)

输出格式没什么大不了,可以用制表符或分号分隔,也可以是其他任何东西,只要它是文本文件-我以后就可以对其进行修改.重要的是那里的信息...:-)

the output format doesn't matter much, can be tab or semicolon seperated or whatever, as long as it's a textfile - I can always modify it after. The important thing is the information is there... :-)

结果-我最终使用的东西(感谢帮助):-)

RESULT - what I ended up using (thanks for the help) :-)

#!/bin/bash

find . -type f -name '*' -print0 | while IFS= read -r -d '' file
do
    name=$(basename "$file")
    path=$(dirname "$file")
    # full_path=$(readlink -f "$file") # This only works on Linux
    full_path=$(echo "$PWD/${file#./}")
    extension=${name##*.}
    size_human_readable=$(ls -lh "$file" | awk -F' ' '{print $5}')
    size_in_bytes=$(stat -f "%z" "$file")
    creation_date=$(stat -f "%SB" "$file")
    last_access=$(stat -f "%Sa" "$file")
    last_modification=$(stat -f "%Sm" "$file")
    last_change=$(stat -f "%Sc" "$file")
    creator=$(mdls -name kMDItemFSCreatorCode "$file")


    printf "\"%q\";" "$name"
    printf "\"%q\";" "$full_path"
    printf "%s" "\"$extension\";"
    printf "\"$size_human_readable\";"
    printf "\"$size_in_bytes\";"
    printf "\"$last_modification\";"
    printf "%s" "\"$creator\""
    printf "\n"
done

推荐答案

也许是这样的:

#!/bin/bash

find . -type f -name '*' -print0 | while IFS= read -r -d '' file
do
    name=$(basename "$file")
    path=$(dirname "$file")
    # full_path=$(readlink -f "$file") # This only works on Linux
    full_path=$(echo "$PWD/${file#./}")
    extension=${name##*.}
    size_human_readable=$(ls -lh "$file" | awk -F' ' '{print $5}')
    size_in_bytes=$(stat -f "%z" "$file")
    creation_date=$(stat -f "%SB" "$file")
    last_access=$(stat -f "%Sa" "$file")
    last_modification=$(stat -f "%Sm" "$file")
    last_change=$(stat -f "%Sc" "$file")

    printf "[$file]:\n"
    printf "\tfile name:\t\t$name\n"
    printf "\tfile path:\t\t$path\n"
    printf "\tfull file path:\t\t$full_path\n"
    printf "\tfile extension:\t\t$extension\n"
    printf "\tfile size:\t\t$size_human_readable\n"
    printf "\tfile size in bytes:\t$size_in_bytes\n"
    printf "\tfile creation date:\t$creation_date\n"
    printf "\tlast file access:\t$last_access\n"
    printf "\tlast file modification:\t$last_modification\n"
    printf "\tlast file change:\t$last_change\n"
    printf "\n"
done

您当然可以修改输出!将此脚本复制到文件中(例如recursive_file_info.sh).然后使用chmod +x recursive_file_info.sh使其可执行.如果您希望将输出显示在文本文件中,则可以使用./recursive_file_info.sh > files.txt重定向它.

Of course you can modify the output! Copy this script into a file (e.g. recursive_file_info.sh). Then make it executable with chmod +x recursive_file_info.sh. If you want the output in a text file you can redirect it with ./recursive_file_info.sh > files.txt.

这篇关于所有文件的递归文件列表,包含路径名,类型,大小,创建数据,修改日期的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆