ls -ls command code example
Example 1: ls command
ls command list computer files in a directory in Unix OS with next structure:
ls [OPTION]... [FILE]...
Examples:
ls -l
ls -a /directory
Example 2: how to use the ls -l command in python
from subprocess import Popen, PIPE def listdir_shell(path, *lsargs): p = Popen(('ls', path) + lsargs, shell=False, stdout=PIPE, close_fds=True) return [path.rstrip('\n') for path in p.stdout.readlines()] dirlist = listdir_shell('/var/log', '-t')[:10] from pprint import pprint pprint(dirlist)