class notes 5 23 - acavataio/ITC-136 GitHub Wiki

Scripting

type iamavar="look, I'm a variable!" - this command in terminal will create a variable called iamavar. echo $iamavar will then echo the assigned string.

This variable only exists in the current terminal as long as it's open. export $iamavar

df -h - will tell you how much space you have used and still available on each file system. du -h shows the disk usage of the current directory or a specific file.

df -h | grep "/dev/sda1" | awk '{print s5}' - this will globally find all files with the /dev/sda1 characters in them, and then print (in the terminal) the 5th column of the line with that character string from the file.

env | less - the environment command will show all global exported variables.

The shebang line = the first line of a bash script, it looked like #!/bin/bash in our new itc136 bash script file example.

chmod - change mode. We changed the mode of our itc136 file with chmod +x /usr/local/bin/itc136. The +x means we're making it executable, rather than just read/write.

echo $PATH and then change it with PATH=""

free -m - shows free memory and swap. free -mh | grep Mem: will show only free memory.

We make a variable out of the terminal command free -mh | grep Mem:. The command to set the variable is: memfree=$( free -mh | grep Mem: | awk '{print $7}' ). Then echo $memfree will display the free memory as if the whole terminal command line was typed.

netstat - shows all connections. netstat | grep tcp will show tcp connections only.