linux - 将 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; } '
我尝试了多种方式,但我只收到多个语法错误。我尝试转义 $ 符号,将 " 放在开头和结尾,但它不起作用。
解决方案
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 ... ; }
推荐阅读
- tensorflow - Tensorflow:FailedPreconditionError:从容器读取资源变量时出错:localhost。在自定义损失函数上运行 sess.run() 时
- azure - 在 Azure Functions 中使用 Azure 应用程序配置的功能标志
- javascript - react-native-video 同时播放单独的视频和音轨?
- javascript - 如何在javascript中声明与类名中的属性同名的函数?
- python - 如何创建具有多级列的 DataFrame?
- parse-platform - 使用 setTimeout() 安排推送
- java - 使用 PDF BOX 库绘制具有背景颜色的图像
- php - 如何在php中制作动态表头
- r - 如何将RDS保存到标准输出?
- python - python 3中的无效语法(elif语句)