взгляните на этот пример
class Person
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Phone { get; set; }
}
class Pet
{
public string Name { get; set; }
public Person Owner { get; set; }
}
public static void LeftOuterJoinExample()
{
Person magnus = new Person {ID = 1, FirstName = "Magnus", LastName = "Hedlund"};
Person terry = new Person {ID = 2, FirstName = "Terry", LastName = "Adams"};
Person charlotte = new Person {ID = 3, FirstName = "Charlotte", LastName = "Weiss"};
Person arlene = new Person {ID = 4, FirstName = "Arlene", LastName = "Huff"};
Pet barley = new Pet {Name = "Barley", Owner = terry};
Pet boots = new Pet {Name = "Boots", Owner = terry};
Pet whiskers = new Pet {Name = "Whiskers", Owner = charlotte};
Pet bluemoon = new Pet {Name = "Blue Moon", Owner = terry};
Pet daisy = new Pet {Name = "Daisy", Owner = magnus};
// Create two lists.
List people = new List {magnus, terry, charlotte, arlene};
List pets = new List {barley, boots, whiskers, bluemoon, daisy};
var query = from person in people
where person.ID == 4
join pet in pets on person equals pet.Owner into personpets
from petOrNull in personpets.DefaultIfEmpty()
select new { Person=person, Pet = petOrNull};
foreach (var v in query )
{
Console.WriteLine("{0,-15}{1}", v.Person.FirstName + ":", (v.Pet == null ? "Does not Exist" : v.Pet.Name));
}
}
// This code produces the following output:
//
// Magnus: Daisy
// Terry: Barley
// Terry: Boots
// Terry: Blue Moon
// Charlotte: Whiskers
// Arlene:
, теперь вы можете include elements from the left
, даже если этот элемент has no matches in the right
, в нашем случае мы восстановили Arlene
, даже если он не имеет соответствия в правой
здесь ссылка
If you really want to use ls
, then format its output using awk:
ls -R /path | awk '
/:$/&&f{s=$0;f=0}
/:$/&&!f{sub(/:$/,"");s=$0;f=1;next}
NF&&f{ print s"/"$0 }'
Я не знаю полного пути, но вы можете использовать -R
для рекурсии. В качестве альтернативы, если вы не зациклены на ls
, вы можете просто выполнить find *
.
Используйте find:
find .
find /home/dreftymac
Если вам нужны только файлы (без каталогов, устройств и т. Д.):
find . -type f
find /home/dreftymac -type f
Никаких внешних команд, кроме ls:
ls -R1 /path |
while read l; do case $l in *:) d=${l%:};; "") d=;; *) echo "$d/$l";; esac; done
Если каталог передается как относительный путь, и вам нужно будет преобразовать его в абсолютный путь перед вызовом find. В следующем примере каталог передается в качестве первого параметра сценария:
#!/bin/bash
# get absolute path
directory=`cd $1; pwd`
# print out list of files and directories
find $directory