Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Small applications of cut, sort, grep and other commands in practical problems

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Count the number of users whose default shell is not / sbin/nologin in the / etc/passwd file, and display all the users.

This problem mainly uses cat, grep, cut, wc commands and pipes.

Cat / etc/passwd | grep-v'/ sbin/nologin' | cut-d ":"-f 1

Cat / etc/passwd | grep-v'/ sbin/nologin' | cut-d ":"-f 1 | wc-l

2. Find out the user name, UID and shell type of the maximum UID of the user

This question mainly examines the use of cat, cut, grep, sort and xargs commands.

First use cat / etc/passwd | cut-d ":"-f 3 | sort-n | tail-1 to remove the largest uid

Then use the grep command to find it, and use the cut command to make a cut that meets the requirements

Grep 65534 / etc/passwd | cut-d ":"-f 1meme 3jue 7

3. Count the number of connections to each remote host IP that is currently connected to this machine, and sort them from large to small

This problem mainly uses w, sort, uniq commands.

4. Write a script createuser.sh to achieve the following functions: use a user name as a parameter, if the user of the specified parameter exists, show its existence, otherwise add it; display information such as the id number of the added user

5. Write a script that generates the basic format of the script, including author, contact information, version, time, description, etc.

Create a .vimrc in the home directory

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report