Computer Science, asked by tallaalekhya99, 6 months ago

Write a command to list all the files and directories in the current directory whose second character is a digit

Answers

Answered by raotd
1

Answer:How will you list all files in the current directory whose second character is a digit?

2 Answers

  1. 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. ...
  2. Use find to look for non-directories (and weed out symbolic links to directories) in the current directory:

Explanation:

Answered by lena38
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