Читать книгу Kali Linux Penetration Testing Bible - Gus Khawaja - Страница 40

Managing Text Files in Kali Linux

Оглавление

Knowing how to handle files in Kali Linux is something that you'll often encounter during your engagements. In this section, you will learn about the most common commands that you can use to get the job done.

There are many ways to display a text file quickly on the terminal window. 90 percent of the time, I use the cat command for this purpose. What if you want to display a large text file (e.g., a password's dictionary file)? Then you have three choices: the head , tail , and more and less commands. It is important to note that you can use the grep command to filter out the results that you're looking for. For example, to identify the word gus123 inside the rockyou.txt dictionary file, you can do the following:

root@kali:/usr/share/wordlists# cat rockyou.txt | grep gus123 gus123 angus123 gus12345 […]

The head command will display 10 lines in a text file starting from the top, and you can specify how many lines you want to display by adding the ‐n option:

$head -n [i] [file name] root@kali:/usr/share/wordlists# head -n 7 rockyou.txt 123456 12345 123456789 password iloveyou princess 1234567

The tail command will display the last 10 lines in a file, and you can specify the number of lines as well using the ‐n switch:

$tail -n [i] [file name] root@kali:/usr/share/wordlists# tail -n 5 rockyou.txt xCvBnM, ie168 abygurl69 a6_123 *7!Vamos!

To browse a large file, use the more command. You need to press Enter or the spacebar on your keyboard to step forward. Pressing the B key will let you go backward. Finally, to search for text, press the / (forward slash) and the Q key to quit:

$more [file name]

less is like the more command; it allows you to view the contents of a file and navigate inside it as well. The main difference between more and less is that the less command is faster than the more command because it does not load the entire file at once, and it allows you to navigate inside the file using the Page Up/Down keys as well:

$less [file name]

To sort a text file, simply use the sort command:

$sort [file name]> [sorted file name] root@kali:~/temp# cat file1.txt 5 6 4 root@kali:~/temp# sort file1.txt>file1_sorted.txt root@kali:~/temp# cat file1_sorted.txt 4 5 6

To remove duplicates in a text file, you must use the uniq command:

$uniq [file name]> [no duplicates file name] root@kali:~/temp# cat file2.txt 5 6 4 4 5 5 5 root@kali:~/temp# uniq file2.txt> file2_uniq.txt root@kali:~/temp# cat file2_uniq.txt 5 6 4 5

Later in this book, you will learn how to use the sort and uniq commands together to create a custom passwords dictionary file.

Kali Linux Penetration Testing Bible

Подняться наверх