0% found this document useful (0 votes)
93 views4 pages

Chapter02-Accessing The Command Line

The document discusses accessing the command line and provides examples of using common commands like date, file, wc, head, tail and history. It demonstrates using command history, command line editing and output redirection.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views4 pages

Chapter02-Accessing The Command Line

The document discusses accessing the command line and provides examples of using common commands like date, file, wc, head, tail and history. It demonstrates using command history, command line editing and output redirection.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CHAPTER 2 | Accessing the Command Line

ACCESSING THE COMMAND LINE


BEFORE YOU BEGIN
Follow steps in the handout named
[Preparation for any Lab Assignment]
to log in to workstation as student
using student as the password. If you
miss these steps you cannot do your
lab assignment!!!

On workstation, run the lab cli-review start script to set up a clean lab
environment. The script also copies the zcat file to student's home directory.

[student@workstation ~]$ lab cli-review start

1. Use the date command to display the current time and date.

[student@workstation ~]$ date


Thu Jan 22 10:13:04 PDT 2019

2. Display the current time in 12-hour clock time (for example, 11:42:11 AM). Hint: The format
string that displays that output is %r.
Use the +%r argument with the date command to display the current time in 12-hour clock
time.

[student@workstation ~]$ date +%r


10:14:07 AM

3. What kind of file is /home/student/zcat? Is it readable by humans?


Use the file command to determine its file type.

[student@workstation ~]$ file zcat


zcat: POSIX shell script, ASCII text executable

4. Use the wc command and Bash shortcuts to display the size of zcat.
The wc command can be used to display the number of lines, words, and bytes in the zcat
script. Instead of retyping the file name, use the Bash history shortcut Esc+. (the keys Esc
and . pressed at the same time) to reuse the argument from the previous command.

42 RH124-RHEL8.0-en-1-20190531
CHAPTER 2 | Accessing the Command Line

[student@workstation ~]$ wc Esc+.


[student@workstation ~]$ wc zcat
51 299 1983 zcat

5. Display the first 10 lines of zcat.


The head command displays the beginning of the file. Try using the Esc+. shortcut again.

[student@workstation ~]$ head Esc+.


[student@workstation ~]$ head zcat
#!/bin/sh
# Uncompress files to standard output.

# Copyright (C) 2007, 2010-2018 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify


# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.

6. Display the last 10 lines of the zcat file.


Use the tail command to display the last 10 lines of the zcat file.

[student@workstation ~]$ tail Esc+.


[student@workstation ~]$ tail zcat
With no FILE, or when FILE is -, read standard input.

Report bugs to <bug-gzip@gnu.org>."

case $1 in
--help) printf '%s\n' "$usage" || exit 1;;
--version) printf '%s\n' "$version" || exit 1;;
esac

exec gzip -cd "$@"

7. Repeat the previous command exactly with three or fewer keystrokes.


Repeat the previous command exactly. Either press the UpArrow key once to scroll back
through the command history one command and then press Enter (uses two keystrokes),
or enter the shortcut command !! and then press Enter (uses three keystrokes) to run the
most recent command in the command history . (Try both.)

[student@workstation]$ !!
tail zcat
With no FILE, or when FILE is -, read standard input.

Report bugs to <bug-gzip@gnu.org>."

case $1 in
--help) printf '%s\n' "$usage" || exit 1;;

RH124-RHEL8.0-en-1-20190531 43
CHAPTER 2 | Accessing the Command Line

--version) printf '%s\n' "$version" || exit 1;;


esac

exec gzip -cd "$@"

8. 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 number of keystrokes.
UpArrow displays the previous command. Ctrl+A makes the cursor jump to the beginning
of the line. Ctrl+RightArrow jumps to the next word, then add the -n 20 option and hit
Enter to execute the command.

[student@workstation ~]$ tail -n 20 zcat


-l, --list list compressed file contents
-q, --quiet suppress all warnings
-r, --recursive operate recursively on directories
-S, --suffix=SUF use suffix SUF on compressed files
--synchronous synchronous output (safer if system crashes, but slower)
-t, --test test compressed file integrity
-v, --verbose verbose mode
--help display this help and exit
--version display version information and exit

With no FILE, or when FILE is -, read standard input.

Report bugs to <bug-gzip@gnu.org>."

case $1 in
--help) printf '%s\n' "$usage" || exit 1; exit;;
--version) printf '%s\n' "$version" || exit 1; exit;;
esac

exec gzip -cd "$@"

9. Use the shell history to run the date +%r command again.
Use the history command to display the list of previous commands and to identify the
specific date command to be executed. Use !number to run the command, where number is
the command number to use from the output of the history command.
Note that your shell history may be different from the following example. Determine the
command number to use based on the output of your own history command.

[student@workstation ~]$ history


1 date
2 date +%r
3 file zcat
4 wc zcat
5 head zcat
6 tail zcat
7 tail -n 20 zcat
8 history
[student@workstation ~]$ !2
date +%r
10:49:56 AM

44 RH124-RHEL8.0-en-1-20190531
CHAPTER 2 | Accessing the Command Line

Evaluation
On workstation, run the lab cli-review grade script to confirm success on this exercise.

[student@workstation ~]$ lab cli-review grade

Finish
On workstation, run the lab cli-review finish script to complete the lab.

[student@workstation ~]$ lab cli-review finish

This concludes the lab.

RH124-RHEL8.0-en-1-20190531 45

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy