linux中列出当前文件及目录的绝对路径

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

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。