Three long alkyl chain-bearing dibenzotriazole ionic liquids (BTA-R-BTA, R = 8, 12, and 16) were synthesized with high yield (>98%) through a simple and eco-friendly process. Their anticorrosion performance for Q235 carbon steel in 6 M hydrochloride acid was comprehensively evaluated by weight loss tests, electrochemical methods (potentiodynamic polarization and electrochemical impedance spectroscopy), and surface analysis techniques. As the length of the alkyl chain increased, the maximum corrosion inhibition efficiency enhanced from 55.02% (for BTA-8-BTA at 1.2 mM) to 97.10% (for BTA-12-BTA at 0.3 mM) and 98.84% (for BTA-16-BTA at 0.3 mM). Density functional theory calculation indicated that the alkyl chain length had little influence on the inhibitors' electronic structures, while molecular dynamics simulations revealed that the thickness, surface coverage, and compactness of adsorption films formed at the metal−electrolyte interface increased with the elongated alkyl chain. Corrosion inhibition efficiency is strongly correlated with the structures of the adsorption film.