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 ...
随机推荐
- JavaScript:复选框事件的处理
复选框事件的处理 复选框本身也是多个组件的名字相同.所以在定义复选框的同事依然要使用document.all()取得全部的内容. 范例:操作复选框,要求是可以一个个去选择选项,也可以直接全选,全选按钮 ...
- JavaScript:JavaScript事件的处理
JavaScript事件处理 —————事件的处理流程: —————动态事件绑定: —————常用的事件处理. 1.事件的概念 在页面之中,会针对用户的每一个操作进行记录.在页面中的事件可以简单的理解 ...
- div元素呈圆环排列
<style> .path { width: 300px; height: 300px; padding: 20px; border-radius: 50%; background: rg ...
- 调试 rewrite
等号后面是变量 访问http://m-test.jinlianchu.com/member/register.html?inviteCode=jlc24639 的跳转到https://wx-test ...
- [g2o]一个备忘
g2o使用的一个备忘 位姿已知,闭环的帧已知,进行图优化. #include "stdafx.h" #include <vector> #include "P ...
- 读取Excel文件的版本
读取xls文件和xlsx文件创建的版本号. 虽然xlsx声明的是向前兼容,但是不知道OleDb是不是也是这样,没有办法所以要读取文件版本,限定只能读取Excel2007保存的文件. using ICS ...
- CentOS安装NodeJS v0.10.25 + Express
安装必需组件 yum -y install gcc make gcc-c++ openssl-devel wget cd ~wget http://nodejs.org/dist/v0.10.25/n ...
- 记32位程序(使用3gb用户虚拟内存)使用D3DX9导致的一个崩溃的问题
为了增加32位程序的用户虚拟内存的使用量,我们使用了/LARGEADDRESSAWARE编译选项来使32位程序可能使用到3gb的内存,能否使用到3gb内存也跟平台.系统和设置有关系,现摘抄部分作为参考 ...
- Java基础之写文件——将多个字符串写入到文件中(WriteProverbs)
控制台程序,将一系列有用的格言写入到文件中. 本例使用通道把不同长度的字符串写入到文件中,为了方便从文件中恢复字符串,将每个字符串的长度写入到文件中紧靠字符串本身前面的位置,这可以告知在读取字符串之前 ...
- leetcode8 String to Integer (atoi)
题目需求: 输入一个字符串,输出对应的int值 特殊处理: 输入: null 输出:0 输入: "a122" 输出:0 输入: " 1233" 输出: ...