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