简体   繁体   English

Linux:如何列出有关文件或目录的信息(大小,权限,按类型划分的文件数?)

[英]Linux:How to list the information about file or directory(size,permission,number of files by type?) in total

Suppose I am staying in currenty directory, I wanted to list all the files in total numbers, as well as the size, permission, and also the number of files by types.假设我留在当前目录中,我想列出所有文件的总数,以及大小、权限以及按类型划分的文件数。

here is the sample outputs:这是示例输出:

Here is a sample :这是一个示例:

Print information about "/home/user/poker"打印有关“/home/user/poker”的信息

total number of file : 83文件总数:83

pdf files : 5 pdf文件:5

html files : 9 html文件:9

text files : 15文本文件:15

unknown : 5未知:5

NB: anyfile without extension could be consider as unknown.注意:任何没有扩展名的文件都可以被认为是未知的。

i hope to use some simple command like ls, cut, sort, unique ,(just examples) put each different extension in file and using wc -l to count number of lines我希望使用一些简单的命令,如 ls、cut、sort、unique ,(只是示例)将每个不同的扩展名放在文件中并使用 wc -l 来计算行数

or do i need to use grep, awk , or something else?还是我需要使用 grep、awk 或其他东西?

Hope to get the everybody's advices.thank you!希望得到大家的建议。谢谢!

Best way is to use file to output only mimetype and pass it to awk .最好的方法是使用file仅输出 mimetype 并将其传递给awk

file * -ib | awk -F'[;/.]' '{print $(NF-1)}' | sort -n | uniq -c

On my home directory it produces this output.在我的主目录上,它会生成此输出。

 35 directory
  3 html
  1 jpeg
  1 octet-stream
  1 pdf
 32 plain
  5 png
  1 spreadsheet
  7 symlink
  1 text
  1 x-c++
  3 x-empty
  1 xml
  2 x-ms-asf
  4 x-shellscript
  1 x-shockwave-flash

If you think text/x-c++ and text/plain should be in same Use this如果你认为text/x-c++text/plain应该在同一个使用这个

 file * -ib | awk -F'[;/.]' '{print $1}' | sort -n | uniq -c

  6 application
  6 image
 45 inode
 40 text
  2 video

Change the {print $1} part according to your need to get the appropriate output.根据需要更改{print $1}部分以获得适当的输出。

You need bash .你需要bash

files=(*)
pdfs=(*.pdf)

echo "${#files[@]}"
echo "${#pdfs[@]}"
echo "$((${#files[@]}-${#pdfs[@]}))"

find . -type f | xargs -n1 basename | fgrep . | sed 's/.*\\.//' | sort | uniq -c | sort -n

That gives you a recursive list of file extensions.这为您提供了文件扩展名的递归列表。 If you want only the current directory add a -maxdepth 1 to the find command.如果您只想要当前目录,请在 find 命令中添加-maxdepth 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Linux中列出目录中的文件和文件夹及其总大小? - How to list the files and folders in a directory with its total size in Linux? 在Python中,列出Linux上某个目录中的某些类型的文件 - In Python, list certain type of file in a directory on Linux Linux Bash 脚本:获取给定目录中“png”和“gif”文件的总大小,然后比较大小 - Linux Bash Scripting: Obtain the total size of 'png' and 'gif' files in a given Directory then compare the size 如何在Linux上的目录中找到csv文件的总行数? - How to find the total lines of csv files in a directory on Linux? 关于Linux系统上的文件的信息? - Information about file on Linux system? 如何在linux中仅递归计算某些文件的总大小 - How to calculate the total size of certain files only, recursive, in linux Linux:如何将 output 目录大小作为不包括目录路径的数字 - Linux: How to output directory size as a number excluding directory path 如何列出 Linux 终端中大小/长度为零的目录中的文件? - How can I list the files in a directory that have zero size/length in the Linux terminal? 如何递归获取目录下所有文件的总大小 - How to get total size of all files recursively under directory 如何在Linux中获取当前目录下文件的信息 - how to get information of files under current directory in Linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM