Linux File Info - Linux Entity Inspector
This crate is for gathering useful infos about linux entities(files, folders or symlinks) with developer friendly way.
This crate is parallel crate of windows-file-info crate, which developed for handling same tasks on windows and developed by me. If you need an entity inspector for Windows, check out that crate.
It basically makes "sudo ls -l" calls with different ways and parses output nicely.
If you like that crate, give a star that liblary on github repo
It primarily uses that struct about all entities:
#[derive(Debug)]
pub struct LinuxEntity {
pub entity_name: String, pub entity_type: String, pub owner: String, pub group: String, pub hardlink: u8,
pub permission: u16, pub size: i32, pub last_change_date: String, }
sample uses:
Disclaimer: You can give absolute paths to all other_folder_info()
and file_info()
and other functions.
use linux_file_info::*;
fn main(){
let current_folder = current_folder_info();
let other_folder = other_folder_info("../hello-everyone");
let check_cargo_file = file_info("/etc/nftables.conf");
let cargo_toml_is_file = is_file("Cargo.toml");
let src_is_folder = is_folder("src");
let cargo_lock_is_symlink = is_symlink("Cargo.lock");
let sfsdfsfds_is_exist = is_exist("sfsdfsfds");
let who_am_i = get_current_user();
}
Warning: current_folder_info()
function works based on your current directory. If you run this on root directory of your computer, you'll take this kind of response:
[
LinuxEntity {
entity_name: "Docker",
entity_type: "folder",
owner: "root",
group: "root",
hardlink: 3,
permission: 755,
size: 4096,
last_change_date: "Jul 8 2023",
},
LinuxEntity {
entity_name: "bin",
entity_type: "symlink",
owner: "root",
group: "root",
hardlink: 1,
permission: 777,
size: 7,
last_change_date: "May 2 2023",
},
LinuxEntity {
entity_name: "boot",
entity_type: "folder",
owner: "root",
group: "root",
hardlink: 2,
permission: 755,
size: 4096,
last_change_date: "Apr 18 2022",
},
LinuxEntity {
entity_name: "dev",
entity_type: "folder",
owner: "root",
group: "root",
hardlink: 16,
permission: 755,
size: 3560,
last_change_date: "Jan 13 15:33",
},
LinuxEntity {
entity_name: "etc",
entity_type: "folder",
owner: "root",
group: "root",
hardlink: 81,
permission: 755,
size: 4096,
last_change_date: "Jan 13 15:33",
},
LinuxEntity {
entity_name: "home",
entity_type: "folder",
owner: "root",
group: "root",
hardlink: 3,
permission: 755,
size: 4096,
last_change_date: "Jul 8 2023",
},
]
Another Example, if you run other_folder_info()
function on your computer's main directory with "./etc/ssh" parameter you'll take that kind of answer:
[
LinuxEntity {
entity_name: "ssh_config",
entity_type: "file",
owner: "root",
group: "root",
hardlink: 1,
permission: 644,
size: 1650,
last_change_date: "Nov 23 2022",
},
LinuxEntity {
entity_name: "ssh_config.d",
entity_type: "folder",
owner: "root",
group: "root",
hardlink: 2,
permission: 755,
size: 4096,
last_change_date: "Nov 23 2022",
},
]
You have 2 options for giving absolute and more reliable paths:
1 - You can give absolute path on the parameter like this: other_folder_info("/sys/dev/block")
, file_info("/sys/dev/block/1:0")
2 - You can use that functions with defining some kind of bash variables which equals some paths(like your current user's home folder or /root folder) and giving other paths depending on that variable.