lz: linux ls 变种 只显示大小和名称(包括目录)
本次输入法使用: 手心输入法 for Mac 1.0版
测试环境为:Ubuntu 14.14.2 LTS updates
测试时间为:2015年5月28日,感觉死亡将至的夜晚,独自一人坐在一个角落,戴着耳机盖着帽子,穿着衬衫的那一天,外面下着雨,不小不大,不紧不慢,却分外的让人不自然,写到这里放的歌是:苏运莹的《野子》
主要解决了特殊用法(为制定参数,. ,..,*的使用)
-d 检测是否为directory时,如果参数为空,也会被错误的认为目录,这是bash的一个诟病吗?应该吧,不过结合-z选项就可以解决。但是问题的关键是我以为-d是会识别的,其实我高估了-d,[see line 34-36]
function lz() {
function du_dir() {
echo -e "\033[01;33m$1\033[00m" # $((RANDOM%6+1))
(cd $; ls - >/dev/null | sed -e 's/^/"/' -e 's/$/"/'| xargs du -h -d >/dev/null)
}
function du_file() {
(ls -lha $ | awk '{print $5,$9}')
}
function getpath() { # support . and .. as the special path
cd $
echo `pwd`
}
function usage(){
echo -e " \033[01;37musage:\033[00m le [dir]/[file] ..."
echo " if no arguement is given, 'lz' will print the current working dir"
echo " .(current dir), ..(parent dir), *(metachar) are supported"
echo -e "\n -V/-h for this help page"
echo -e " \n--------------------------------------------------\n lz v0.1 by Ray Lee - March 30, 2015"
echo -e " updates:\n 1.clone 'le' as 'lz', new feature added\n 2.empty parameter doesn't work"
echo -e " ^\n lz v0.2 by Ray Lee - may 28, 2015"
echo -e " updates: \n 1.make the empty arg work, printing the current directory\n 2.-V and -h works\n 3.add comments for code block\n 4.modify the help page"
}
default='.'
args=($@)
if [[ ${#args[@]} -gt ]]; then
## the * meta means all the things in the current directory, length of it is gt 1 when current dir contains
## more than 1 thing, 1 if there is only one thing, le 1 when empty
28 ##
for each in ${args[@]}; do
[ -d $each ] && du_dir `getpath $each` || du_file `getpath $each`
done
elif [ ! -z $ ]; then
## The oddness of the -d option for file test is that it recognises the empty as a directory
34 ## So the -z should be used to make -d solid for empty args.
35 ##
if [ -d $ ]; then # support . and .. as the special path
du_dir `getpath $`
elif [[ $ == '-V' ]]; then
usage
elif [[ $ == '-h' ]]; then
usage
fi
else
du_dir `getpath "."`
fi
}
Results:
Reference:
1. http://www.cnblogs.com/raybiolee/p/4240363.html
lz: linux ls 变种 只显示大小和名称(包括目录)的更多相关文章
- hbuilder在android手机里用chrome调试,只显示了设备名称,却没有inspect按钮
stark 通过“菜单”->“工具”->“检查设备”打开设备检查页面,只显示了设备名称,却没有inspect按钮,要怎么办 1 赞2014-10-09 22:00 ============ ...
- [Linux] 终端设置只显示当前目录及终端美化
1.只显示当前目录 vim ~/.bashrc 找到位置: if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($d ...
- php递归遍历目录计算其大小(文件包括目录和普通文件)
<?php function countdir($path){ $size = 0; //size = 0; 跟 size = null; 怎么结果不一样 $path = rtrim($path ...
- 关于虚拟机下centOS版linux系统ifconfig只显示inet6ip,不显示inet4ip的问题
在linux命令窗口输入ifconfig会显示如下 [root@localhost Desktop]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0 ...
- AD域-让共享目录只显示用户有权限访问的文件夹
问题: 在AD域中,我们一般都会用到共享,如果有很多部门,我们可能还会按部门.职位配置权限.比如CSD,IT,PA等,但文件夹一多,用户看着就头大,而且用户没权限访问的文件夹误点击进去还会提示无权限访 ...
- Linux学习总结(5)——CentOS常用的目录文件操作命令
CentOS常用的目录文件操作命令 一.路径操作的CentOS常用命令 cd pwd NO1. 显示当前路径 [root@rehat root]# pwd NO2. 返回用户主目录 [roo ...
- Linux -- ls只显示目录
ls没有直接显示目录的选项, 不过根据目录和文件显示的差异,可以搭配grep来实现 方法1: ll | grep "^d" 方法2: ls -F | grep$ "/$& ...
- Linux显示只显示目录文件
Linux显示只显示目录文件 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ ls -l -d */ drwxr-xr-x 2 root root 4096 1 ...
- Linux 只显示目录或者文件方法
ls 参数 -a 表示显示所有文件,包含隐藏文件-d 表示显示目录自身的属性,而不是目录中的内容-F 选项会在显示目录条目时,在目录后加一个/ 只显示目录 方法一: find . -type d -m ...
随机推荐
- [BS-05] init、initWithFrame和initWithCoder的区别
init.initWithFrame和initWithCoder的区别 1.Xib方式自定义UIView(指任意的UI控件) 使用Xib文件,就是我们所常用的“拖控件”的方式.如果我们使用了该方法创建 ...
- [BS-01] 根据字符串对象的参数自动计算用来显示该字符串的UI控件的宽和高
根据字符串对象的参数自动计算用来显示该字符串的UI控件的宽和高 1. 影响昵称Label的高和宽的因素: 字体和字号大小.文字多少.高度取决于是否固定了宽度(是否限制了最大的宽度和高度) 2. 使用 ...
- Android解决java.lang.OutOfMemoryError: bitmap size exceeds VM budget(转)
昨天遇到这个问题就是从一个输入流里调用BitmapFactory.decodeStream(this.getContentResolver().openInputStream(uri))得到一个bit ...
- 第十二篇 Integration Services:高级日志记录
本篇文章是Integration Services系列的第十二篇,详细内容请参考原文. 简介在前一篇文章我们配置了SSIS内置日志记录,演示了简单和高级日志配置,保存并查看日志配置,生成自定义日志消息 ...
- C#和VC++字符集和编码
C# char 关键字用于声明 .NET framework 使用 Unicode 字符表示 System.Char 结构的实例. Char 对象的值是 16 位数字 (序号值.)将字符表示为 UTF ...
- 批量文本读取URL获取正常访问且保留对应IP
#coding=utf-8 import sys import requests for i in range(3000,4999,1): url = 'http://192.168.88.139:8 ...
- 常见的appbug(转)
移动App Bug的影响是用户体验差.App的商店评级下降.用户换用竞争对手的App,声誉和信誉损失.最后销售量减少,如果它是一个付费App的话. 移动App测试与传统台式机测试相比有一定的复杂性.这 ...
- C++之路进阶——codevs2460(树的统计)
2460 树的统计 2008年省队选拔赛浙江 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 一棵树上有n个节 ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- java socket 发送文件
客户端: package tt; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStrea ...