Wildcard ignores hidden files

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the bash category.

Last Updated: 2024-04-25

I wanted to move the current directory to AWS using scp as part of a simple deploy process.

I used this:

# Instead of the ip address for the remote host, I use an alias `schillerchor` from .ssh/config
# Then transfer it to the webapp directory there.
$ scp -r ./* schillerchorchat:webapp

When I did this I noticed (later) that the remote machine did not have the .env file. It did however have subdir/.env This issue is that the shell wildcard ignores hidden files in the current directory.

The following command will also omit the .env file

$  ls ./*

Howver this one will work

$  ls .*

--

The fix, for my deploy script, was to use absolute directory reference

$  scp -r $(pwd) schillerchorchat:webapp

Alternatively, I could have used a second (additional) command that just targets the dotfiles

$ scp -r ./* schillerchorchat:webapp
# Second, additional command
$ scp -r .* schillerchorchat:webapp

(Don't worry - this second command won't copy dirs like .. )