1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/docs/parsers/stat.md

197 lines
5.7 KiB
Markdown
Raw Normal View History

[Home](https://kellyjonbrazil.github.io/jc/)
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.stat"></a>
2020-07-30 16:20:24 -07:00
2019-11-14 17:23:44 -08:00
# jc.parsers.stat
2022-01-25 17:07:47 -08:00
2022-03-04 13:27:39 -08:00
jc - JSON Convert `stat` command output parser
2019-11-14 17:23:44 -08:00
2022-01-19 17:30:14 -08:00
The `xxx_epoch` calculated timestamp fields are naive. (i.e. based on the
local time of the system the parser is run on)
2021-03-29 20:36:10 -07:00
2022-01-19 17:30:14 -08:00
The `xxx_epoch_utc` calculated timestamp fields are timezone-aware and are
only available if the timezone field is UTC.
2021-03-29 20:36:10 -07:00
2020-08-05 13:32:59 -07:00
Usage (cli):
2019-12-12 09:47:14 -08:00
2022-01-25 18:03:34 -08:00
$ stat * | jc --stat
2020-08-05 16:51:58 -07:00
2022-01-25 18:03:34 -08:00
or
2020-08-05 16:51:58 -07:00
2022-01-25 18:03:34 -08:00
$ jc stat *
2019-12-12 09:35:42 -08:00
2020-08-05 13:32:59 -07:00
Usage (module):
2022-01-25 18:03:34 -08:00
import jc
result = jc.parse('stat', stat_command_output)
2022-01-18 15:38:03 -08:00
2021-04-08 15:52:49 -07:00
Schema:
2022-01-25 18:03:34 -08:00
[
{
"file": string,
"link_to" string,
"size": integer,
"blocks": integer,
"io_blocks": integer,
"type": string,
"device": string,
"inode": integer,
"links": integer,
"access": string,
"flags": string,
"uid": integer,
"user": string,
"gid": integer,
"group": string,
"access_time": string, # - = null
"access_time_epoch": integer, # naive timestamp
"access_time_epoch_utc": integer, # timezone-aware timestamp
"modify_time": string, # - = null
"modify_time_epoch": integer, # naive timestamp
"modify_time_epoch_utc": integer, # timezone-aware timestamp
"change_time": string, # - = null
"change_time_epoch": integer, # naive timestamp
"change_time_epoch_utc": integer, # timezone-aware timestamp
"birth_time": string, # - = null
"birth_time_epoch": integer, # naive timestamp
"birth_time_epoch_utc": integer, # timezone-aware timestamp
"unix_device": integer,
"rdev": integer,
"block_size": integer,
"unix_flags": string
}
]
Examples:
$ stat /bin/* | jc --stat -p
[
{
"file": "/bin/bash",
"size": 1113504,
"blocks": 2176,
"io_blocks": 4096,
"type": "regular file",
"device": "802h/2050d",
"inode": 131099,
"links": 1,
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": 0,
"user": "root",
"gid": 0,
"group": "root",
"access_time": "2019-11-14 08:18:03.509681766 +0000",
"modify_time": "2019-06-06 22:28:15.000000000 +0000",
"change_time": "2019-08-12 17:21:29.521945390 +0000",
"birth_time": null,
"access_time_epoch": 1573748283,
"access_time_epoch_utc": 1573719483,
"modify_time_epoch": 1559885295,
"modify_time_epoch_utc": 1559860095,
"change_time_epoch": 1565655689,
"change_time_epoch_utc": 1565630489,
"birth_time_epoch": null,
"birth_time_epoch_utc": null
},
{
"file": "/bin/btrfs",
"size": 716464,
"blocks": 1400,
"io_blocks": 4096,
"type": "regular file",
"device": "802h/2050d",
"inode": 131100,
"links": 1,
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": 0,
"user": "root",
"gid": 0,
"group": "root",
"access_time": "2019-11-14 08:18:28.990834276 +0000",
"modify_time": "2018-03-12 23:04:27.000000000 +0000",
"change_time": "2019-08-12 17:21:29.545944399 +0000",
"birth_time": null,
"access_time_epoch": 1573748308,
"access_time_epoch_utc": 1573719508,
"modify_time_epoch": 1520921067,
"modify_time_epoch_utc": 1520895867,
"change_time_epoch": 1565655689,
"change_time_epoch_utc": 1565630489,
"birth_time_epoch": null,
"birth_time_epoch_utc": null
},
...
]
$ stat /bin/* | jc --stat -p -r
[
{
"file": "/bin/bash",
"size": "1113504",
"blocks": "2176",
"io_blocks": "4096",
"type": "regular file",
"device": "802h/2050d",
"inode": "131099",
"links": "1",
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": "0",
"user": "root",
"gid": "0",
"group": "root",
"access_time": "2019-11-14 08:18:03.509681766 +0000",
"modify_time": "2019-06-06 22:28:15.000000000 +0000",
"change_time": "2019-08-12 17:21:29.521945390 +0000",
"birth_time": null
},
{
"file": "/bin/btrfs",
"size": "716464",
"blocks": "1400",
"io_blocks": "4096",
"type": "regular file",
"device": "802h/2050d",
"inode": "131100",
"links": "1",
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": "0",
"user": "root",
"gid": "0",
"group": "root",
"access_time": "2019-11-14 08:18:28.990834276 +0000",
"modify_time": "2018-03-12 23:04:27.000000000 +0000",
"change_time": "2019-08-12 17:21:29.545944399 +0000",
"birth_time": null
},
...
]
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.stat.parse"></a>
2022-03-05 12:15:14 -08:00
### parse
2022-01-25 17:07:47 -08:00
2019-11-14 17:23:44 -08:00
```python
2022-01-25 17:07:47 -08:00
def parse(data, raw=False, quiet=False)
2019-11-14 17:23:44 -08:00
```
Main text parsing function
2022-01-25 18:03:34 -08:00
Parameters:
2019-11-14 17:23:44 -08:00
2022-01-25 18:03:34 -08:00
data: (string) text data to parse
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
2019-11-14 17:23:44 -08:00
2022-01-25 18:03:34 -08:00
Returns:
2019-11-14 17:23:44 -08:00
2022-01-25 18:03:34 -08:00
List of Dictionaries. Raw or processed structured data.
2019-11-14 17:23:44 -08:00
2022-01-25 19:18:54 -08:00
### Parser Information
Compatibility: linux, darwin, freebsd
2022-07-16 20:52:19 -07:00
Version 1.12 by Kelly Brazil (kellyjonbrazil@gmail.com)