I'm trying to list files that start with "s" and with "l".
The command I'm trying is
ls -l *sfa*
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
The question is not very clear... based on your comment to @cmks, here are two options:
If you are looking for files where the first character of the filename is "s" and the last is "l" - then use
ls -l s*l
If you are looking for files where the first character of the filename is (either "a" or "s") and the last is (either "a" or "l") - then use
If it's something else, please edit your question to clarify...
ls -l sfa will only list files with the exact name "sfa" (or, if there's a directory with that name, any files in that directory). It doesn't do what you seem to be looking for.
The rules for matching file names ("globbing") are quite simple:
The directory separator "/" is excluded from matching - matching is only done on filenames.
See also ShellGlobbing in Ubuntu help.
ls -l s*l ls -l s?l
ls -l s[a-z]lwould limit it to
If you want files beginning with "s" and "a" you can use a collection:
ls -l [sa]*
will list all files beginning with those 2 letters. You can use that to create all kinds of groups. Exampe [sa][df][1ojwfihwef]* would make it search for file beginning with 3 letters that each match that specific group
You may give more than one parameter to the
ls command at a time:
ls -l H* *l
What happens is, the shell does a
Pathname Expansion. You may read more about it in the manual pages of bash:
Because the shell does it, the shell calls the command
ls as follows:
ls -l Hejo Hesja Hejan Lesl Lesil Lesul Lestl
It is imported to understand, it is not the
ls command but the shell who looks for matching pathnames.
Aside from using
ls command and shell's wildcards, one could use
find command as well.
$ find -maxdepth 1 -iname "s*l" ./script.pl ./storm carl ./sal ./simple_curl