"To the shores of Tripoli" refers to the Marine role in Thomas Jefferson's war against the Barbary pirates. The "Barbary coast" was a collection of Moslem mini-states on Africa's Mediterranean coast stretching from present day Algeria to present day Libya. The principal source of revenue for the Barbary states was attacking shipping in the Mediterranean, stealing their cargoes, and hold the crews for ransom or selling them into slavery.
The European powers of the day thought it cheaper to pay tribute to the Barbary states than to attack the pirates, and in 1784, the U.S. Congress followed suit. This was opposed by Mr. Jefferson, then the minister to France, who thought paying tribute would lead to larger demands. "It will be more easy to raise ships and men to fight these pirates into reason, than money to bribe them," Mr. Jefferson wrote in a letter to the president of Yale University in 1786.
Thomas Jefferson favored forming an international coalition to fight the pirates, but the Europeans wouldn't go along. When he became president in 1801, Mr. Jefferson refused Tripoli's demands for an immediate payment of $225,000, whereupon the Pasha of Tripoli, Yussif Karamanli, declared war on the United States.
This turned out to be a big mistake for Mr. Karamanli. President Jefferson dispatched naval forces to the Mediterranean, and sent one of the most remarkable of American heroes, William Eaton, to Egypt to raise an army to attack Tripoli. The only Americans Captain Eaton had with him were seven Marines led by Lt. Presley O'Bannon.
Mr. Eaton led the seven Marines and a motley force of about 500 Arab and Greek mercenaries on a 500-mile trek across the Libyan desert to attack Tripoli's capital of Derna, which was captured on April 27, 1805 in large part because of the reckless courage displayed by Lt. O'Bannon and his Marines. The dress sword Marine officers carry is modeled on the Mameluke sword an Arab prince presented to Lt. O'Bannon after the victory.
American naval forces commanded by Commodore Edward Preble and Captain Stephen Decatur had successes against the other Barbary states. On June 5, 1805, the Pasha signed a surrender treaty and President Jefferson told Congress the threat posed by the Barbary pirates was at an end.
Seizures of U.S.-flagged ships on the high seas have been few and far between since Jefferson's time, thanks largely to his forceful response.