Reputation: 37
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
?
Upvotes: 1
Views: 395
Reputation: 369274
[..]
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.
Upvotes: 2