# Shell script I use to show most recent file changes

**URL:** https://forum.syncthing.net/t/shell-script-i-use-to-show-most-recent-file-changes/6873
**Category:** General
**Created:** [March 1, 2016, 4:02pm UTC](https://forum.syncthing.net/t/shell-script-i-use-to-show-most-recent-file-changes/6873 "2016-03-01T16:02:52Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![BTstink](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/b/6f9a4e/32.png) [@BTstink](https://forum.syncthing.net/u/BTstink)
#### Post date: [March 1, 2016, 4:02pm UTC](https://forum.syncthing.net/t/shell-script-i-use-to-show-most-recent-file-changes/6873/1 "2016-03-01T16:02:52Z")

</div>

Thought I’d share this shell script I use to show the most recent file changes / updates from the audit log file. It uses [jq](https://stedolan.github.io/jq/) to parse the json. I am using this on ubuntu boxes and Windows via cygwin.

Hope other folks find this useful. I have a ton of similar scripts I use in a management console I wrote.

```
#!/usr/bin/bash
filename=$(find /cygdrive/c/Syncthing/config/ -name "audit*" | sort -r | head -1);
printf "searching last 10,000 lines of: \n$filename \ntotal rows: " && wc -l < $filename
printf "\n\ndate,time,action,error,type,folder,item" | awk -F, '{for(i=1;i<=NF;i++){printf "%-15s", $i};printf "\n"}';
echo "===============,===============,===============,===============,===============,===============,===============" | awk -F, '{for(i=1;i<=NF;i++){printf "%-15s", $i};printf "\n"}';
#next line find the latest audit file and breaks down the json using jq. output is passed to awk to turn into 15 char columns
tail $filename -n 10000 -f | grep --line-buffered "ItemFinished" | jq -r --unbuffered '[.time[0:10],.time[11:19],.data.action,.data.error,.data.type,.data.folder,.data.item] | join(",")' | awk -F, '{for(i=1;i<=NF;i++){printf "%-15s", $i};printf "\n"}';
```

---

<div class="post-metadata">

### Author: ![BTstink](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/b/6f9a4e/32.png) [@BTstink](https://forum.syncthing.net/u/BTstink)
#### Post date: [March 1, 2016, 5:06pm UTC](https://forum.syncthing.net/t/shell-script-i-use-to-show-most-recent-file-changes/6873/2 "2016-03-01T17:06:13Z")

</div>

Output from this is as follows:

```
date time action error type folder item
=========================================================================================================
2016-03-01 07:39:18 update file my_sync tools\pull_stock_data\stocks_output_file.txt
2016-03-01 07:48:16 update file my_sync tools\pull_stock_data\stocks_output_file.txt
2016-03-01 07:51:20 update file datastore ds-mail\profiles\mmatt\ImapMail\stbeen. *****.com\INBOX.msf
2016-03-01 07:52:06 update file datastore ds-mail\profiles\mmatt\ImapMail\stbeen. *****.com\INBOX
2016-03-01 07:56:50 update file my_sync tools\pull_stock_data\stocks_output_file.txt
```
