1、测试文件及路径
root@PC1:/home/test# ls a.txt gwas.bed test1 test2 root@PC1:/home/test# pwd /home/test root@PC1:/home/test# ll -h total 24K drwxr-xr-x 4 root root 4.0K 2月 8 13:53 ./ drwxr-xr-x 8 root root 4.0K 2月 8 13:53 ../ -rw-r--r-- 1 root root 549 2月 7 16:54 a.txt -rw-r--r-- 1 root root 341 2月 7 16:56 gwas.bed drwxr-xr-x 2 root root 4.0K 2月 8 13:53 test1/ drwxr-xr-x 2 root root 4.0K 2月 8 13:53 test2/
2、ls + tr + awk实现
root@PC1:/home/test# ls a.txt gwas.bed test1 test2 root@PC1:/home/test# ls | tr "\t" "\n" a.txt gwas.bed test1 test2 root@PC1:/home/test# ls | tr "\t" "\n" | awk -v a=$(pwd) '{print a"/"$0}' ## 先把文件及目录转换为列,然后添加路径 /home/test/a.txt /home/test/gwas.bed /home/test/test1 /home/test/test2
3、ls + sed实现
root@PC1:/home/test# ls a.txt gwas.bed test1 test2 root@PC1:/home/test# pwd /home/test root@PC1:/home/test# ll -h total 24K drwxr-xr-x 4 root root 4.0K 2月 8 13:53 ./ drwxr-xr-x 8 root root 4.0K 2月 8 13:53 ../ -rw-r--r-- 1 root root 549 2月 7 16:54 a.txt -rw-r--r-- 1 root root 341 2月 7 16:56 gwas.bed drwxr-xr-x 2 root root 4.0K 2月 8 13:53 test1/ drwxr-xr-x 2 root root 4.0K 2月 8 13:53 test2/ root@PC1:/home/test# ls | sed "s#^#`pwd`/#" ## 利用ls列出, sed在行首添加路径 /home/test/a.txt /home/test/gwas.bed /home/test/test1 /home/test/test2