# Excercises Medium. Answers
## 2. Permissions*
#### 1. Find world executable folder
:::spoiler
:::success
find / -perm -o x -type d 2>/dev/null`
:::
#### 2. Find world writable files directories
:::spoiler
:::success
find / -writable -type d 2>/dev/null
find / -perm -222 -type d 2>/dev/null
find / -perm -o w -type d 2>/dev/null
:::
#### 3. Find world writable and executable folders
:::spoiler
:::success
find / \( -perm -o w -perm -o x \) -type d 2>/dev/null
:::
#### 4. List of last modified/opened/created files on the system
:::spoiler
:::success
Find / -mtime 5 -xdev > modified.txt
:::
#### 5. Find all suid files
:::spoiler
:::success
find / -perm -4000 (find all suid files)
:::
---
## 3. Text processing
#### 1. Display the names of all users with a last name "Jones"
>awkusers.txt
:::info
Mike Jones
John Smith
Kathy Jones
Jane Kennedy
Tim Scott
:::
:::spoiler
:::success
awk '$2 == "Jones" {print $0}' awkusers.txt
:::
#### 2. List commands for running processes with a word in their names "systemd"
:::spoiler
:::success
ps -ax | awk '/systemd/ {print $5}'
:::
#### 3. Display username, replace quotes, remove the table header
>csvex.txt
:::info
"name","username","phone","password hash"
"John Smith","jsmith","555-555-1212",5f4dcc3b5aa765d61d8327deb882cf99
"Jane Smith","jnsmith","555-555-1234",e10adc3949ba59abbe56e057f20f883e
"Bill Jones","bjones","555-555-6789",d8578edf8458ce06fbc5bb76a58c5ca4
:::
:::spoiler
:::success
cut -d',' -f1 csvex.txt | tr -d '"' | tail -n +2
:::
#### 4. Display phone number, cut quotes symbols
:::spoiler
:::success
cut -d',' -f3 csvex.txt | cut -c2-13 | tail -n +2
:::
---
## 4. Text processing*
#### 1. Display the ip address of interface from "ip a s eth0" command
:::spoiler
:::success
ip a s eth0 | awk -F '[\/ ]+' '/inet / {print $3}'
:::
#### 2. Replace the ip "10.0.4.35" to "10.0.4.27" from "ips.txt" file
>ips.txt
:::info
ip,OS
10.0.4.2,Windows 8
10.0.4.35,Ubuntu 16
10.0.4.107,macOS
10.0.4.145,macOS
:::
:::spoiler
:::success
sed 's/10\.0\.4\.35/10.0.4.27/g' ips.txt
:::
#### 3. Find user passwords using the corresponding hashes from the csv file "csvex.txt"
>passwords.txt
:::info
password,md5hash
123456,e10adc3949ba59abbe56e057f20f883e password,5f4dcc3b5aa765d61d8327deb882cf99 welcome,40be4e59b9a2a2b5dffb918c0e86b3d7 ninja,3899dcbab79f92af727c2190bbd8abc5 abc123,e99a18c428cb38d5f260853678922e03 123456789,25f9e794323b453885f5181f1b624d0b 12345678,25d55ad283aa400af464c76d713c07ad sunshine,0571749e2ac330a7455809c6b0e7af90 princess,8afa847f50a716e64932d995c8e7435a qwerty,d8578edf8458ce06fbc5bb76a58c5c
:::
:::spoiler
:::success
grep "$(awk -F "," '{print $4}' csvex.txt)" passwords.txt
:::
---
## 5. Text processing*
#### 1. Display the 7 most frequent IP addresses and print the number of their requests
>access.log
:::info
http://www.almhuette-raith.at/apache-log/access.log
:::
:::spoiler
:::success
cut -d' ' -f1 access log | sort | uniq -c | sort -rn
:::