pipping -tryhackme

 

🇹🇷 Piping Nedir?

Piping, komut satırı ortamlarında kullanılan bir tekniktir ve bir komutun çıktısının başka bir komutun girdisi olarak kullanılmasını sağlar. Bu, verinin bir komuttan diğerine akmasını sağlayan bir işlem sırası oluşturur. PowerShell'de, | (pipe) sembolü ile temsil edilir. Bu teknik, yalnızca Windows komut satırında değil, Unix tabanlı kabuklarda da yaygın olarak kullanılır.

PowerShell'de piping daha güçlüdür çünkü yalnızca metin değil, nesneler aktarılır. Bu nesneler, sadece veriyi taşımakla kalmaz, aynı zamanda veriyi tanımlayan ve onunla etkileşime giren özellikler ve yöntemler de taşır.

Örneğin, bir dizindeki dosyaların listesini alıp, sonra bu dosyaları boyutlarına göre sıralamak isterseniz, PowerShell'de şu komutu kullanabilirsiniz:

powershell
PS C:\Users\captain\Documents\captain-cabin> Get-ChildItem | Sort-Object Length

Bu komutta:

  • Get-ChildItem komutu, dosyaları nesneler olarak alır.

  • Pipe (|) sembolü, bu dosya nesnelerini Sort-Object komutuna gönderir, burada dosyalar Length (boyut) özelliğine göre sıralanır.

Burada nesne tabanlı bir yaklaşım kullanıldığından, çok daha ayrıntılı ve esnek komut sıralamaları yapılabilir.


🇬🇧 What is Piping?

Piping is a technique used in command-line environments that allows the output of one command to be used as the input for another. This creates a sequence of operations where the data flows from one command to the next. Represented by the | (pipe) symbol, piping is widely used in both the Windows Command Line Interface (CLI) and Unix-based shells.

In PowerShell, piping is even more powerful because it passes objects instead of just text. These objects not only carry the data but also the properties and methods that describe and interact with the data.

For instance, if you want to get a list of files in a directory and then sort them by size, you could use the following command:

powershell
PS C:\Users\captain\Documents\captain-cabin> Get-ChildItem | Sort-Object Length

In this command:

  • Get-ChildItem retrieves the files as objects.

  • The pipe (|) sends these file objects to Sort-Object, which then sorts them by their Length property.

By using an object-based approach, this enables more detailed and flexible command sequences.


🇹🇷 Nesne Tabanlı Piping'in Avantajları

PowerShell’deki nesne tabanlı piping, daha fazla veri işleme ve analiz yeteneği sağlar. Bir komutun çıktısı bir nesne olduğunda, bu nesne sadece veriyi taşımaz, aynı zamanda nesnenin özellikleri ve metodlarıyla daha derin etkileşimler gerçekleştirebilirsiniz.

Örneğin, dizindeki yalnızca .txt uzantılı dosyaları listelemek için:

powershell
PS C:\Users\captain\Documents\captain-cabin> Get-ChildItem | Where-Object -Property "Extension" -eq ".txt"

Burada Where-Object komutu, dosyaları Extension özelliği üzerinden filtreler ve yalnızca .txt uzantısına sahip olanları listeler.


🇬🇧 Advantages of Object-Based Piping

The object-based piping in PowerShell allows for more advanced data manipulation and analysis. When a command's output is an object, it not only carries the data but also allows deeper interactions with the object's properties and methods.

For example, to list only .txt files in a directory:

powershell
PS C:\Users\captain\Documents\captain-cabin> Get-ChildItem | Where-Object -Property "Extension" -eq ".txt"

Here, the Where-Object cmdlet filters the files based on their Extension property, ensuring only files with a .txt extension are listed.


🇹🇷 Farklı Filtreleme Yöntemleri

PowerShell, nesneleri filtrelemek için bir dizi cmdlet sağlar. Bunlar:

  • Where-Object: Belirtilen bir özelliğe göre nesneleri filtreler.

  • Select-Object: Nesnelerden belirli özellikleri seçer ya da döndürülecek nesne sayısını sınırlar.

Örneğin, dizindeki sadece "ship" ile başlayan dosyaları listelemek için:

powershell
PS C:\Users\captain\Documents\captain-cabin> Get-ChildItem | Where-Object -Property "Name" -like "ship*"

Select-Object komutunu, çıktı üzerinde daha fazla inceleme yapmak için kullanabilirsiniz:

powershell
PS C:\Users\captain\Documents\captain-cabin> Get-ChildItem | Select-Object Name, Length

🇬🇧 Different Filtering Methods

PowerShell provides a range of cmdlets for filtering objects. These include:

  • Where-Object: Filters objects based on a specified property.

  • Select-Object: Selects specific properties from objects or limits the number of objects returned.

For instance, to list only files starting with "ship" in the name:

powershell
PS C:\Users\captain\Documents\captain-cabin> Get-ChildItem | Where-Object -Property "Name" -like "ship*"

You can use Select-Object to refine the output and display specific details:

powershell
PS C:\Users\captain\Documents\captain-cabin> Get-ChildItem | Select-Object Name, Length

🇹🇷 Pipelining'in Genişletilmesi

PowerShell'de pipelining sadece iki cmdlet arasında veri iletmekle sınırlı değildir. Daha fazla komut eklenerek, daha karmaşık ve özelleştirilmiş veri işleme sıralamaları oluşturulabilir.

Örneğin, C:\Users\captain\Documents\captain-cabin dizinindeki en büyük dosyayı listelemek için şu şekilde bir pipeline oluşturabilirsiniz:

powershell
Get-ChildItem | Sort-Object Length -Descending | Select-Object -First 1

🇬🇧 Extending Pipelining

In PowerShell, pipelining isn't limited to just passing data between two cmdlets. It can be extended by adding more commands to create more complex and customized data processing sequences.

For example, to list the largest file in the C:\Users\captain\Documents\captain-cabin directory, you can build a pipeline like this:

powershell
Get-ChildItem | Sort-Object Length -Descending | Select-Object -First 1

🇹🇷 Select-String Cmdlet'i ve Kullanımı

Son olarak, Select-String komutunu kullanarak, dosyalar içindeki metin desenlerini arayabilirsiniz. Bu, Unix tabanlı sistemlerdeki grep komutuna veya Windows Komut Satırı’ndaki findstr komutuna benzer şekilde çalışır.

powershell
PS C:\Users\captain\Documents\captain-cabin> Select-String -Path ".\captain-hat.txt" -Pattern "hat"

Bu komut, captain-hat.txt dosyasında "hat" desenini arar ve sonucu döker. Select-String komutu, regular expressions (regex) kullanımını da tam olarak destekler, böylece daha karmaşık desen eşleştirmeleri yapılabilir.


🇬🇧 Select-String Cmdlet and Usage

Finally, using the Select-String cmdlet, you can search for text patterns within files. This works similarly to the grep command in Unix-based systems or the findstr command in Windows Command Prompt.

powershell
PS C:\Users\captain\Documents\captain-cabin> Select-String -Path ".\captain-hat.txt" -Pattern "hat"

This command searches the captain-hat.txt file for the "hat" pattern and returns the result. The Select-String cmdlet fully supports the use of regular expressions (regex), making it powerful for more complex pattern matching.