-1

I'm learning Ubuntu in University and the task is find a file in the command line with the following instruction:

  • file should start with letter g
  • filename should have only 3 characters
  • file extension must be .d

The search should be performed with the command find.

  • Did you read the find manpage? What is unclear there? – PerlDuck Mar 18 '18 at 9:11
  • Unclear how to find with only 3characters, starts with letter "g". – Maxim Savchuk Mar 18 '18 at 9:20
  • 2
    File or filename should start with g? If filename, does the character limit include the .d extension? – muru Mar 18 '18 at 10:30
4

Since you are allowed to use the find command, this is quite simple:

find / -type f -name "g??.d"

This will find all files (-type f) with a name that starts with g, followed by two arbitrary characters ??, followed by .d (-name "g??.d") in the root directory / and below.

When run as non-root user you will get many permission denied errors because not all directories below / are accessible by non-root. Also, it may take a while.

Change / to the path where you want to start the search from, e.g. /home/your_user or simply . for the current directory.

Add -ls to get not only the file's names but also their attributes (size, age, permissions):

find . -type f -name "g??.d" -ls

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.