Skip to main content
Engineering LibreTexts

01-B.19: Leftovers, What Else Do We Need?

  • Page ID
    26795
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Before We Move On

    Just a few more points to cover before we move on.

    Shutdown/Reboot

    Those who come from the world of Windows systems are used to having to reboot the system at various times. While Linux does not suffer from the frequency of reboots that Windows seems to, there are still times when Linux need to be powered off, or simply rebooted. Current distros are better at dealing with being shut down by a user hitting the power off button on their computer, BUT, that is never the recommended method. It is best to perform an orderly shutdown, and for that there is the shutdown command and a reboot command.

    A couple of the more common invocations of shutdown:

    • shutdown -h
      • The  -h option tells shutdown to halt the system, that is, to power it off after an orderly shutdown.
    • shutdown -h -t 60
      • The system will shut down after the specified time delay - in this example the delay is 60 seconds
    • shutdown -r
      • If a reboot is desired, the -r option is available. You can also issue the reboot command from the terminal to achieve the same resultsBash History

    The bash shell comes with a very powerful command called “history.” This command is used to extract the history information about commands that have been executed by the user including all previous login sessions. Linux stores the command history for each user in a file ~/.bash_history by default.

    As each command is issued, it is recorded in the history file. The history command reads the history file and displays the contents to the terminal screen. You can see an example of the output in the image to the left. This history is set up to record 2000 entries, so you will be able to view the previous 2000 commands you enter, and the history file is persistent between login sessions.

    pbmac@pbmac-server $ history
     2000  ./"HW-01" 
     2001  journalctl
     2002  ls /var/log/journal/
     2003  ls -l /var/log/journal/
     2004  ls -l /var/log/journal/75d57d2bcd2831ebf58bcc1a000008d4/
     2005  journalctl -x
     2006  journalctl 
     2007  journalctl -x
     2008  last
     2009  lastlog
     2010  man dar
     2011  cd /usr/share/man
     2012  ls
     2013  cd man8
     2014  cd ../man1
     2015  ls tar*
    

    To access previous commands you can use the UpArrow and DownArrow to find the command you wish to re-issue. Often it is a matter of a typo - use the arrow keys to find the command, then use the left/right arrow keys to move your cursor and use the backspace or delete keys to remove characters and type in the correct input.

    There is much more that can be done with history in regards to command recall and command editing. There are several web sites and blogs that discuss this topic in great detail. Search for "bash history" and find one that works for you.

    Shell Tricks

    TAB completion saves typing. The completion feature in Bash permits typing a partial command, then pressing the [Tab] key to auto-complete the command sequence. If multiple completions are possible, then [Tab] lists them all. Let's see how it works.

    bash$ xtra[Tab]
    xtraceroute       xtrapin           xtrapproto
    xtraceroute.real  xtrapinfo         xtrapreset
    xtrapchar         xtrapout          xtrapstats
    
    bash$ xtrac[Tab]
    xtraceroute       xtraceroute.real
    
    bash$ xtraceroute.r[Tab]
    xtraceroute.real

    There is a clear command, which clears your terminal window. Sometimes things get cluttered, and to ease reading the terminal you can use the clear command to clean up your workspace.

    Use your history - see the previous section.

    Adapted from:
    "Appendix J. An Introduction to Programmable Completion" by David Merrill is licensed under CC BY-SA 3.0


    This page titled 01-B.19: Leftovers, What Else Do We Need? is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by Patrick McClanahan.

    • Was this article helpful?