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

 

相关文章:

  • 2021-08-07
  • 2021-11-22
  • 2022-12-23
  • 2021-11-23
  • 2021-12-10
  • 2021-11-26
  • 2022-12-23
猜你喜欢
  • 2021-12-31
  • 2022-12-23
  • 2021-11-20
  • 2021-08-21
  • 2022-12-23
  • 2022-01-30
  • 2022-02-13
相关资源
相似解决方案