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 #display all files in current directory with  (-l) long format.
ls -a /directory #display all hidden files in given directory that start with .

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)