Write a command to list all the files and directories in the current directory whose second character is a digit
Answers
Answered by
1
Answer:How will you list all files in the current directory whose second character is a digit?
2 Answers
- Use a shell loop, testing each name to see whether it's a directory or not and display the name if it isn't: for name in ?[0-9]*; do [ ! - d "$name" ] && printf '%s\n' "$name" done. ...
- Use find to look for non-directories (and weed out symbolic links to directories) in the current directory:
Explanation:
Answered by
0
My code for this is ls | grep .[0-9]*
And the output is showing as
d2
d4
di3
dir1
f1
f2
fil4
file3
g2t
g3t
The expected output is
d2
d4
f1
f2
g2t
g3t
I know i can directly use ls ?[0-9] but then my output order is different
f1 f2 g2t g3t
d2:
d4:
Similar questions