Commit cc2a5e7

bryfry <bryon.fryer@gmail.com>
2017-01-12 16:28:16
unixy adds
1 parent 8a898ce
Changed files (4)
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`                   | &#10004; | &#10004; | &#10004; |
+| directory move     | `mv foo bar`                  |          | &#10004; | &#10004; |
+| file creation      | `touch foo/foo`               |          | &#10004; | &#10004; |
+| list directory     | `ls foo`                      | &#10004; |          |          |
+| change directory   | `cd foo`                      |          |          |          |
+| file test          | `-f foo`                      |          |          |          |
+| file move/rename   | `mv foo foo_mvd`              |          | &#10004; | &#10004; |
+| permissions change | `chmod/chown <some_perm> foo` |          | &#10004; |          |
+| file copy          | `mv foo_mvd foo`              |          | &#10004; | &#10004; |
+| file edit          | `vim foo`                     |          | &#10004; | &#10004; |
+| file edit          | `emacs foo`                   | &#10004; | &#10004; | &#10004; |
+| 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`                    | &#10004;  | &#10004;  | &#10004;  |
+| rename             | `mv bar bar`                   |           |           |           |
+| permissions change | `chmod <some_perm> bar`        |           | &#10004;  |           |
+| copy               | `cp bar baz`                   | &#10004;  |           |           |
+| copy overwrite     | `cp bar baz`                   |           | &#10004;  | &#10004;  |
+| append             | `cat >> bar`                   |           | &#10004;  | &#10004;  |
+| overwrite          | `cat > bar`                    |           | &#10004;  | &#10004;  |
+| truncate           | `cp /dev/null bar`             |           | &#10004;  | &#10004;  |
+| list file          | `ls bar`                       |           |           |           |
+| edit               | `vim/emacs/xemacs/joe/jed bar` | &#10004;  | &#10004;  | &#10004;  |
+| edit               | `ed/nvi/vi/nano/pico bar`      | &#10004;1 | &#10004;1 | &#10004;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
+```
+
+
+