Linux experiments - the use of shell

Experiment 5: Use the shell

 

Experimental Procedure

  1. log in system.

a. Using a user name and password to create a system test.

b. Open the Terminal application.

 

  1. Respectively, using a single echo command to output the following information:

a.Hello World

b.Hello

World

c.”Hello World”

d.?*[]&();><

e.Filename: file?Option:all

 

answer:

aecho Hello World

becho -e “Hello\nWorld”

cecho ‘”Hello World”’ echo \"Hello world\"

decho ‘?*[]&();><’

eecho ‘Filename: file?Option:all’

 

  1. Echo command, and other commands output the following information:

a. Current Date Time: [current date and time].

   Current Directory Contents:

   [Current directory contents]

answer:

echo “Current Date Time: `date`”; echo “Current Directory Contents:”; ls

(Note: Use the command to command more than two single-line replacement and knowledge)

 

b. Display after a delay of 5 seconds: I woke up.

answer:

sleep 5; echo “I woke up”

 

  1. shell variables and environment variables

a. Create a variable MyNAME, assign abbreviated his name letters.

b. Value MyNAME display variables.

c. The variable becomes an environment variable.

d. Bash executed in the shell, and then displays the value of the variable MyNAME.

e. Reopen a terminal application, display the value of the variable MyNAME.

answer:

aname=XXX

becho $name

cexport MyNAME

dbash

echo $MyNAME

(Showing results XXX )

E . Open a new Terminal application

echo $MyNAME

(Showing results is empty)

 

  1. Login profile

a. Is there a .profile file to view the home directory.

b. Create or modify .profile file so that every time you log displays the following information:

Hello World

Current Date and Time: [current date and time]

c. 3 switch to the virtual terminal, after outputting the registration confirmation message.

answer:

afind $HOME -name .profile

b . if there is not:

   cd

   cat > .profile

   echo Hello World

   echo “Current Date and Time: `date`”

   [ctrl-d]

   If there is:

   Use vi opened before the first row was added:

echo Hello World

   echo “Current Date and Time: `date`”

 

  1. Process Management

a. Create a background process sleep 120; echo "Job done".

b. Create a background process vi numbers, to see their ID.

c. Turn off background process sleep 120; echo hi.

d. Turn off background processes vi numbers.

e. Switch to virtual terminal 2, to create a background process using nohup sleep 10; echo "Job done". Ps command to view the background processes.

f. Exit virtual terminal 2 with [Ctrl-d] or exit command.

g. Switch back to the virtual terminal 2, login.

h. Ps command to view the status of a background process.

i. Find the current home directory nohup.out, and view its contents, confirmed the presence of Job done.

 

answer:

a(sleep 120;echo hi)&

bvi numbers&

c . PS (see the sleep process pid )

   kill sleep process pid

d . PS (see vi process pid )

   kill -9 vi process pid  (can only be forced to close)

echvt 2

nohup bash -c ‘sleep 10;echo “Job done”’ &

ps

fexit

gchvt 2

hps

icd

find . -name nohup.out

cat nohup.out

 

  1. High Command

a. Create a file in your home directory contact, saved 10 people's name, age and phone number, between the first and last names separated by spaces, separated by Tab between the name, age, telephone number. Format is as follows:

Zhang San 20 13504401234

Li Si 15 13522434856

Wang Wu-9 15808465237

……

 

b. Use the sort command, respectively, by name, last name and phone forward and reverse sort order.

c. Grep the surname Zhang students, and the students at the beginning of the telephone 135 in the contact.

answer:

avi contact

b . Sort by name: the Sort the Sort -r Business Card Business Card

   Sort by name: the Sort -k 2 -k 2 -r the Sort Business Card Business Card

   Sort by age: the Sort -k -k the Sort 3N 3N Business Card Business Card | tac

cgrep Zhang contact

   grep -E “135[0-9]{8}” contact

 

  1. Environment Variables

a. Save the file to the value of PS1 ps1, view ps1 content.

b. Modify the shell prompt so that it displays the command number + "$."

c. Modify the shell prompt that displays the name of the shell + "$."

d. Restores the value of PS1 ps1 file.

answer:

aecho $PS1 > ps1

   as PS1

b . PS1 = "\! $"

c . PS1 = "\ $ s"

g . PS1 = $ (as PS1)

 

  1. Aliases

a. View aliases defined in the current shell.

b. --color create an alias ls as ls -l.

c. At the command line, type ls, how to determine the ls command is executed and ls aliases.

d. Contrast ls and \ execute two commands ls effect, indicating the reasons.

 

answer:

a . by the way

balias ls=ls -l --color

ctype ls

d . ls is an alias, \ ls is ls command, slash role is to escape

 

Published 58 original articles · won praise 22 · views 9852

Guess you like

Origin blog.csdn.net/zsd0819qwq/article/details/103868873