Homework exercises After class

Source: Internet
Author: User
Tags syslog

Related exercises:

1. The contents of the File1 file are: "1 2 3 4 5 6 7 8 9 10" Calculates the sum of all numbers

Echo $[1+2+3+4+5+6+7+8+9+10]

echo "1+2+3+4+5+6+7+8+9+10" | Bc


Computer Demo

[[email protected] desktop]# echo $[1+2+3+4+5+6+7+8+9+10]

55

[Email protected] desktop]# echo "1+2+3+4+5+6+7+8+9+10" | Bc

55

[Email protected] desktop]#



2, processing string "Xt.,l 1 jr#! $mn 2 c*/fe3 uz4", keep only the numbers and spaces

echo "Xt.,l 1 jr#! $mn 2 c*/fe3 uz4" | Tr-d "xt.,ljr#! $MNC */feuz"


Computer Demo

[[email protected] desktop]# echo "Xt.,l 1 jr#! $mn 2 c*/fe3 uz4" | Tr-d "xt.,ljr#! $MNC */feuz"

echo "Xt.,l 1 jr#bcmn2 c*/fe3 uz4" | Tr-d "Xt.,ljr#bcmnc*/feuz"

1 2 3 4

[Email protected] desktop]#


3. Display the path variable in a separate row for each directory

echo $PATH | TR ":" \ n "


Computer Demo

[Email protected] desktop]# echo $PATH | TR ":" \ n "

/usr/lib64/qt-3.3/bin

/usr/local/sbin

/usr/sbin

/sbin

/usr/local/bin

/usr/bin

/bin

/root/bin

[Email protected] desktop]#


4. Delete blank lines of the specified file

Cat/root/install.log | Tr-s "\ n" "Use the-S loop"


Computer Demo


[Email protected] desktop]# Cat/root/install.log | Tr-s "\ n"

{

333

Anaconda-ks.cfg

Desktop

Documents

Downloads

F1

F22

F99

F[A,B,C,D,E,F]

History.log

Install.log

Install.log.syslog

Music

Nusers

Pictures

Public

Templates

Videos

[Email protected] desktop]#


5. Display each word (letter) in the file in a separate line with no blank lines

Cat/root/install.log | TR "" \ n "| Tr-s "\ n"


Computer Demo


[Email protected] desktop]# Cat/root/install.log | TR "" \ n "| Tr-s "\ n"

{

333

Anaconda-ks.cfg

Desktop

Documents

Downloads

F1

F22

F99

F[A,B,C,D,E,F]

History.log

Install.log

Install.log.syslog

Music

Nusers

Pictures

Public

Templates

Videos


6, create user Tiantian, additional group is bin and root, default shell is/bin/csh, annotation information is "Tiantian distribution"

Useradd-g bin,root-s/bin/csh-c "Tiantian Distribution" Tiantian


Computer Demo


[Email protected] desktop]# useradd-g bin,root-s/bin/csh-c "Tiantian Distribution" Tiantian


Rtkit:x:499:499:realtimekit:/proc:/sbin/nologin

Avahi-autoipd:x:170:170:avahi Ipv4ll Stack:/var/lib/avahi-autoipd:/sbin/nologin

Vcsa:x:69:69:virtual Console Memory Owner:/dev:/sbin/nologin

Abrt:x:173:173::/etc/abrt:/sbin/nologin

Rpcuser:x:29:29:rpc Service User:/var/lib/nfs:/sbin/nologin

Nfsnobody:x:65534:65534:anonymous NFS User:/var/lib/nfs:/sbin/nologin

Haldaemon:x:68:68:hal Daemon:/:/sbin/nologin

Ntp:x:38:38::/etc/ntp:/sbin/nologin

Apache:x:48:48:apache:/var/www:/sbin/nologin

SASLAUTH:X:498:76:SASLAUTHD User:/var/empty/saslauth:/sbin/nologin

Postfix:x:89:89::/var/spool/postfix:/sbin/nologin

Mysql:x:27:27:mysql Server:/var/lib/mysql:/bin/bash

Gdm:x:42:42::/var/lib/gdm:/sbin/nologin

Pulse:x:497:495:pulseaudio System Daemon:/var/run/pulse:/sbin/nologin

Sshd:x:74:74:privilege-separated Ssh:/var/empty/sshd:/sbin/nologin

Tcpdump:x:72:72::/:/sbin/nologin

Tianya:x:500:500:tianya:/home/tianya:/bin/bash

Gentoo:x:501:501:gentoo disttibuution:/home/gentoo:/bin/csh

Tian:x:502:502::/home/tian:/bin/bash

Tiantian:x:503:503:tiantian distribution:/home/tiantian:/bin/csh

[Email protected] desktop]# ^c

[Email protected] desktop]#




7. Create the following user, group, and group memberships

Group with the name Admins

User Natasha, using admins as a subordinate group

User Harry, also use admins as a subordinate group

User Sarah, no interactive login system, and not a member of admins, Natasha,harry,sarah password is CentOS

1 #!/bin/bash

2 groupadd Admins

3 useradd-g Admins Natasha

4 useradd-g Admins Harry

5 Useradd-s/sbin/nologoin Sarah

6 echo "CentOS" | passwd--stdin Natasha

7 echo "CentOS" | passwd--stdin Harry

8 echo "CentOS" | passwd--stdin Sarah


Computer Demo


[Email protected] desktop]# Nano f1.xt

[email protected] desktop]# cat F1.XT

#!/bin/bash

Groupadd Admins

USERADD-G Admins Natasha

Useradd-g Admins Harry

Useradd-s/sbin/nologoin Sarah

echo "CentOS" | passwd--stdin Natasha

echo "CentOS" | passwd--stdin Harry

echo "CentOS" | passwd--stdin




This article from "11892658" blog, declined reprint!

Homework exercises After class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.