本文接 《shell 常见面试题及答案(3)》
七、
一、命令部分
1.新建一个用户user,密码设为123456,并将其加到root组。写出所用命令。
Loong:/home/julius# groups julius
julius
Loong:/home/julius# groups root
root fileshare
Loong:/home/julius# usermod -g root julius
组在前,用户在后
Loong:/home/julius# groups julius
root
Loong:/home/julius#
一,组操作
1,创建组
groupadd test
增加一个test组
2,修改组
groupmod -n test2 test
将test组的名子改成test2
3,删除组
groupdel test2
删除 组test2
4,查看组
a),查看当前登录用户所在的组 groups (用户名)
2.将当前计算机的IP地址设为192.168.1.123,子网掩码为255.255.255.0。写出所用命令。
ifconfig eth0 192.168.1.123 netmask 255.255.255.0
3.你是公司的Linux服务的管理员。你使用vi编缉/etc/inittab文件时,在命令模式下查询shutdown字符串,使用的命令。
/shutdown 回车
4.显示当前系统的日期和时间命令。
5.查看命令sort的帮助文件,写出所用命令。
man sort
info sort
sort --help
6.统计/etc/passwd文件的字节数和行数,写出所用命令。
7.分屏显示/etc/httpd/conf/httpd.conf文件的命令。
:vsplit
:vsplit xxx(要打开的文件名)
水平切割:
:split
:split xxx(要打开的文件名)
:new(在新窗口创建文件)
<CTRL+W> k:跳转到上面的窗口 (若为大写K,则是把当前窗口调至上方)
<CTRL+W> j:跳转到下面的窗口 (类似于上)
垂直切割:
:vsplit
:vsplit xxx(要打开的文件名)
:vnew(在新窗口创建文件)
:only 取消分屏
<CTRL+W> h:跳转到左边的窗口 (若为大写H,则是把当前窗口调至左方)
<CTRL+W> l:跳转到右边的窗口 (类似于上)
<CTRL+W> w:在窗口之间跳转
<CTRL+W> +:扩大窗口 (或在当前窗口位置,输入命令:res +9)
<CTRL+W> -:缩小窗口
8.将hello!写入 /home/wang/test.txt 的命令(vi及vim编辑器除外)。
9.让named守护进程运行在级别3,5的命令。
# telinit 3 #用init也可以
# telinit 5 #不懂named守护进程是啥进程,没有找到
守护进程,也就是通常说的Daemon进程,是Linux中的后台服务进程。它是一个生存期较长的进程,通常独立于控制终端并且周期性地执行某种任务或等待处理某些发生的事件。守护进程常常在系统引导装入时启动,在系统关闭时终止。Linux系统有很多守护进程,大多数服务都是通过守护进程实现的,同时,守护进程还能完成许多系统任务,例如,作业规划进程crond、打印进程lqd等(这里的结尾字母d就是Daemon的意思)。
由于在Linux中,每一个系统与用户进行交流的界面称为终端,每一个从此终端开始运行的进程都会依附于这个终端,这个终端就称为这些进程的控制终端,当控制终端被关闭时,相应的进程都会自动关闭。但是守护进程却能够突破这种限制,它从被执行开始运转,直到整个系统关闭时才退出。如果想让某个进程不因为用户或终端或其他地变化而受到影响,那么就必须把这个进程变成一个守护进程。
常用的守护进程简单介绍:
Kudzu(硬件检测) sshd(远程连接) inetd(网络连接) ldap(目录访问协议)
Linux运行等级介绍:
最常用的是3,5
run level 0:是作关机用的,一开机就会作关机的动作。
run level 1:都是Single user mode模式,只允许root账号登录,主要是作一些系统维护的工作。
run level 2:可以使所有的用户登录,但不会启用NFS working,也就是没有网络功能
run level 3:可以使所有用户登录,并拥有完整的功能。包含run level 2没有的功 能,但是开机后是用文本模式
run level 4 :使用者自己定义,但是默认情况下和run level 3完全相同,
run level 5:和run level 3几乎一样,唯一的不同是开机后是图形界面,
run level 6:重启。开机后立刻重启
显示系统当前运行级别:
# runlevel 查看运行级别。
改变系统运行级别:
# init [0123456] 更改运行级别。(所更改的内容保存在内存中,关机或重启后还原)
系统服务程序在各运行级别的启动状态:
查看服务启动状态:
# Chkconfig --list 查看当前系统中所有进程。
# chkconfig --list 查看单个进程。
设置独立服务的启动状态:
Chkconfig --level ]
例:# chkconfig --level 234 init off 将init进程设置为在2 3 4运行级别为off。
10.更改用户zhang的登录shell为/sbin/nologin的命令。
# usermod –s /sbin/nologin yangang
11.查看当前linux服务器的主机名的命令。
12.查看当前主机的路由的命令。
13.配置当前主机的默认网关为192.168.2.254的命令。
# route add default gw 192.168.2.254
14.连续ping目的IP为192.168.2.245为10次的的命令。
15.查看当前主机TCP协议连接情况的命令。
NETSTAT(8) Linux Programmer's Manual NETSTAT(8)
NAME
netstat - Print network connections, routing tables, interface statistics, masquerade con-
nections, and multicast memberships
SYNOPSIS
netstat [address_family_options] [--tcp|-t] [--udp|-u] [--raw|-w] [--listening|-l]
[--all|-a] [--numeric|-n] [--numeric-hosts] [--numeric-ports] [--numeric-users] [--sym-
bolic|-N] [--extend|-e[--extend|-e]] [--timers|-o] [--program|-p] [--verbose|-v] [--continu-
ous|-c]
netstat {--route|-r} [address_family_options] [--extend|-e[--extend|-e]] [--verbose|-v]
[--numeric|-n] [--numeric-hosts] [--numeric-ports] [--numeric-users] [--continuous|-c]
netstat {--interfaces|-i} [--all|-a] [--extend|-e[--extend|-e]] [--verbose|-v] [--pro-
gram|-p] [--numeric|-n] [--numeric-hosts] [--numeric-ports] [--numeric-users] [--continu-
ous|-c]
netstat {--groups|-g} [--numeric|-n] [--numeric-hosts] [--numeric-ports] [--numeric-users]
[--continuous|-c]
netstat {--masquerade|-M} [--extend|-e] [--numeric|-n] [--numeric-hosts] [--numeric-ports]
[--numeric-users] [--continuous|-c]
netstat {--statistics|-s} [--tcp|-t] [--udp|-u] [--raw|-w]
16.打包并压缩/etc目录的命令。
17.测试httpd是否安装的命令。
# rpm -q httpd
18.卸载named软件包的命令。
# rpm –e named
19.查看月历并将内容追加到文件/dd中的命令。
CAL(1) BSD General Commands Manual CAL(1)
NAME
cal, ncal - displays a calendar and the date of easter
SYNOPSIS
cal
[-3jmy] [[month] year]
ncal [-jJpwy] [-s country_code] [[month] year]
ncal [-Jeo] [year]
20.查看当前目录的命令。
Pwd或ls
21.显示历史命令表的所有内容的命令。
history
22.将/etc/passwd的内容追加到文件aaa中的命令。
cat /etc/passwd >>aaa
23.查看/etc/passwd文件的前10行的命令。
head -n 10 /etc/passwd
24.查看/etc/vsftpd/vsftpd.conf的后10行的命令。
tail -n 10 /etc/vsftpd/vsftpd.conf
25.重启samba服务的命令。
service smb restart
26.查看进程状态的命令。
ps -aux 或top
27.列出后台作业的命令。
jobs -l
28.将作业ID为5的后台作业放到前台的命令。
fg 5
29.停止ssh服务的命令。
service sshd stop
30.将name=wxstc配置为全局变量的命令。
export name=wxstc
31.重启linux服务器的命令。
shutdown -r now
reboot
32.要给文件file1加上其他人可执行属性的命令。
chmod o+x file1
33.为了达到使文件sudent.txt的所有者有读(r)和写(w)的许可,而其他用户只能进行只读访问的命令。
chmod u=rw,o=r student.txt
34.把大写字母转换为小写字母的命令。
tr 'A-Z' 'a-z'
35.显示操作系统核心版本详细信息的命令。
uname -a
36.将新建文件权限设置为600的命令。
umask 600 filename
umask命令的一般格式:
umask [选项] [
掩码] 该命令用来设置限制新文件权限的掩码。当新文件被创建时,其最初的权限由文件创建掩码决定。用户每次注册进入系统时,umask命令都被执行,并自动设置掩码改变默认值,新的权限将会把旧的覆盖。 选项及其含义如下。 -S:显示当前的掩码。 umask是从权限中“拿走”相应的位,且文件创建时不能赋予执行权限
umask设置了用户创建文件的默认 权限,它与chmod的效果刚好相反,umask设置的是权限“补码”,而chmod设置的是文件权限码。
37.从IP地址查找域名或从域名来查找IP地址应使用什么命令。
host
38.如何查看用户zhang属于哪个组。
cat /etc/group
39.假如当前系统是在 level 3 运行,不重启系统就可转换到 level 5 运行的命令。
telinit 5
40.查看Linux的启动信息的命令。
dmesg
41.创建一个以自己姓的拼音缩写为名的用户。
useradd lee
42.进入用户主目录,显示当前的路径。
cd /home/lee
pwd
43.复制文件/etc/group到用户主目录,文件名不变。
cp /etc/group /home/lee
44.统计文件/etc/fstab的行数、单词数、字符数。
45.查看/etc/passwd文件的后5行。
ail -5 /etc/passwd
46.创建普通文件/home/abc。
touch /home/abc
47.修改/home/abc的属性为:属主具有一切权限,同组用户和其他用户具有可读可写的权限。
chmod 766 /home/abc
chmod u=rwx,go=rw /home/abc
48. 显示当前的时间。
date
49. 写出系统1分钟后关机的命令。
shutdown -t -s 60 #因系统不同参数有些差异
50. 启动ssh服务器。
service sshd start
56.显示2011年1月的日历。
57.建立文件/etc/group的符号链接文件/root/abc。
ln –s /etc/group /root/abc
-d, -F, --directory
allow the superuser to attempt to hard link directories (note: will probably fail due
to system restrictions, even for the superuser)
-f, --force
remove existing destination files
-n, --no-dereference
treat destination that is a symlink to a directory as if it were a normal file
-i, --interactive
prompt whether to remove destinations
-s, --symbolic
make symbolic links instead of hard links
-S, --suffix=SUFFIX
override the usual backup suffix
-t, --target-directory=DIRECTORY
specify the DIRECTORY in which to create the links
58.后台启动程序gedit。
/usr/bin/gedit &
67.写出30分钟后系统重启的命令。
shutdown –s –t 1800
77.设置当前时间设为15:00,显示当前系统时间。
date –s “15:00”
date
80.查看DHCP服务器的状态。
service dhcpd status
二、操作题
1. 某系统管理员需每天做一定的重复工作,请按照下列要求,编制一个解决方案:
(1)在下午4 :50删除/abc目录下的全部子目录和全部文件;
(2)从早8:00~下午6:00每小时读取/xyz目录下x1文件中每行第一个域的全部数据加入到/backup目录下的bak01.txt文件内。
利用crontab 编辑定时任务,举例设置每个4分钟重启一次如下:
2. 某学校内部既存在WINDOWS操作系统,又存在LINUX操作系统,为了方便资源共享,建立一台SAMBA服务器,其地址为192.168.0.5,建立std、teacher两个用户,同时设置其密码。
实践
3.富曼公司有2个部门,分别是研发部yf和车间cj.搭建公司WWW服务器,IP地址为192.168.2.6,公司域名为www.fuman.com,研发部域名为yf.fuman.com,车间域名为cj.fuman.com,要求根据以上域名在IP地址192.168.2.6上搭建基于域名的虚拟服务器,并且不允许192.168.2.245的IP访问研发部的网页。
实践
4.外语系老师为了共享教学资料,需要架设一个FTP服务器,允许所有老师以匿名方式登录FTP服务器,可以浏览文件、上传文件和创建文件夹,但不允许删除和修改文件。
实践
5.编写一个名为mul的脚本程序,参数为一个大于20的正整数。先检查参数是否符合要求。如果不符合要求,请给出提示;如果符合要求,分别输出其与1到10的乘积。
6.编写一个名为move的脚本程序,格式move <file1> <file2>。如果file1不存在,给出提示;否则移动file1至file2。
7.编写一个shell脚本,能够显示下面序列的前25个数字。0,1,1,2,3,5,8,13…,前二个数字之和为第三个数字,即著名的Fibonacci序列。
8.编写一个名为square的脚本程序,参数为一大于10的正整数。先检查参数是否符合要求。如果不符合要求,请给出提示;如果符合要求,输出从1到该正整数的平方值。
shell 面试题的归纳和整理就暂时到此,欢迎读者们提出自己的新解题方法和读后感;
下来再回顾下python的面试题或者内容了,很久没用了,忘的差不多了,呜呜..........................................