首页 > 解决方案 > 将 oneline 命令放入别名中

问题描述

我不能将此命令放入 linux 别名中。

du --max-depth=1 | sort -nr | awk ' BEGIN { split("KB,MB,GB,TB", Units, ","); } { u = 1; while ($1 >= 1024) { $1 = $1 / 1024; u += 1 } $1 = sprintf("%.1f %s", $1, Units[u]); print $0; } '

我尝试了多种方式,但我只收到多个语法错误。我尝试转义 $ 符号,将 " 放在开头和结尾,但它不起作用。

标签: linuxbashalias

解决方案


Do not bother with aliases. They have been effectively deprecated for over 2 decades. It is trivial to use a function. Put this in your startup scripts:

foo() { du --max-depth=1 | sort -nr | awk  ... ; }

推荐阅读