johnlemon
johnlemon

Reputation: 21449

Bash join ls output

How can I join 2 ls results ? - I need this because the files are in 2 different directories and I need to sort them in different ways.

Anyway for the output I need a normal listing with both results.

Upvotes: 4

Views: 1780

Answers (4)

Vytenis Bivainis
Vytenis Bivainis

Reputation: 2376

Perhaps find is more useful here because of that "directory:" format that ls uses when it's given more than one directory as an argument.

find /etc/dpkg/ /etc/apt -mindepth 1 -maxdepth 1 | sort

You can customize output if your find supports printf, for example

find /etc/dpkg/ /etc/apt -mindepth 1 -maxdepth 1 -printf "%f\n" | sort

Upvotes: 0

Dennis Williamson
Dennis Williamson

Reputation: 359965

No need to run ls twice, just put multiple file specifications as arguments.

ls /path/to/first_file_spec* /different_path/to/second_file_spec*

Upvotes: 6

icyrock.com
icyrock.com

Reputation: 28598

This should do it:

{ ls folder1 && ls folder2; }

Got this from:

Try this example:

{ ls /etc/fonts && ls /etc/init; }|while read i; do echo $i; done

(hope you have these folders - replace if you don't).

Upvotes: 1

Thevs
Thevs

Reputation: 3253

(ls <first dir>; ls <second dir>) | sort ...

Upvotes: 2

Related Questions