[英]How to generate manifest (List of files with their sizes and count) for a folder in linux
How to generate manifest containing all files except particular file name in a folder like the fillowing. 如何生成包含除填充之类的文件夹中除特定文件名之外的所有文件的清单。
Acctual requirement 实际要求
4
issue1425.tgz 3096209598
issue1426.TGZ 3096209591
issue1427.ZIP 3096209592
issue1428.zip 3096209593
=> total number of files: 4 =>文件总数:4
file name: issue1425.tgz 文件名:issue1425.tgz
size of file: 123333 文件大小:123333
.... ....
im doing Like this 我喜欢这样
ls i2*.* |wc -l >>manifest.txt
vdir i2*.* >>manifest.txt
Output in "manifest.txt" from this is 从“manifest.txt”输出的是
4
-rwxr-Sr-t 1 root root 3096209598 2013-03-28 05:46 issue1425.tgz
-rwxrw-r-- 1 root root 3096209591 2013-03-20 06:46 issue1426.TGZ
-rwxr-Sr-t 1 root root 3096209592 2013-03-28 07:46 issue1427.ZIP
-rwxrw-r-- 1 root root 3096209593 2013-03-20 08:46 issue1428.zip
does any one has the solution to get my exact requirement: 有没有人有解决方案来满足我的确切要求:
Edit 2:@jarnbjo your command gives me wrong output see the actual sizes of files but its gives me wrongly. 编辑2:@jarnbjo你的命令给我错误的输出看到文件的实际大小,但它错误地给了我。
root@aim-deb:/mnt/arch1/batchfiles/siva/20130328094916142/received# vdir
total 108816
drwxrwxrwx 5 1330 sno 4096 2013-03-20 00:30 i23321367
-rw-rw-r-- 1 1330 sno 39934457 2013-03-20 03:20 i23321367.tgz
drwxrwxrwx 5 1330 sno 4096 2013-03-20 00:33 i23321376
-rw-rw-r-- 1 1330 sno 36030069 2013-03-20 03:20 i23321376.tgz
drwxrwxrwx 5 1330 sno 4096 2013-03-20 00:34 i23321436
-rw-rw-r-- 1 1330 sno 35310600 2013-03-20 03:20 i23321436.tgz
-rw-r--r-- 1 root root 69 2013-03-29 00:57 manifest_QAG.txt
-rw-rw-r-- 1 1330 sno 75 2013-03-20 03:20 manifest.txt
root@aim-deb:/mnt/arch1/batchfiles/siva/20130328094916142/received# ls -1s -- block-size=1 i*.* $dir| awk '{print $2"\t"$1}'
i23321367.tgz 39981056
i23321376.tgz 36073472
i23321436.tgz 35352576
root@aim-deb:/mnt/arch1/batchfiles/siva/20130328094916142/received#
Answer:@jarnbjo thanks finally i got it why its happening. 答案:@jarnbjo,谢谢,我明白为什么会发生这种情况。 block size gives me size if file size on disk not actual size of file.
如果磁盘上的文件大小不是文件的实际大小,则块大小给出了大小。 here i want size of file so i can use vdir i*.* $dir|
这里我想要文件的大小,所以我可以使用vdir i *。* $ dir | awk '{print $8"\\t"$5}'
awk'{print $ 8“\\ t”$ 5}'
If you just want the amount of files and its size, try with this: 如果您只想要文件数量及其大小,请尝试使用:
ls -1hs $dir
h
stands for human readable h
代表人类可读 s
stands for size s
代表大小 1
(one)just shows the names of files, one on each line. 1
(一)只显示文件的名称,每行一个。 And if you want it to be first name, then size, use: 如果你想要它的名字,然后大小,使用:
ls -1hs $dir | awk '{print $2" "$1}'
Edit 编辑
From comments, you want it to have size in bytes, so you can do it like: 从注释中,您希望它具有以字节为单位的大小,因此您可以这样做:
ls -1s --block-size=1 $dir
Further edit 进一步编辑
If you want the dir not to be displayed, you have to cd $dir
previously. 如果你想要不显示目录,你必须先
cd $dir
。 There are other ways, but this seems to be the cleanest. 还有其他方法,但这似乎是最干净的。
cd $dir; ls -1s --block-size=1 is*.* | awk '{print $2"\t"$1}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.