linux - Bash 脚本,不使用 ls 输出文件夹内容和字节大小

标签 linux bash variables output

我正在编写 bash 脚本。 此脚本应显示文件夹的内容及其字节大小。 通常我会使用 ls 命令,但在本练习中我不能使用它。 显示屏上的输出必须采用“file_name:bite_size”格式 所以我尝试了几个小时,我得到的是:

#!/bin/bash

IFS=" ";

string="$(du -bc /var/*)";

textArray=($string);

for ((i=0; i<${#textArray[@]}; ++i));
    do
            echo "${textArray[$i]}";
    done
exit 0;

我走对了还是完全错了?

最佳答案

也许是这样的:

stat --format="%n:%s" *

关于linux - Bash 脚本,不使用 ls 输出文件夹内容和字节大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24392105/

相关文章:

c++ - QMessageBox使用快捷键多次打开

php - 为网络爬虫优化 PHP CURL

bash - 如何将参数传递给带空格的 docker run

bash - Makefile 匹配任何目标/任务

python - 在 Python 中通过源代码安装时出现错误 "can' t create or remove files in install directory”

c - 通过管道的多条消息

linux - lsdev 有 mac os x 版本吗?

jquery - 在变量上使用 jQuery 而不是在 DOM 上?

javascript - 使用 Jquery 更新全局 JS 变量并返回该值

java - 创建具有动态长度的整数数组时无法显示数组