Linux Common command-related exercises:
1, only show how many lines of/etc/inittab file, other information does not display:
#wc-L/etc/inittab | Cut-d '-f1
[Email protected] ~]# Wc-l/etc/inittab | Cut-d '-f1
26
2. The number of files in the statistics/usr/bin directory:
#ls/usr/bin | Wc-l
[Email protected] ~]# Ls/usr/bin | Wc-l
1748
3. Take out the shell of all the users on the current system and request that each shell be displayed only once and in order;
#cut-D:-f7/etc/passwd |sort-u
[Email protected] ~]# cut-d:-f7/etc/passwd |sort-u
/bin/bash
/bin/sync
/sbin/halt
/sbin/nologin
/sbin/shutdown
4, thinking: How to display the content type of each file in the/var/log directory?
[[email protected] ~]# file/var/log/* or file ' Ls/var/log '
/var/log/anaconda.ifcfg.log:ascii text
/var/log/anaconda.log:utf-8 Unicode 中文版 Text
/var/log/anaconda.program.log:ascii 中文版 text, with very long lines, with overstriking
5. Take out the sixth line of the/etc/inittab file;
[Email protected] ~]# head-6/etc/inittab | TAIL-1 takes the first six lines and then takes the last line through the pipe
#
6. Take out the user name and shell of the 9th user in the/etc/passwd file.
Display to the screen and save it to the/tmp/users file;
[Email protected] ~]# tail-9/etc/passwd | head-1 | Cut-d:-f1,7|tee/tmp/users
Rpcuser:/sbin/nologin Tee content is displayed on the screen and saved to the specified directory
7. Display all files starting with PA in/etc directory, and count the number of them;
[Email protected] ~]# ls-d/etc/pa* | Wc-l
4
8, do not use a text editor, add alias Cls=clear a line of content to the current user's. bashrc file;
[Email protected] ~]# echo "Alias Cls=clear" >>.BASHRC
[Email protected] ~]# tail. BASHRC
Alias rm= ' Rm-i '
Alias cp= ' Cp-i '
Alias mv= ' Mv-i '
# Source Global Definitions
if [-F/ETC/BASHRC]; Then
. /etc/bashrc
Fi
Alias Cls=clear
Linux common command exercises: WC, cut, |, tee, tail