Commit cc2a5e7
Changed files (4)
unix
meta
unix/commands/ls.md
@@ -0,0 +1,34 @@
+---
+date: "2017-01-12"
+draft: false
+title: "ls"
+
+---
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+### Displaying MAC time using LS
+
+| | Linux | OpenBSD | Solaris |
+|-------|-----------------------|-------------|------------|
+| mtime | `ls -latr –full-time` | `ls -latTr` | `ls -latr` |
+| atime | `ls -laur –full-time` | `ls -lauTr` | `ls -laur` |
+| ctime | `ls -lacr –full-time` | `ls -lacTr` | `ls -lac` |
+
+[Source](http://blog.granneman.com/2008/04/20/what-actions-change-mac-times-on-a-unix-box/)
+See also:
+
+* [meta - MAC times]({{< relref "unix/meta/mactimes.md" >}})
+* [stat]({{< relref "unix/commands/stat.md" >}})
unix/commands/stat.md
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+## See also
+
+* [meta - MAC times]({{< relref "unix/meta/mactimes.md" >}})
+* [ls]({{< relref "unix/commands/ls.md" >}})
unix/meta/mactimes.md
@@ -0,0 +1,48 @@
+---
+date: "2017-01-12"
+draft: false
+title: "MAC times"
+
+---
+
+
+### How common commands change MAC times for a directory (`foo`):
+| Action | Example Command | atime | ctime | mtime |
+|--------------------|-------------------------------|----------|----------|----------|
+| creation | `mkdir foo` | ✔ | ✔ | ✔ |
+| directory move | `mv foo bar` | | ✔ | ✔ |
+| file creation | `touch foo/foo` | | ✔ | ✔ |
+| list directory | `ls foo` | ✔ | | |
+| change directory | `cd foo` | | | |
+| file test | `-f foo` | | | |
+| file move/rename | `mv foo foo_mvd` | | ✔ | ✔ |
+| permissions change | `chmod/chown <some_perm> foo` | | ✔ | |
+| file copy | `mv foo_mvd foo` | | ✔ | ✔ |
+| file edit | `vim foo` | | ✔ | ✔ |
+| file edit | `emacs foo` | ✔ | ✔ | ✔ |
+| file edit | `vi/nano foo` | | | |
+
+[Source](http://blog.granneman.com/2008/04/20/what-actions-change-mac-times-on-a-unix-box/)
+
+### How common commands change MAC times for a file (bar)
+| Action | Example Command | atime | ctime | mtime |
+|--------------------|--------------------------------|-----------|-----------|-----------|
+| creation | `touch bar` | ✔ | ✔ | ✔ |
+| rename | `mv bar bar` | | | |
+| permissions change | `chmod <some_perm> bar` | | ✔ | |
+| copy | `cp bar baz` | ✔ | | |
+| copy overwrite | `cp bar baz` | | ✔ | ✔ |
+| append | `cat >> bar` | | ✔ | ✔ |
+| overwrite | `cat > bar` | | ✔ | ✔ |
+| truncate | `cp /dev/null bar` | | ✔ | ✔ |
+| list file | `ls bar` | | | |
+| edit | `vim/emacs/xemacs/joe/jed bar` | ✔ | ✔ | ✔ |
+| edit | `ed/nvi/vi/nano/pico bar` | ✔1 | ✔1 | ✔1 |
+
+1 - all times changed, but atime is slightly older than mtime and ctime.
+[Source](http://blog.granneman.com/2008/04/20/what-actions-change-mac-times-on-a-unix-box/)
+
+## See also
+
+* [ls]({{< relref "unix/commands/ls.md" >}})
+* [stat]({{< relref "unix/commands/stat.md" >}})
unix/meta/trinkets.md
@@ -0,0 +1,85 @@
+---
+date: "2017-01-12"
+draft: false
+title: "Unix Trinkets"
+
+---
+
+# Generic
+
+### Replace match with new line in `sed`
+
+```bash
+# Yep, that is a hard return followed by the end of the expression
+sed 's/needle/\
+/g'
+
+cat test.sh | sed 's/BREAK/\
+/g' > test.sh
+```
+
+### Removing control and color characters from a file
+
+* `cat file.txt | perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g' | col -b > survey-processed.txt`
+
+### Get process information related to a specific file
+
+* `ps -o pid,args -p "$(fuser /home/bubba 2>/dev/null)"`
+* `ps -o pid,args -p "$(fuser /usr/bin/slogin 2>/dev/null)"`
+
+# Solaris
+
+### PIDS listening on PORT
+
+On solaris you can display the PIDS listening on PORT with the below command.
+Found on [stack overflow](http://stackoverflow.com/questions/13246309/how-to-get-process-id-attached-with-particular-port-in-sunos).
+
+Replace `PORTNUMBER` with a port number you wish to research
+
+* `pfiles /proc/* 2>/dev/null | nawk '/^[0-9]*:/ { pid=$0 }/port: PORTNUMBER$/ { printf("%s %s\n",pid,$0);}'`
+
+```bash
+# This gives the same information as above but shows the network connection status
+# for every process on the box
+# Shows
+# PID: /path/to/executable
+# sockname:...
+# sockname:...
+for p in $(cd /proc;
+ find * -type d -prune | sort -n );
+ do pf_out=$(pfiles $p 2> /dev/null);
+ echo -e "$(echo "$pf_out" | head -n 1)\n$(echo "$pf_out" | grep port)";
+done
+```
+
+### File Access Times
+
+* `truss -v lstat -t lstat ls /etc/passwd`
+
+### `ptree` with socket table
+
+```bash
+IFS=$'\n'; for line in $(ptree);
+ do p=$(echo $line | awk '{print $1}');
+ ports=$(pfiles $p 2> /dev/null | grep port);
+ printf "%s\n%s\n" "$line" "$ports";
+done
+```
+
+# Linux
+
+### Getting True Executable Paths
+
+```bash
+# Made for Linux
+# Assumes a PID is in the second column of the PS output
+# Uses --forest instead of -H for pretty output
+IFS=$'\n'; for line in $(ps -ef --forest);
+ do pid=$(echo $line | awk '{print $2}');
+ exec_path=$(ls -l /proc/$pid/exe 2> /dev/null | awk -F "-> " '{print $2}');
+ printf "%-100s%-30s\n" "$line" "'$exec_path'";
+done
+```
+
+
+