Bookmark this page

Lab: Accessing the Command Line

Performance Checklist

In this lab, you will use the Bash shell to efficiently execute commands using shell metacharacters.

Resources:
Files: /usr/bin/clean-binary-files

Outcomes

  • Practice using shell command line editing and history functions to efficiently execute commands with minor changes.

  • Change the password of the student user to T3st1ngT1me.

  • Execute commands used to identify file types and display parts of text files.

Reset your desktopX system. Perform the following steps on desktopX.

  1. Log into your desktopX system's graphical login screen as student.

  2. Open a terminal window that will provide a bash prompt.

    Select ApplicationsUtilitiesTerminal.

  3. Change student's password to T3st1ngT1me.

    Use the passwd command to change the password. Be sure to provide the original password, student, first.

    [student@desktopX ~]$ passwd
    Changing password for user student.
    Changing password for student.
    (current) UNIX password: student
    New password: T3st1ngT1me
    Retype new password: T3st1ngT1me
    passwd: all authentication tokens updated successfully.
    
  4. Display the current time and date.

    [student@desktopX ~]$ date
    Thu Apr  3 10:13:04 PDT 2014
    
  5. Display the current time in the following format: HH:MM:SS A/PM. Hint: The format string that displays that output is %r.

    Specify the +%r argument to date.

    [student@desktopX ~]$ date +%r
    10:14:07 AM
    
  6. What kind of file is /usr/bin/clean-binary-files? Is it readable by humans?

    Use the file command to determine its file type.

    [student@desktopX ~]$ file /usr/bin/clean-binary-files
    /usr/bin/clean-binary-files: POSIX shell script, ASCII text executable
    
  7. Use the wc command and bash shortcuts to display the size of /usr/bin/clean-binary-files.

    The easiest shortcut to use is Esc+. to reuse the argument from the previous command.

    [student@desktopX ~]$ wc <Esc>.
    [student@desktopX ~]$ wc /usr/bin/clean-binary-files
      594  1780 13220 /usr/bin/clean-binary-files
    
  8. Display the first 10 lines of /usr/bin/clean-binary-files.

    The head command displays the beginning of the file. Did you use the bash shortcut again?

    [student@desktopX ~]$ head <Esc>.
    [student@desktopX ~]$ head /usr/bin/clean-binary-files
    #!/bin/sh
    #
    # Script to clean binary files.
    #
    # JPackage Project <http://www.jpackage.org/>
    #
    # $Id: clean-binary-files,v 1.1 2006/09/19 19:39:37 fnasser Exp $
    
    # Import java functions
    [ -r "/usr/share/java-utils/java-functions" ] \
    
  9. Display the last 10 lines at the bottom of the /usr/bin/clean-binary-files file.

    Use the tail command.

    [student@desktopX ~]$ tail <Esc>.
    [student@desktopX ~]$ tail /usr/bin/clean-binary-files
    ...Output omitted...
    
  10. Repeat the previous command, but use the -n 20 option to display the last 20 lines in the file. Use command line editing to accomplish this with a minimal amount of keystrokes.

    Up Arrow displays the previous command. Ctrl+a makes the cursor jump to the beginning of the line. Ctrl+Right Arrow jumps to the next word, then add the -n 20 option and hit Enter to execute the command.

    [student@desktopX ~]$ tail -n 20 /usr/bin/clean-binary-files
    ...Output omitted...
    
  11. Execute the date command without any arguments to display the current date and time.

    [student@desktopX ~]$ date
    Thu Apr  3 10:48:30 PDT 2014
    
  12. Use bash history to display just the time.

    Display the list of previous commands with the history command to identify the specific date command to be executed. Execute the command with the !number history command.

    [student@desktopX ~]$ history
    ...
       44  date +%r
    ...
    [student@desktopX ~]$ !44
    date +%r
    10:49:56 AM
    
  13. Finish your session with the bash shell.

    Use either exit or the Ctrl+d key combination to close the shell.

    [student@desktopX ~]$ exit
    
Revision: rh124-7-1b00421