ls
List contents of a directory in ruby
linux manual
Basic Usage
require 'kanrisuru'
host = Kanrisuru::Remote::Host.new(host: '127.0.1.1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
result = host.ls(path: '/home')
result.success?
true
result[0].path
"ubuntu"
Parameters
Field |
Type |
Description |
all |
boolean
|
Do not ignore entries starting with "." |
path |
string
|
List information about FILES at path location |
id |
boolean
|
Use UID and GID instead of user and group names |
Result
Returns an array of FileInfo
structs.
FileInfo Fields
Field |
Type |
Description |
inode |
integer
|
Unique inode value assigned to file |
mode |
Kanrisuru::Mode
|
An instance of the mode class for querying the mode of a file |
hard_links |
integer
|
The number of hard links pointing to the inode |
owner |
string
|
The owner of file or directory. Can either be a string or integer depending on id param passed |
group |
string
|
The group the file or directory belongs to. Can either be a string or integer depending on id param passed |
fsize |
integer
|
Size of the file in bytes |
date |
DateTime
|
An instance of the DateTime class. Indicates last update time |
path |
string
|
Location of the file |
Return Example
host.ls(path: '/home')[0]
<Struct:Kanrisuru::Core::Path::FileInfo:0x000006b8
fsize = 4096,
date = <DateTime: 2021-07-21T19:55:00+00:00 ((2459417j,71700s,0n),+0s,2299161j)>,
group = "ubuntu",
inode = 322561,
memory_blocks = 3,
mode = <Kanrisuru::Mode:0x920 @numeric=775 @symbolic=drwxrwxr-x>,
owner = "ubuntu",
path = "build",
type = "directory"
>
Exit Status
Code |
Description |
0 |
Success |
1 |
Minor problems (e.g., cannot access subdirectory) |
2 |
Serious trouble (e.g., cannot access command-line argument) |
Additional Examples
result = host.ls(path: '/etc/', id: true)
result.map(&:path)
[
"NetworkManager",
"PackageKit",
"X11",
"adduser.conf",
...
]
Tested On
- Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES