Hi I have had a random email saying my apple account was compromised and I needed to click link to verify my account in the next 24 hours or my account would be shut down is this legitimate or could it be a scam
This is a well-known scam. Don't provide any information, and just throw the email away.
But, if you gave your Apple ID password to the scammer, then
Change your Apple ID password https://support.apple.com/en-us/HT201355
And here is What to do after you change your Apple ID or password https://support.apple.com/en-us/HT204071
To be proactive, learn about phishing, scams, and Apple practices, etc., see:
If you see apple.com/bill, itunes.com/bill, or an unfamiliar charge on your statement https://support.apple.com/en-us/HT201382
Identify legitimate emails from the App Store or iTunes Store https://support.apple.com/en-us/HT201679
How to avoid scams when using Apple Pay to send and receive money https://support.apple.com/en-us/HT208226
This scam related information from Apple including reporting scams to Apple see Avoid phishing
emails, fake 'virus' alerts, phony support calls, and other scams https://support.apple.com/en-us/HT204759
How to identify scams related to purported apple email notifications—per Eric Root.
“Apple will always address you by your name or the name they have on file for you, not Dear Customer, Dear Client or by using your e-mail address. The e-mail will be from @apple.com or @iTunes.com. E-mail addresses can be spoofed. You can go to Mail/View/Message/Show all Headers to see more. Apple emails won't have poor grammar/misspellings. Apple e-mails will never contain an attachment. Apple will never request personal information by email such as Social Security numbers, your Mother’s maiden name or full credit card numbers. …The only exception to the above I have noticed is if you order something from the Apple Store (apple.com), your receipt will be addressed to Dear Apple Customer. That is a receipt for a purchase you initiated.”
When Eric says Apple will always address you by your name or the name they have on file for you, I am not sure if he intends to include being address by your first name. I get some pertinent Apple emails that use only my first Name.
While scams and activities that compromise an account are different, learn about/Increase your security for safety. See:
If you think your Apple ID has been compromised https://support.apple.com/en-us/HT204145
Increase the Security of your Apple ID https://support.apple.com/en-us/HT201303
iCloud security overview https://support.apple.com/en-us/HT202303
Ways to keep your information safe on Mac https://support.apple.com/en-gb/guide/mac-help/mh11402/mac
Use Two-factor authentication for Apple ID https://support.apple.com/en-us/HT204915