Using the command line (experimental)

Table of contents

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

2. Display the current time in 12-hour format (for example, 11:42:11AM). Tip: The format string that displays this output is %r.

3. What is the file type of /home/student/app1.log? Can it be read by others?

4. Use the wc command and Bash shortcut keys to display the size of zcat.

5. Display the first 10 lines of app1.log.

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

7. Completely repeat the previous command in three keystrokes or less.

8. Repeat the previous command, but use the -n 20 option to display the last 20 lines in the file. Use command line editing capabilities to do this with a minimum of keystrokes.

9. Use the shell history to run the date +%r command again.


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

date

                                

 

2. Display the current time in 12-hour format (for example, 11:42:11AM). Tip: The format string that displays this output is %r.

        Use the +%r parameter to run the date command to display the current time in 12-hour format.

date +%r

                                

 

3./home/student/app1.log What is the file type of ? Can it be read by others?

        Use the file command to determine its file type.

file app1.log

                ​​​​​​​        ​​​​​​​        

4. Use the wc command and Bash shortcut keys to display the size of zcat.

        The wc command can be used to display the number of lines, words, and bytes in the app1.log script. Use the Bash history shortcut Esc+, (press the Esc and . keys simultaneously) to reuse arguments from the previous command instead of retyping the filename.

wc Esc+.
wc app1.log

        ​​​​​​​        ​​​​​​​                

 

5. Display the first 10 lines of app1.log.

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

head Esc+.
head app1.log

        ​​​​​​​        ​​​​​​​        ​​​​​​​        

        Since the content of the app1.log file is empty, the content of the displayed output is also empty. If the file is not empty, the first ten lines of the file content can be output.

 

head .bashrc

        ​​​​​​​        ​​​​​​​        ​​​​​​​        

 

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

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

tail .bashrc

                                

 

7. Completely repeat the previous command in three keystrokes or less.

Repeat the previous command exactly. Press the _ key to scroll forward one command at a time from the command history, then press Enter (using two keystrokes), or enter the shortcut command!! and then press Enter (using three keystrokes) key) to run the most recent command in the command history. (Try both methods once.)

!!

        ​​​​​​​        ​​​​​​​        ​​​​​​​        

 

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 do this with the minimum number of keystrokes.

        The up arrow displays the previous command. ctrl+A makes the cursor jump to the beginning of the line. ctr1+right arrow to jump to next word, then add -n 20 option and press enter to execute the command.

tail -n 20 .bashrc

        ​​​​​​​        ​​​​​​​        ​​​​​​​        

         

9. Use the shell history to run the date +%r command again.

        Use the history command to display a list of previous commands to determine the specific date command to execute. Run the command using ! number, where number is the command number taken from the history command output. Note that your shell history may differ from the following example. Determine the command number to use based on the output of your own history command.

history
!73

        ​​​​​​​        ​​​​​​​        ​​​​​​​        

 

Guess you like

Origin blog.csdn.net/m0_65299954/article/details/131962940