Remember that one command that solved your problem? Was it cat, less, more, wc or something else? When were at the terminal, we can issue dozens of commands to solve a problem and in the background our Linux OS is recording these commands to a history file.
In this how-to well look at various ways of searching and re-using our command history. Whilst you become accustomed to these commands its important to double check you dont unintentionally reissue a command that could cause problems. Take your time using these new techniques and double check the details before pressing enter!
All the commands in this how-to will work on most Linux machines. Weve used a Ubuntu 20.04 install but you could run this how-to on a Raspberry Pi. All of the how-to is performed via the Terminal. You can open a terminal window on most Linux machines by pressing ctrl, alt and t.
The simplest way to look through your recent commands is to use the up and down arrow keys on your keyboard to scroll through the previous commands. If you want to reissue a found command simply press the enter key.
The history command, in its most basic use case, lists and annotates the last 1000 commands issued in the terminal emulator. Each command has a number associated with it.
1. Run the history command to see a list of the last 1000 commands. Youll see that all the listed historical commands are given a unique reference number.
2. Reissue the history command but constrain the amount of results to a specific number. This is useful if you know roughly when a command you are looking for was issued. You should see only the last 20 results listed.
Now we can use history to view our previous commands, we can choose and reissue a command using the number assigned to the history results.
1. Run history 20 to create a list of commands, choose a command to reissue making sure that the chosen command is safe to run. Choosing a simple command like cd Music (1660) is a good safe example. Note there is no space between the exclamation mark and the command number.
By piping the output of history into grep we can perform a search of our command history returning results for a specified term or string. This is an excellent approach for finding a partially remembered command.
1. Search for a specific term using history and grep. We used the example search term silhouette as we recalled we had issued some commands to rectify a problem with a silhouette vinyl cutter. Replace that search term with something suited to your machine.
Another handy approach to retrieve previous Linux commands is to use the reverse search function built into the terminal. To enter this mode you simply press ctrl and r. You can then enter a search term and use repeat presses of ctrl and r to step back through the list of previous commands containing that term. When you find a command you want to reissue press enter.
1. Press ctrl and r enters the reverse search mode, you should see the prompt now reads (reverse I search)`':
2. Type a search term and you should see the last command issued that contained this term. For example we added the search term sudo to show the previous commands issued with sudo privileges.
3. Repeat pressing ctrl and r to step through other results.
4. Run a previous command by pressing enter or quit the reverse search by pressing esc .
Often we will want to simply rerun the last command we issued. We can achieve this simply using the !! command.
1. Run the ls command to set this as the example to test.
2. Reissue the last command using !!. Note that the previous command is listed and performed.
Sometimes we may try to reuse a command that requires elevated privileges, for example editing a file outside of our home directory. To do this we can preface the previous command with sudo. In the following example we append the first ls command to be reissued with sudo.
There may come a time where you need to keep a command out of your history, and if that scenario ever occurs, all you need to do is preface the command with a single press of the spacebar.
For example here are two ls commands, the second has a single space, hiding it from the history file.
With a little practice all the above approaches become quite instinctive to use and can make your terminal session more powerful and efficient. The ability to locate and reissue commands is extremely useful, especially when recovering a rarely used command or a command that was hard to create in the first instance.
The rest is here:
How to View Your Command History in Linux - Tom's Hardware
- US GAO - About GAO - 100 Years of GAO - Government Accountability Office [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- Oklahoma football: Baker Mayfield making OU history in the NFL - Stormin' in Norman [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- Here are the 5 biggest HRs in Padres history - MLB.com [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- Corey Crawford retires as one of the best in Chicago Blackhawks history - Da Windy City [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- Cardinal Koch: History of separation can be part of history of reconciliation - Vatican News [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- The Local Take Talks Health, History and African Americans - WCLK [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- In Depth: What history tell us about the US Capitol riots - RADIO.COM [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- Brighton Women's History Roll Of Honor Accepting Nominations For 2021 Inductees - WHMI [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- Who Has the Most Rushing Yards and Touchdowns in NFL Playoff History? - Sportscasting [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- Denver's cataloguing its Latino and Chicano history through places and buildings - Denverite [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- The Apple Car would wreck Apple, and Tesla's incredibly volatile history shows why - Business Insider [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- America Is Not Exceptional. It Has a History of Violence. - The Intercept [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- A brief history of the headscarf - CNN [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- On this date in history: -60 temperature reported in Cameron, WI - WQOW TV News 18 [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- Morning Flurries: WHL announcement and the Toronto Marlies make history - Mile High Hockey [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- How Warnock and Ossoff's victories evoked the history of the Black freedom struggle - CNN [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- Presidential Pours: A History of Wine in the White House - The Wall Street Journal [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- Today in History - MyMotherLode.com [Last Updated On: January 9th, 2021] [Originally Added On: January 9th, 2021]
- Today in History: George Washington approved adding two stars, two stripes to the American flag - Lompoc Record [Last Updated On: January 13th, 2021] [Originally Added On: January 13th, 2021]
- More inclusive: Local principal, teacher to help review history education in Virginia - WYDaily [Last Updated On: January 13th, 2021] [Originally Added On: January 13th, 2021]
- Here's a salute to one of Ohio women's suffrage pioneers - Richland Source [Last Updated On: January 13th, 2021] [Originally Added On: January 13th, 2021]
- Police Commissioners brother, an SFPD sergeant, has a history of shootings and excessive force complaints - Mission Local [Last Updated On: January 13th, 2021] [Originally Added On: January 13th, 2021]
- On January 13 in NYR history: The longest unbeaten streak ever in the NHL - Blue Line Station [Last Updated On: January 13th, 2021] [Originally Added On: January 13th, 2021]
- Democratic Party history from the year you were born - Buffalo News [Last Updated On: January 13th, 2021] [Originally Added On: January 13th, 2021]
- A US history teacher tries to explain attacks - The Hechinger Report [Last Updated On: January 13th, 2021] [Originally Added On: January 13th, 2021]
- Ron Rivera Embraced History To Find Success In His First Season In Washington - Forbes [Last Updated On: January 13th, 2021] [Originally Added On: January 13th, 2021]
- The Mother Lode: This is history in the making - again - for kids - CT Insider [Last Updated On: January 13th, 2021] [Originally Added On: January 13th, 2021]
- The History Behind 'Mob' Mentality - The New York Times [Last Updated On: January 13th, 2021] [Originally Added On: January 13th, 2021]
- 'I saw my life flash before my eyes': An oral history of the Capitol attack | TheHill - The Hill [Last Updated On: January 13th, 2021] [Originally Added On: January 13th, 2021]
- The US Capitol attack fits into the history of White backlash - CNN [Last Updated On: January 13th, 2021] [Originally Added On: January 13th, 2021]
- Bylaws of the Department of History - Nevada Today [Last Updated On: January 13th, 2021] [Originally Added On: January 13th, 2021]
- Subversive Capital Acquisition Corp. Closes The Largest Cannabis SPAC In History And Announces The Launch Of The Parent Company With Shawn... [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- Out of the Attic: The Moss Kendrix Collection at the Black History Museum - Alexandria Times [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- How Does the Nets' Big Three Compare to Other Big Threes in NBA History? - InsideHook [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- The Ku Klux Klans history is a warning about the Capitol riot - Vox.com [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- New Phillies reliever made postseason history vs. Pat Neshek - That Balls Outta Here [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- Lionel Gossman, specialist in French literature and history and 'one of the great humanists and scholar-teachers of his generation,' dies at 91 -... [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- 'Southern Charm': Leva Bonaparte Is on The Right Side Of History. Are You? - Decider [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- This Place in History: Warren Austin - Local 22/44 News [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- Here's how Tom Brady and the Buccaneers could make NFL history if they win their next two playoff games - CBS Sports [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- A History of the Trump Era Through Stories About Toilets - New York Magazine [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- 'Alarmingly Similar.' What the Chaos Around Lincoln's First Inauguration Can Tell Us About Today, According to Historians - TIME [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- A Brief Cultural History of Work Sucking - The New Republic [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- Naples Underground Featured on the History Channel - PRNewswire [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- Derby history is not kind to the Lecomte - VSiN [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- Gandhi, History, and the Lessons of the Events at the Capitol - The New Yorker [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- Will Donald Trump go down as the worst president in history? - CNN [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- View and delete your browsing history in Internet Explorer [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- View and delete browser history in Microsoft Edge [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- This Day in History - What Happened Today - HISTORY [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- History | discipline | Britannica [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- History - Wikipedia [Last Updated On: January 15th, 2021] [Originally Added On: January 15th, 2021]
- The most memorable walkoff wins in Cubs history, Part 2: Original NL teams - Bleed Cubbie Blue [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Dustin Pedroia will always have a place in Red Sox history; what about the Hall of Fame? - CBS Sports [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Sundance: 'Judas and the Black Messiah' introduces 'a history thats been buried in this country' - USA TODAY [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Virginia teacher uses bowties to share history and teach life lessons - WAVY.com [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Kremlin critic Navalny tells court that Putin will go down in history as nothing but an 'underpants poisoner' - Yahoo News [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Trump's impeachment lawyers have a history of being involved in controversial legal matters - KCTV Kansas City [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- 'Black History is a Verb': A young poet's message about Black history in America - KARE11.com [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- February is Black History Month and Heart Month. Why one cardiologist says thats a good coincidence. - ABC27 [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Thanks to the Internet Archive, the history of American newspapers is more searchable than ever - Nieman Journalism Lab at Harvard [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Creativity Is the Focus of Black History Month 2021 | | SBU News - Stony Brook News [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- This Black History Month, remember: History isnt here to make you feel good - Chicago Sun-Times [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Black History Month: How did it start, and why February? - 11Alive.com WXIA [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Comparing COVID-19 to other deadly diseases in U.S. history - CBS News 8 [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- Talk of the Times: Touring the rich history of Cape Ann - Gloucester Daily Times [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- Vice President Harris inspiring Black women and girls everywhere during Black History Month - Wink News [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- Brookshire Grocery Company publishes book to share 92-year history - Weatherford Democrat [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- Black History Month: Wyoming County was active on the Underground Railroad - The Daily News Online [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- Suspect in NMSP officers death had an extensive criminal history - KTSM 9 News [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- This week in history: Historical Society votes to move forward with fundraising for museum - Albert Lea Tribune - Albert Lea Tribune [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- The topsy-turvy history of the Nissan Pathfinder - Autoblog [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- God and government linked in history | Religion And Values | messenger-inquirer.com - messenger-inquirer [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- Black History and Heritage - The San Diego Union-Tribune [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- Behringer Crawford's NKY History Hour will feature Travis Brown and Locks and Dams of Ohio River - User-generated content [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- History and Hope: A conversation with Seaside's John Nash - KSBW Monterey [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- Today in History | National News - Tulsa World [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- NFL: Protesting players 'on the right side of history,' union says - Reuters [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- The True History Behind Netflix's 'The Dig' and Sutton Hoo - Smithsonian Magazine [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]
- A look at the top rotations in Dodgers history - Los Angeles Times [Last Updated On: February 6th, 2021] [Originally Added On: February 6th, 2021]