virt-ls(1)
β¨ NAME β¨
OK so picture this: the manual page is virt-ls(1), and honestly it's the β¨iconicβ¨ little sibling of ls that lives rent-free inside your virtual machines. virt-ls β List files in a virtual machine. That's the whole vibe, bestie. π
π«Ά SYNOPSIS π«Ά
Like, here's the modern way to call her:
virt-ls [--options] -d domname directory [directory ...]
virt-ls [--options] -a disk.img [-a disk.img ...] directory [directory ...]
And the old style (she's vintage, she still works):
virt-ls [--options] domname directory
virt-ls [--options] disk.img [disk.img ...] directory
πΈ DESCRIPTION πΈ
So virt-ls lists filenames, file sizes, checksums, extended attributes and more β straight out of a virtual machine or a disk image. No booting required, no cap. π₯
You can hand her multiple directory names and she'll just concatenate the output from each one. Casual.
Need to list dirs from a libvirt guest? Use the -d option and tell her the name of the guest. Working with a disk image instead? That's the -a option, babe.
virt-ls can do many simple file listings. But for the more complicated cases β the messy, main-character-complex ones β you may need to use guestfish(1), or honestly just write a program directly against the guestfs(3) API. She's not gonna do everything for you. π
π¦ EXAMPLES π¦
Get a list of all files and directories in a virtual machine:
virt-ls -R -d guest /
List all setuid or setgid programs in a Linux virtual machine:
virt-ls -lR -d guest / | grep '^- [42]'
List all public-writable directories in a Linux virtual machine:
virt-ls -lR -d guest / | grep '^d ...7'
List all Unix domain sockets in a Linux virtual machine:
virt-ls -lR -d guest / | grep '^s'
List all regular files with filenames ending in β.pngβ:
virt-ls -lR -d guest / | grep -i '^-.*\.png$'
To display files larger than 10MB in home directories:
virt-ls -lR -d guest /home | awk '$3 > 10*1024*1024'
Find everything modified in the last 7 days:
virt-ls -lR -d guest --time-days / | awk '$6 <= 7'
Find regular files modified in the last 24 hours:
virt-ls -lR -d guest --time-days / | grep '^-' | awk '$6 < 1'
π§ DIFFERENCES IN SNAPSHOTS AND BACKING FILES π§
Okay so yes, technically you can use virt-ls to look for differences, but listen β since libguestfs β₯ 1.26 there's a whole new tool for that, it's called virt-diff(1). Use that one for diffing, iykyk. π
π OUTPUT MODES π
virt-ls has four output modes, and they're controlled by different combos of the -l and -R options. Four whole personalities, bestie. Let's meet them. π
β SIMPLE LISTING β
A simple listing is like the ordinary ls(1) command. Nothing fancy, just vibes:
$ virt-ls -d guest /
bin
boot
[etc.]
π LONG LISTING π
With the -l (--long) option, the output is like the ls -l command β or, more specifically, like the guestfs_ll function. Look at her go:
$ virt-ls -l -d guest /
total 204
dr-xr-xr-x. 2 root root 4096 2009-08-25 19:06 bin
dr-xr-xr-x. 5 root root 3072 2009-08-25 19:06 boot
[etc.]
β οΈ Note that while this is useful for displaying a directory, do not try parsing this output in another program. It's giving "look, don't touch." Use "RECURSIVE LONG LISTING" instead, bestie. π
π RECURSIVE LISTING π
With the -R (--recursive) option, virt-ls lists the names of files and directories recursively:
$ virt-ls -R -d guest /tmp
foo
foo/bar
[etc.]
To generate this output, virt-ls runs the guestfs_find0 function and converts \0 characters to \n. That's the whole trick, no cap. β¨
π₯ RECURSIVE LONG LISTING π₯
Using the -lR options together changes the output to display directories recursively, with file stats, and optionally other features such as checksums and extended attributes. This is the main character mode, fr fr.
Most of the interesting features of virt-ls are only available when using -lR mode. Obsessed. π
The fields are normally space-separated. Filenames are not quoted, so you cannot use the output in another program β because filenames can contain spaces and other unsafe characters. And like, if the guest was untrusted and someone knew you were using virt-ls to analyze the guest, they could play tricks on you by creating filenames with embedded newline characters. π So to safely parse the output in another program, use the --csv (Comma-Separated Values) option.
π Also note that this output format is completely unrelated to the ls -lR command. Do not confuse them, she is her own woman.
$ virt-ls -lR -d guest /bin
d 0555 4096 /bin
- 0755 123 /bin/alsaunmute
- 0755 28328 /bin/arch
l 0777 4 /bin/awk -> gawk
- 0755 27216 /bin/basename
- 0755 943360 /bin/bash
[etc.]
These basic fields are always shown:
typeβ The file type, one of:-(regular file),d(directory),c(character device),b(block device),p(named pipe),l(symbolic link),s(socket) oru(unknown).permissionsβ The Unix permissions, displayed as a 4 digit octal number.sizeβ The size of the file. This is shown in bytes unless-hor--human-readableoption is given, in which case this is shown as a human-readable number.pathβ The full path of the file or directory.linkβ For symbolic links only, the link target.
In -lR mode, additional command line options enable the display of more fields.
With the --uids flag, these additional fields are displayed before the path:
uidgidβ The UID and GID of the owner of the file (displayed numerically). Note these only make sense in the context of a Unix-like guest. π
With the --times flag, these additional fields are displayed:
atimeβ The time of last access.mtimeβ The time of last modification.ctimeβ The time of last status change.
The time fields are displayed as string dates and times, unless one of the --time-t, --time-relative or --time-days flags is given. π°οΈ
With the --extra-stats flag, these additional fields are displayed:
deviceβ The device containing the file (displayed as major:minor). This may not match devices as known to the guest.inodeβ The inode number.nlinkβ The number of hard links.rdevβ For block and char special files, the device (displayed as major:minor).blocksβ The number of 512 byte blocks allocated to the file.
With the --checksum flag, the checksum of the file contents is shown (only for regular files). Computing file checksums can take a considerable amount of time β like, she's gonna be a minute, go grab a snack. π
β¨ OPTIONS β¨
Okay bestie, this is the part where we go through literally every flag. There are a lot. Grab a snack. π
--helpβ shows you a lil brief help message. That's it, that's the whole thing.- *
-a*file /--addfile** β adds *file*, which should be a disk image from a virtual machine. Heads up: if the VM has multiple block devices, you gotta supply **all** of them, each with its own separate-a` option. No shortcuts.
The format of the disk image is auto-detected. Wanna override that and force a specific format? Use the --format=.. option. π
- *
-a*URI /--addURI** β adds a *remote* disk. See"ADDING REMOTE STORAGE"inguestfish(1)` for the deets. π --blocksize=512,--blocksize=4096,--blocksizeβ this parameter sets the sector size of the disk image. It affects all the explicitly added subsequent disks after this parameter (so order matters, bestie π). Using--blocksizewith no argument switches the disk sector size back to the default, which is usually 512 bytes. See also"guestfs_add_drive_opts"inguestfs(3).--checksum,--checksum=crc|md5|sha1|sha224|sha256|sha384|sha512β displays a checksum over the file contents, for regular files only. With no argument it defaults tomd5. Give it an argument and you get to pick which checksum type is used. π₯
This option only has an effect in -lR output mode. See "RECURSIVE LONG LISTING" above.
-cURI /--connectURI` β if you're using libvirt, connect to the given URI. If you leave it out, we connect to the default libvirt hypervisor. β¨
If you specify guest block devices directly (with -a), then libvirt is not used at all. Zero libvirt. None. π
--csvβ writes the results out in CSV format (comma-separated values). This format imports super easily into databases and spreadsheets, but pls read"NOTE ABOUT CSV FORMAT"below before you go feral with it. π-dguest /--domainguest` β adds all the disks from the named libvirt guest. Oh and fun fact: domain UUIDs can be used instead of names. π--echo-keysβ when prompting for keys and passphrases,virt-lsnormally turns echoing off so you can't see what you're typing. If you're not worried about Tempest attacks and there's literally no one else in the room, you can drop this flag to see what you're typing. iykyk. π«Ά--extra-statsβ displays extra stats. π
This option only has an effect in -lR output mode. See "RECURSIVE LONG LISTING" above.
--format=raw|qcow2|..,--formatβ the default for the-aoption is to auto-detect the format of the disk image. Using this forces the disk format for-aoptions that follow on the command line. And using--formatwith no argument switches back to auto-detection for the subsequent-aoptions.
For example:
virt-ls --format=raw -a disk.img /dir
forces raw format (no auto-detection) for disk.img.
virt-ls --format=raw -a disk.img --format -a another.img /dir
forces raw format (no auto-detection) for disk.img and reverts to auto-detection for another.img.
β οΈ If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). Not a drill, bestie. π₯
-h/--human-readableβ displays file sizes in human-readable format. Much cuter numbers. πΈ
This option only has an effect in -lR output mode. See "RECURSIVE LONG LISTING" above.
--keySELECTOR β specifies a key for LUKS, so it automatically opens a LUKS device when using the inspection. π--keyNAME:key:KEY_STRING--keyUUID:key:KEY_STRING--keyall:key:`KEY_STRING**
NAME is the libguestfs device name (eg. /dev/sda1). UUID is the device UUID. all means try the key against any encrypted device.
Uses the specified KEY_STRING as the passphrase. π
--keyNAME:file:FILENAME--keyUUID:file:FILENAME--keyall:file:`FILENAME**
Reads the passphrase from FILENAME. π
--keyNAME:clevis--keyUUID:clevis--keyall:clevis`**
Attempts passphrase-less unlocking for the device with Clevis, over the network. Pls refer to "ENCRYPTED DISKS" in guestfs(3) for more info on network-bound disk encryption (NBDE).
Heads up: if any such option is present on the command line, QEMU user networking will be automatically enabled for the libguestfs appliance. π
--keyNAME:error--keyUUID:error--keyall:error`**
Any encrypted device matching will cause an error. And --key all:error can be used to reject any disk image that contains an encrypted partition. Cold. But useful. π
--keys-from-stdinβ reads key or passphrase parameters from stdin. The default is to try to read passphrases from the user by opening/dev/tty.
If there are multiple encrypted devices then you may need to supply multiple keys on stdin, one per line. π
-mdev[:mountpoint[:options[:fstype]]]/--mountdev[:mountpoint[:options[:fstype]]]β mounts the named partition or logical volume on the given mountpoint. π§
If the mountpoint is omitted, it defaults to /.
Big one: specifying any mountpoint disables the inspection of the guest and the mount of its root and all of its mountpoints, so make sure you mount all the mountpoints needed to work with the filenames given as arguments. Don't skip a step, bestie. π
If you don't know what filesystems a disk image contains, you can either run guestfish without this option and then list the partitions, filesystems and LVs available (see "list-partitions", "list-filesystems" and "lvs" commands), or you can just use the virt-filesystems(1) program. π
The third (and rarely used) part of the mount parameter is the list of mount options used to mount the underlying filesystem. If this isn't given, then the mount options are either the empty string or "ro" (the latter if the --ro flag is used). By specifying the mount options, you override this default choice. Probably the only time you'd use this is to enable ACLs and/or extended attributes if the filesystem can support them:
-m /dev/sda1:/:acl,user_xattr
Using this flag is equivalent to using the "mount-options" command. β
The fourth part of the parameter is the filesystem driver to use, such as "ext3" or "ntfs". This is rarely needed, but can be useful if multiple drivers are valid for a filesystem (eg: "ext2" and "ext3"), or if libguestfs misidentifies a filesystem. π¦
-l/--long,-R/--recursiveβ selects the mode. With neither of these options,"virt-ls"produces a simple, flat list of the files in the named directory. See"SIMPLE LISTING".
"virt-ls -l" produces a "long listing", which shows more detail. See "LONG LISTING".
"virt-ls -R" produces a recursive list of files starting at the named directory. See "RECURSIVE LISTING".
"virt-ls -lR" produces a recursive long listing which can be more easily parsed. See "RECURSIVE LONG LISTING". π
--timesβ displays time fields. β°
This option only has an effect in -lR output mode. See "RECURSIVE LONG LISTING" above.
--time-daysβ displays time fields as days before now (negative if in the future).
Note that 0 in the output means "up to 1 day before now", or that the age of the file is between 0 and 86399 seconds. π°οΈ
This option only has an effect in -lR output mode. See "RECURSIVE LONG LISTING" above.
--time-relativeβ displays time fields as seconds before now (negative if in the future).
This option only has an effect in -lR output mode. See "RECURSIVE LONG LISTING" above.
--time-tβ displays time fields as seconds since the Unix epoch. π
This option only has an effect in -lR output mode. See "RECURSIVE LONG LISTING" above.
--uidsβ displays UID and GID fields. π
This option only has an effect in -lR output mode. See "RECURSIVE LONG LISTING" above.
-v/--verboseβ enables verbose messages for debugging. She's chatty. π£οΈ-V/--versionβ displays the version number and exits. β¨-xβ enables tracing of libguestfs API calls. Watch her work. π
π« OLD-STYLE COMMAND LINE ARGUMENTS π«
Previous versions of virt-ls let you write either:
virt-ls disk.img [disk.img ...] /dir
or
virt-ls guestname /dir
whereas in this version you should use -a or -d respectively to avoid that confusing case where a disk image might have the same name as a guest. π Like, imagine the chaos.
For compatibility the old style is still supported. She's nostalgic like that. π«Ά
π¨ NOTE ABOUT CSV FORMAT π¨
Comma-separated values (CSV) is a deceptive format. It seems like it should be easy to parse, but it is definitely not easy to parse. Not even a little. π
Myth: Just split fields at commas. Reality: This does not work reliably. This example has two columns:
"foo,bar",baz
Myth: Read the file one line at a time. Reality: This does not work reliably. This example has one row:
"foo
bar",baz
See?? Deceptive!! π
For shell scripts, use "csvtool" (https://github.com/Chris00/ocaml-csv also packaged in major Linux distributions).
For other languages, use a CSV processing library (eg. "Text::CSV" for Perl or Python's built-in csv library).
Most spreadsheets and databases can import CSV directly. πΈ
β EXIT STATUS β
This program returns 0 if successful, or non-zero if there was an error. Simple as that, bestie.
π¦ SEE ALSO π¦
guestfs(3), guestfish(1), virt-cat(1), virt-copy-out(1), virt-diff(1), virt-tar-out(1), http://libguestfs.org/.
π AUTHOR π
Richard W.M. Jones http://people.redhat.com/~rjones/
πΈ COPYRIGHT πΈ
Copyright (C) 2009-2025 Red Hat Inc.
π LICENSE π
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
π BUGS π
ok so if you ever wanna go snooping through the bug list for libguestfs, bestie, here's the link, no gatekeeping:
https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools
and if you actually found something π and wanna file a brand new bug against libguestfs, this is the one you want:
https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools
π when you report a bug, pls pls pls include π
like genuinely, the maintainers are begging, this is the vibe check:
- The version of libguestfs. β yes we need to know which one, don't be mysterious about it π
- Where you got libguestfs (eg. which Linux distro, compiled from source, etc) β so, like, the whole origin story. where did this libguestfs come from, bestie.
- Describe the bug accurately and give a way to reproduce it. β be honest, be specific, and hand them the exact steps so they can make it happen too. "it broke" is not a description, it's a cry for help π
- Run
libguestfs-test-tool(1)and paste the complete, unedited output into the bug report. complete. unedited. don't trim it, don't pretty it up, don't paraphrase β the whole thing, raw, into the report. that output is the main character of your bug report fr fr π«Ά
fair warning: snipping or "cleaning up" that libguestfs-test-tool(1) output lowkey makes the report way harder to debug, so just paste the whole unedited thing, k thanks π
and that's the whole page, bestie!! you made it to the end, iconic behavior honestly ππ
this was virt-ls(1) from guestfs-tools 1.57.3, dated 2026-09-16 β go forth and list some files inside your guests, you absolute legend π¦β¨πΈ
π¦ where this page comes from
- centos-stream 10: guestfs-tools 1.57.3-1.el10 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms