本文于 9 天前发布,最后更新于 9 天前
lsr() { find "${@:-.}" -print0 | sort -z | xargs -0 ls --color=auto -dlha; }
命令注释:
${@:-.}
:传递给 lsr 函数的所有参数(即路径),如果没有提供参数,则以 . 作为起点(当前路径)-print0
:处理特殊字符sort -z
:排序并处理特殊字符xargs -0 ls --color=auto -dlha
:列出文件并着色
使用方法:
(1)将函数添加到环境变量中
[root@dameng ~]# cat .bash_profile
lsr() { find "${@:-.}" -print0 | sort -z | xargs -0 ls --color=auto -dlha; }
(2)使环境变量生效
[root@dameng ~]# source .bash_profile
(3)使用验证
[root@dameng ~]# lsr /home/wwwroot/wordpress/live2d-widget-master/
drwxr-xr-x 5 www www 4.0K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/
drwxr-xr-x 2 www www 4.0K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/assets
-rw-r--r-- 1 www www 48K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/assets/screenshot-1.png
-rw-r--r-- 1 www www 321K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/assets/screenshot-2.png
-rw-r--r-- 1 www www 243K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/assets/screenshot-3.png
-rw-r--r-- 1 www www 2.2K Nov 24 14:39 /home/wwwroot/wordpress/live2d-widget-master/autoload.js
drwxr-xr-x 2 www www 4.0K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/demo
-rwxr-xr-x 1 www www 1.5K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/demo/demo.html
-rwxr-xr-x 1 www www 6.4K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/demo/login.html
-rw-r--r-- 1 www www 41 Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/.gitignore
-rw-r--r-- 1 www www 35K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/LICENSE
-rwxr-xr-x 1 www www 148K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/live2d.min.js
-rw-r--r-- 1 www www 919 Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/package.json
-rw-r--r-- 1 www www 11K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/README.en.md
-rw-r--r-- 1 www www 10K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/README.md
-rw-r--r-- 1 www www 881 Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/rollup.config.js
drwxr-xr-x 2 www www 4.0K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/src
-rwxr-xr-x 1 www www 6.9K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/src/index.js
-rw-r--r-- 1 www www 722 Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/src/message.js
-rw-r--r-- 1 www www 3.0K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/src/model.js
-rw-r--r-- 1 www www 2.8K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/src/tools.js
-rw-r--r-- 1 www www 150 Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/src/utils.js
-rw-r--r-- 1 www www 70 Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/src/waifu-tips.js
-rwxr-xr-x 1 www www 4.9K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/waifu.css
-rw-r--r-- 1 www www 12K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/waifu-tips.js
-rwxr-xr-x 1 www www 12K Feb 26 2024 /home/wwwroot/wordpress/live2d-widget-master/waifu-tips.json
如上图,函数使用成功。