Class Activities: Week 6.1,6.2,6.3
- Create a research directory and copy all system logs along with the
shadow
,passwd
, andhosts
files in one long command.
sudo cp -r /var/log* ~/research; sudo cp /etc/shadow; sudo cp /etc/passwd ~/research/passwd; sudo cp /etc/hosts ~/research/hosts
do I need this many repetitive sudo
's?
- Create a list of all executable files in the home folder and save it to a text file in the research folder with one long command.
sudo find ~ -executable -type f ~/research/executable_files.txt
- Create a list of the 10 most active processes. The list should only contain the
USER
,PID
,%CPU
,%MEM
andCOMMAND
. Save this list to a text file in your research directory with one long command.
ps -eo user,pid,%mem,%cpu,comm --sort=%cpu | tail
question: how do I reverse order something I sort?
ps -eo user,pid,%mem,%cpu,comm --sort=%cpu | head -10
Bonus
- Create a list of home folders along with user info from the
passwd
file. Only add the user info to your list if theUID
is greater than 1000.
awk -F : '$3 >= "1000" {print "User: " $1, "UID: " $3, "HomeDir: " $6 }' /etc/passwd
- Create a bash script of today's date, current logged on users, and IP address of host machine:
#!/bin/bash
IPADDR=$(ip addr show | grep inet | head -1)
DNS=$(nmcli dev show | grep DNS)
cat << EOF
"Hello $USER! Today's date is $(date)."
"The machine you are using is $(uname) at... $IPADDR for $HOSTNAME."
"The current users logged on are: $(who)"
EOF