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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM