Pregunta

I have a code which includes the line below:

old_fil=`ls -lt [!_]*xyz* 2> /dev/null | grep -v ^total | tail -1 | awk '{print $9}'`

Can you explain the meaning of [!_] and 2 in ls -lt?

¿Fue útil?

Solución

[..] matches any character that is listed inside.

But if the first character is ^ or !, it matches any characters not in the specified characters.; [!_] match characters that is not _.

Following command lists files that whose name does not starts with _ (it should match a chracter) and contains xyz:

ls [!_]*xyz*

2 in 2> means file descriptor. (0 = standard input, 1 = standard output, 2 = standard error).

By appending 2> /dev/null, error messages generated by the command will be discarded.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top