Score:2

display the filenames with 4 or more characters using ls

sd flag

How to display the filenames with 4 or more characters using the ls command

Score:9
it flag

Use wildcards (they're not regexps):

ls -A -d ????*

That's 4 "any characters" followed by "any number of any characters". man ls.

marcelm avatar
cn flag
You say `man ls`, but what good will that do anyone? Globbing is performed by the shell; `ls` doesn't know about it and there's nothing about it in its manual.
Quasímodo avatar
jp flag
Although I see the asker artificially required Ls, invoking Ls here is just useless and requires using `-d` flag to make Ls work more or less like a plain Printf at the end of the day. In other words, spawning no new external process, one may simply write `printf '%s\n' ????*` or `echo ????*`.
Zanna avatar
kr flag
@Quasímodo `printf` works (though filenames having newlines might cause confusion), but with `echo` I get no newlines making it impossible to read the filenames. The advantage of `ls` is that it's designed to *display to the user* files in a directory in the most readable and unambiguous way. Personally, I don't think all of its design elements contribute to that end, but that is the intent. The commands you mention have different purposes and are less suited to this task.
Zanna avatar
kr flag
I agree with marcelm. We should rather read `man bash` or indeed https://www.gnu.org/software/bash/manual/bash.html#Filename-Expansion - `man ls` will be of little help.
Will avatar
id flag
@waltinator - should it be ls -A -d ???* if he wants 4 or more characters? I’m not sure if the * mandates at least 1 character after the 4 wildcards in your answer? Or can the * be any number of characters *including zero* in which case your answer is perfect?
mckenzm avatar
in flag
@will - that's a good question , it doesn't - * also matches ''. So ???* matches foo - This is easily tested. Personally I would be piping ls -la through grep, and what about links and folders?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.