ls command: how can I get a recursive full-path li

2019-01-09 20:35发布

How can I get ls to spit out a flat list of recursive one-per-line paths?

For example, I just want a flat listing of files with their full paths:

/home/dreftymac/.
/home/dreftymac/foo.txt
/home/dreftymac/bar.txt
/home/dreftymac/stackoverflow
/home/dreftymac/stackoverflow/alpha.txt
/home/dreftymac/stackoverflow/bravo.txt
/home/dreftymac/stackoverflow/charlie.txt

ls -a1 almost does what I need, but I do not want path fragments, I want full paths.

23条回答
时光不老,我们不散
2楼-- · 2019-01-09 21:28

The easiest way for all you future people is simply:

du

This however, also shows the size of whats contained in each folder You can use awk to output only the folder name:

du | awk '{print $2}'

Edit- Sorry sorry, my bad. I thought it was only folders that were needed. Ill leave this here in case anyone in the future needs it anyways...

查看更多
Ridiculous、
3楼-- · 2019-01-09 21:31

ls -ld $(find .)

if you want to sort your output by modification time:

ls -ltd $(find .)

查看更多
三岁会撩人
4楼-- · 2019-01-09 21:32

Best command is: tree -fi

In order to use the files but not the links, you have to remove > from your output:

tree -fi |grep -v \>

If you want to know the nature of each file, (to read only ASCII files for example) with two whiles:

tree -fi | \
grep -v \> | \
while read first ; do 
    file ${first}
done | \
while read second; do 
    echo ${second} | grep ASCII
done
查看更多
Animai°情兽
5楼-- · 2019-01-09 21:34

Use find:

find .
find /home/dreftymac

If you want files only (omit directories, devices, etc):

find . -type f
find /home/dreftymac -type f
查看更多
来,给爷笑一个
6楼-- · 2019-01-09 21:35

With having the freedom of using all possible ls options:

find -type f | xargs ls -1

查看更多
登录 后发表回答