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

199 lines
5.8 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-08-15 13:51:48 -07: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
2023-12-21 14:55:21 -08:00
Source: [`jc/parsers/stat.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/stat.py)
Dev v1.23.3 (#426) * make certificate search more robust to different line endings * use license_files instead of license_file which is deprecated * version bump * parsing extra options -e, -o, -p * fix for extra opts and different field length at option -[aeop] * test integration for extra opts -e -o -p * formatting and use ast.literal_eval instead of eval * doc update * doc update * Add a parser to parse mounted encrypted veracrypt volumes (fixes #403) * update compatibility warning message * netstat windows parser * tests * Windows route parser * tests * id should be a string * add veracrypt parser and docs * formatting * doc update * lsattr parser * Update test_lsattr.py * changed keys to lowercase * changed info * support missing data for stat * doc update * doc update * doc update * ensure compatibility warning prints even with no data * improve compatibility message * add support for dig +nsid option * New parser: srt (#415) * srt parser * changed the parser to support more complex cases * doc updates * Adding certificate request parser (#416) * Adding certificate request parser * Adding the CSR type for Windows-style CSR --------- Co-authored-by: Stg22 <stephane.for.test@gmail.com> * doc update * add csr tests * Last -x (#422) * Refactored the parser * last -x support * doc update * fix for ping on linux with missing hostname * allow less strict email decoding with a warning. * doc update * use explicit ascii decode with backslashreplace * doc update * use jc warning function instead of print for warning message * last -x shutdown fix (#423) * inject quiet setting into asn1crypto library * Parse appearance and modalias lines for mouse devices (fixes #419) (#425) The bluetoothctl device parser is implemented so that it aborts the parsing process immediately returning what it has collected so far. This is because the parser should work in hydrid way to support outputs comming from bluetoothctl devices and bluetoothctl info calls. * doc update * doc update --------- Co-authored-by: gerd <gerd.augstein@gmail.com> Co-authored-by: Jake Ob <iakopap@gmail.com> Co-authored-by: Mevaser <mevaser.rotner@gmail.com> Co-authored-by: M.R <69431152+YeahItsMeAgain@users.noreply.github.com> Co-authored-by: Stg22 <46686290+Stg22@users.noreply.github.com> Co-authored-by: Stg22 <stephane.for.test@gmail.com>
2023-06-22 01:48:23 +03:00
Version 1.13 by Kelly Brazil (kellyjonbrazil@gmail.com)