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 ...
随机推荐
- java中 set,list,array(集合与数组)相互转换
public static Object[] List2Array(List<Object> oList) { Object[] oArray = oList.toArray(new ...
- Android中颜色的设置
方案一:新建xml文件,然后在java中用代码访问(xml文件可以直接访问) 1.在res->values文件夹下新建color.xml(这个文件中定义的代码是#RRGGBB) 2.在java类 ...
- 《30天自制操作系统》11_day_学习笔记
harib08a: 鼠标的显示问题:我们可以看到,鼠标移到窗口最右侧之后就不能再移动了,而WIN中,鼠标是可以移动到最右边隐藏起来的.怎么办?把鼠标指针显示的范围扩宽就行!我们来修改一下HariMai ...
- PostgreSQL与RPM
如何查看使用PostgreSQL的RPM包安装后的文件目录及相关路径(PostgreSQLRPM的spec文件已经帮我们创建好了postgres用户及postgres组). 查看RPM文档信息:/us ...
- Lintcode: Topological Sorting
Given an directed graph, a topological order of the graph nodes is defined as follow: For each direc ...
- 配置DruidDataSource参考(com.alibaba.druid.pool.DruidDataSource)
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-met ...
- .NET: WPF Template
Data Template: 要做一个listBox,里面有车子的简单信息,点了里面的item后就会显示详细信息. car class: using System; using System.Coll ...
- 对ImageView.ScaleType的详解
设置的方式有两种: 1.在layout.xml里面定义android:scaleType = "center" 2.在代码中调用imageview.setScaleType(Ima ...
- gulpfile.js
文件目录如上: 下载代码地址:https://github.com/lianbinghua/gulptest 切换目录:cd gulp 安装依赖包:npm install 编译文件:gulp或者gul ...
- cocos2dx建立项目
http://www.cocos.com/doc/article/index?type=wiki&url=/doc/cocos-docs-master/manual/framework/nat ...