Question

I occasionally do "ls -laR /" on my system and offsite backup the results. If disaster strikes, I'll at least know which files I've lost.

I recently started sshfs mounting remote systems, yielding two problems:

  • "ls -laR" on sshfs mounted systems is painfully slow

  • I don't need the "ls -laR" results of remote filesystems, at least not locally.

What's the ls equivalent of find's "-xdev" option or du's "-x" option?

In case there's a better way to do it, my goal is to efficiently get a list of all files on my hard drive with size, owner, mod time, etc. In other words, all the info "ls -l" would normally provide.

I've considered: "find / -xdev | xargs ls -la", but I sense that would be less efficient.

Was it helpful?

Solution 2

There is no such option for ls itself, but you can do

find / -xdev -ls

or if that is not sufficiently detailed, look into the possibilities offered by the -printf option.

OTHER TIPS

Use the -ls action with find(1), which prints out the file stats like ls -dils would:

find / -xdev -ls

If the ls -dils format isn't your thing, you can also use the -exec ... + action, which works similarly to xargs(1) but is more efficient:

find / -xdev -exec ls -l '{}' +

The + instructs find to pass as many filenames as it can into the subprocess, so it only spawns as few subprocesses as necessary (which is determined by the maximum size of command line arguments on your OS). If you use a ; instead of +, then find creates one process per file, which is very slow when you have a lot of files, so that's not recommended.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top