According to IRS rules, you can't sell a security, take a capital loss on your taxes, and then buy back the same or a "substantially identical" security within 30 days. However, "substantially identical" is poorly defined, especially with regard to mutual funds/ETFs as opposed to individual stocks. Which of the following examples would/wouldn't be considered "substantially identical":
Sell the Vanguard 500 Index and buy the Vanguard Total Stock Market Index? The holdings are about 80% identical and the returns are usually similar, but they are completely different funds with slightly different objectives, since they track different U.S. stock indices.
Sell one company's ETF that tracks a given index and buy another company's ETF that tracks the exact same index.
Sell your long position in a stock and then buy a far out of the money call on the same stock just in case it goes back up a lot.
Sell a bunch of individual stocks in a given sector and then buy a sector ETF whose biggest holdings are the stocks you just sold.