Pregunta de entrevista de Meta

What will happen when type "ls -l *.txt"

Respuestas de entrevistas

Anónimo

9 mar 2018

I think the interviewer was looking for information on how the shell creates child processes and what sys calls might be involved in running ls. The shell executes a stat syscall looking for file named ls in all paths included in the PATH environment variable. Once ls is found, the shell forks and execs the ls binary with the arguments -l and the expansion of the glob for *.txt, so multiple file names might be included, e.g. 1.txt, 2.txt etc, in the ls -l arguments. The expansion is probably done internally by the shell, depending on the shell, using a call to readdir or getdents, looking for files that match the glob in the cwd. ls then calls stat, or one of the stat family of syscalls, on each entry passed to ls to retrieve metadata from the file's inode. ls then writes the associated inode information, in a consistent format, including metadata such as: permissions, number of links, owning user, owning group, file size, modification time and filename to the stdout file descriptor (fd: 1) for the process. All printed metadata is drawn from the inode information that the stat call will return. Finally ls exits and the shell, which has perviously called wait, reprints the shell prompt.

2

Anónimo

28 feb 2018

That depends on shell. Shells usually does not support RE, instead they have something called globbing, or file expansion. It can be even turned off, so above command can dispaly only file called *.txt. Shells can change behaviour of globbing via various flags, so correct answer really depends on many stuff. By default, bash, will display files not starting with dot.

Anónimo

12 dic 2015

Displays a list of all text files in this folder using a long listing format option

1