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
复制代码

 

posted @   小鲨鱼2018  阅读(737)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示