Issue
Directory content
rtetteh@PW02R9F3:~/Projects$ ls -al
total 68
drwxr-xr-x 5 rtetteh rtetteh 4096 Oct 27 13:45 .
drwxr-xr-x 18 rtetteh rtetteh 4096 Oct 27 13:45 ..
-rw-r--r-- 1 rtetteh rtetteh 12288 Sep 30 15:19 .ThreadTest.cpp.swp
drwxr-xr-x 2 rtetteh rtetteh 4096 Oct 27 13:45 .recycleBin
-rw-r--r-- 1 rtetteh rtetteh 953 Oct 27 13:44 ThreadTest.cpp
-rwxr-xr-x 1 rtetteh rtetteh 24984 Sep 30 15:14 ThreadTest_exe
drwxr-xr-x 2 rtetteh rtetteh 4096 Aug 17 18:26 hello
drwxr-xr-x 6 rtetteh rtetteh 4096 Oct 21 15:12 python-account-manager
-rwxr-xr-x 1 rtetteh rtetteh 168 Aug 19 20:23 test_pos_param.sh
Test 1
rtetteh@PW02R9F3:~/Projects$ ls -al *.sh
-rwxr-xr-x 1 rtetteh rtetteh 168 Aug 19 20:23 test_pos_param.sh
Test 2
rtetteh@PW02R9F3:~/Projects$ ls -al *.swp
ls: cannot access '*.swp': No such file or directory
Why does Test 1 work and not Test 2. How do I get Test 2 to work i.e show files with .swp extension
Solution
Your incorrect assumption is that asterisk expands to include "." at the start of the string. Shell defaults don't make that match in regexp.
You need to specifically specify ".*.swp" in order to make the correct expansion. That also doesn't need the -a switch for ls, because you specified the "." prefix.
Answered By - Eric Marceau Answer Checked By - Terry (WPSolving Volunteer)