linux上机考试题(Linux基础)

一、试完成下列小题:

(1)、在根目录下创建目录aa。((Create directory aa in the root directory.)

cd /->mkdir aa

(2)、在根目录下创建一个文件cc,然后把cc拷贝到aa下。(Create a file cc in the root directory and copy cc to aa.)

touch cc->cp cc aa

(3)、更改目录aa的权限为777,然后查看是否更改成功。(Change the permission of directory aa to 777, and check whether the change is successful.)

chmod 777 aa->ls -l

(4)、创建用户bob,更改目录aa的拥有着和组群都为bob,然后查看是否更改成功 。(Create user bob, change the directory aa owner and group to BOB, and check whether the change is successful.)

   bob aa->chgrp bob aa->ls -l

(5)、删除该目录以及该目录下的所有文件并不作提示?(Delete this directory and all files in this directory without prompt?

rm -rf aa

二、试完成下列小题:

(1)、用命令把当前工作目录切换到"/root",并用命令查看是否切换成功。(Use the command to change the current working directory to "/root", and use the command to check whether the switch is successful.)

cd /root->pwd

(2)、用命令新建文件"testfile",然后为其创建软链接和硬链接文件,查看其inode编号、文件类型、文件权限、连接计数、大小等属性。(Create a new file "testfile" with the command, and then create soft and hard linked files for it. Check INODE number, file type, file permissions, connection count, size and other properties.)

touch testfile->ln testfile test->ln –s testfile file-> ls –l

(3)、创建文件file1,并将file1改为file2,然后将文件file1和文件file2移动到目录/tmp下,并查看是否移动成功。(Create file file1 and change file1 to file2, then move file file1 and file file2 to the directory/TMP, and check whether the move is successful.)

touch file1->cp file1 file2->mv file1 file2 /tmp->ls /tmp

三、试题成下列小题:

(1)、查找系统命令pwd指令文件的位置(Find the location of the system command PWD instruction file)

which pwd

(2)、查找whereis文件,且只将二进制文件查找出来(Find the file whereis, and only find the binary file)

whereis -b whereis

(3)、查找和pwd相关的所有文件(Find all files related to PWD)

locate pwd

(4)、搜索etc目录下所有以sh开头的文件(search etc directory for all files beginning with sh)

locate /etc/sh

(5)、建立目录/tmp/a/b/c,若不存在目录/tmp/a及/tmp/a/b,则自动建立。(create directory /tmp/a/b/c, if it is not exist of /tmp/a and /tmp/a/b, automatically set up)

mkdir -p /tmp/a/b/c

四、用vim编辑器在/tmp下新建一个文件名aa插入如下内容:(Using the Vim editor, create a new filename aa under/TMP and insert the following)

abcdefg

1234567

ABCDEFG

zyxwvuts

7654321

ZYXWVUTS 

使用vim创建新文件:

vim /tmp/aa

i 键切换为输入模式

输入以下内容:

abcdefg

1234567

ABCDEFG

zyxwvuts

7654321

ZYXWVUTS

完成录入后,先按Esc键回到命令模式,再输入 :wq 保存并退出编辑器

(1)、显示文档每一行行号(Display the number of each line of the document)

方法一:

在末行模式下输入set nu”即可显示文件的行号

方法二:

如果要让vim编辑器永久显示行号,需要修改vim编辑器对应的配置文件vimrc。一般在当前用户的根目录下创建vimrc文件,命令如下:

sudo su#登录root用户

vim,vimrc#创建vimrc文件

[.vimrc]文件中添加如下内容

:set number

(2)、删除第二行中的第3到6个字符并撤销操作(Delete the third to sixth characters in the second line and undo the operation)

方法一:
删除光标所在处的字符,点击一次x键只能删除一个字符。

方法二:

删除光标所在处后的4个字符(nx),输入4x

撤销方法:ctrl+R

(3)、复制第二行,并粘贴到第6行(Copy the second line and paste it into line 6)

光标放在第二行

小写yy复制单行

P粘贴在光标下一行

五.用vim编辑器在/tmp下新建一个文件名bb插入如下内容:(Using the Vim editor, create a new filename bb under/TMP and insert the following:)

abcdefg

1234567

ABCDEFG

zyxwvuts

7654321

ZYXWVUTS

使用vim创建新文件:

vim /tmp/bb

i 键切换为输入模式

输入以下内容:

abcdefg

1234567

ABCDEFG

zyxwvuts

7654321

ZYXWVUTS

完成录入后,先按Esc键回到命令模式,再输入 :wq 保存并退出编辑器

(1)、删除第2至6行中的第3值6个字符(Delete the third value of 6 characters from lines 2 to 6)

光标放在第2行第3个字符-----ctrl+v---光标移到第6个字符再移至第6----d

(2)、在第4行插入空白行,并输入“ZYX127”;(Insert a blank line in the fourth line and enter "ZYX127")

光标放在第3行末尾---按小写o—输入“ZYX127”

(3)、在第2行到第7行中查找“127”,并用字符串“hello”替代。(Find "127" in lines 2-7 and replace it with the string "hello".)

2,7 s /127/hello/g

(4)、在vim编辑器中运行date命令,并把结果插入到文档的第5行,然后并保存此文件并退出vim编辑器(Run the date command in the Vim editor and insert the result into line 5 of the document. Then save the file and exit the Vim editor)

光标放在第4行末尾---:r!date

六、新建一个分区并挂载到文件夹mz(Create a new partition and mount it into the folder mz)

(1)、新建硬盘分区vda4。(Create a new hard disk partition sda4.)

第一步:进入fdisk指令交互模式:fdisk /dev/sda

第二步:使用n 命令创建新的硬盘分区:n(如果sda4已经存在,先删除dd ,然后按n ,p,)

第三步:使用P命令显示分区列表:p

第四步:使用w命令保存并退出:w`

reboot 重启电脑

(2)、对vda4分区格式化。(Format sda4 partition.)

格式化:mkfs -t ext4 /dev/sda4

(3)、在根目录下新建一个目录mz,并将vda4分区挂载到目录mz上。(Create a new directory mz in the root directory, and mount the sda4 partition on the directory mz.)

在桌面上创建目录:mkdir cz

挂载:mount -t ext4 /dev/sda4 cz

ls cz

七、对文件和目录解压缩(Unzip files and directories)

(1)、在根目录下创建目录bb和文件x、y、z;(Create directory bb and files x, y, z in root directory)

cd /

mkdir bb

touch x

touch y

touch z

ls

(2)、对这x、y、z三个文件进行压缩和解压操作;(Compress and decompress the x, y and z files)

gzip x y z

ls

gunzip x.gz y.gz z.gz

ls

(3)、把x、y、z三个文件移动到bb下;(Move x, y and z files to bb)

mv x y z bb

(4)、对目录bb进行打包并压缩并解包解压缩;(Pack and compress directory bb and unpack and uncompress it)

压缩的时候可以任选一种gzip,bzip2 You can choose either gzip or bzip2 for compression

tar -czvf aaa.tar.gz bb

rm -rf bb

tar -xzvf aaa.tar.gz

八、使用rpm命令进行软件包的安装、查询、删除(Use RPM command to install, query and delete software packages)

(1)、切换到root下,手动将要安装的vsftpd软件包所在的文件夹packages的vsftpd-2.2.2-11.el6.i686.rpm复制到root文件夹下。(Copy VSFTPD Packages VSFTPD -2.2.2-11.el6.i686. RPM to root: Packages VSFTPD -2.2.2-11.el6.i686. RPM to root: Packages VSFTPD -2.2.2-11.el6.i686. RPM)

cd

(2)、使用rpm查询软件包vsftpd是否安装到当前系统中,如果没有安装,则安装。(Use RPM to check whether the package VSFTPD is installed in the current system. If not, then install it.)

rpm -q vsftpd

(3)、使用rpm安装软件包vsftpd。(Install the package VSFTPD using RPM.)

rpm -ivh vs

(4)、删除软件包vsftpd。(Delete the package VSFTPD.)

rpm -e vsftpd

九、创建用户和组群(Create users and groups)

(1)、创建用户rjxy

useradd rjxy

(2)、创建用户test,并设置该用户的UID号为1050;(Create user test and set UID number of this user to 1050)

Useradd test -u 1050

(3)、创建用户abc并设置该用户的宿主目录为/home/xyz;(Create user ABC and set the host directory of user as /home/xyz)

useradd -d /home/xyz abc

cat /etc/passwd | grep abc

(4)、创建用户new,并指定该用户的主组群为rjxy组群;(Create user new, and specify the primary group of this user as rjxy group)

useradd -g rjxy new

(5)、创建名为guess的组群,并设置GID为1060;(Create a group named guess and set the GID to 1060)

useradd -d /home/xyz abc

cat /etc/passwd | grep abc

(6)、修改用户test的登录名为doc。(alter user test login name doc)

vim /etc/passwd

找到旧用户名改为新用户名,但是 /home/旧用户名 不能更改,若更改重启后,便登陆不了系统了。

vim /etc/shadow

找到旧用户名改为新用户名

十、 磁盘配额(Disk quota)

(1)、对dev/sda4配置磁盘配额,使用vim编辑器修改/etc/fstab文件。(Configure the disk quota on dev/sda4 and modify the /etc/fstab file using Vim editor.)

 mkdir /home/quota

vim /etc/fstab

/dev/sda4 /home/quota ext4 defaults,usrquota,grpquota 0 0

(2)、重新挂载文件系统以使修改生效。(mount the file system again for the changes to take effect.)

init 6 重新启动操作系统

mount -s 看是否挂载成功

(3)、在/home/quota目录下创建配额文件,为启用了配额的文件系统生成当前次盘用量表。(Create a quota file in the /home/quota directory, and generate the current file size for the file system with quota enabled.)

quotacheck -acug

setenforce 0

ls -l /home/quota/

quotacheck -avug

(4)、执行edquota rjxy命令,把用户rjxy的软硬限制分别为100000和200000,即软限制100KB,硬限制200kB。(Executing the edquota rjxy command to set the hard and soft limits of the user rjxy to 100000 and 200000 respectively, namely, the soft limit of 100KB and the hard limit of 200KB.)

useradd rjxy

edquota rjxy

最后一行修改

/dev/sda4 0 100000 200000 0 0 0

(5)、启动磁盘配额,为rjxy用户设定权限,可以对/hone/quota目录进行写操作。(Start disk quotas and set permissions for the rjxy user to write to the /hone/quota directory)

chmod 777 /home/quota

(6)、切换到rjxy用户并进入/home/quota目录。(Switch to rjxy and enter /home/quota directory.)

su rjxy

cd /home/quota/

pwd

(7)、创建一个大小为300M的空文件。(Create an empty file with size 300M)

dd if+/dev/zero of=testfile bs=300M count=1

十一:bash变量

(1)、设置一个变量名为name,其变量值为tom,然后再为变量name增加内容andjack。(Set a variable named name with the value of tom and add content to name andjack.)

name=tom--->回车

name="$name"and jack---->回车

(2)、自定义一个变量x,并为其赋值tom,并转换成环境变量,然后换一个shell环境,然后输出变量x的值。(Customize a variable x, assign the value Tom to it, and change it to an environment variable, then change to a shell environment, and output the value of the variable x.)

x=tom--->回车

export x---->回车

bash---->回车

echo $x

(3)、为y变量读取来自键盘输入的变量值为tom,并且输入时会有提示内容“please input your name:“。(Read the variable value of TOM from the keyboard for Y variable, and there will be prompt content "Please input your name:" when input.)

read -p "please keyin your name:" y---->回车----->tom---->回车

(4)、声明一个变量z为整数型变量,然后为其赋值56,然后并且输出变量的内容。(Declare a variable z as an integer variable, assign the value 56 to it, and print the contents of the variable.)

declare -i z

z=56

十二:数据流重定向和管道命令(Data flow redirection and piping commands)

(1)、先进入/root目录下,然后查看文件test1的标准输出时利用标准输出重定向符号,里面并且写上两行字符分别为linux!和world!,然后查看文件test2的标准输出重定向符号并把test1的内容作为test2的输入,然后查看文件test2。然后再把test1的内容标准输出到test2中并且不会覆盖其原来的内容。(When entering the /root directory and looking at the stdout of file test1, use the stdout redirect symbol, and write two lines of characters in it: Linux! And the world!, then look at the standard output redirection symbol of file test2 and take the contents of test1 as input to test2, then look at file test2. The contents of test1 are then standardised out to test2 without overwriting the original contents.)

cd-->回车

cat > test1--->回车-->linux!-->回车-->world-->回车--->ctrl+d

cat > test2 < test1

cat test1 >> test2-->回车

(2)、利用last指令列出当前与过去登录的用户信息同时利用cut指令截取每行的第1-6个字符出来。(Use the last command to list the information of current and past logged users. At the same time use the cut command to intercept the 1st to 6th characters of each line.)

last | cut -c 1-6-->回车

(3)、利用grep命令把/etc/passwd文件中包含关键字符”root“的行搜索出来。(Search for lines in /etc/passwd containing the key character "root" using grep.)

cat /etc/passwd | grep 'root'--->回车

十三:历史命令和命令执行控制符号&&与||( History command and command control symbol && and | |)

(1)、列出当前系统中记录的所有历史记录,然后再立即清空当前shell所有历史命令的记录(List all the history records of the current system, and then immediately clear the record of all the history commands of the current shell)

history-->回车

history -c------->回车

(2)、判断/tmp目录下是否有tt文本文件,如果有就输出”exist“,如果不存在则输出”not exist“。(Determine whether there is a TT text file in the/TMP directory. If there is, output "EXIST"; if not, output "NOT EXIST".)

ls /tmp/tt && echo "exist" || echo "not exist"---->回车

十四:正则表达式(Regular expression)

(做下面的题之前首先start.txt文本文件拷贝到/root目录下,并把当前目录调为/root。 Start.txt file in /root directory and change the current directory to /root.

(1)、从文件start.txt中查找含When或者Then的行,要显示行号。(Find a line containing WHEN or THEN in the file start.txt, and display the line number.)

grep -n '[WT]hen' start.txt--->回车

(2)、从文件start.txt中中查找以大写字母开头的行和查找不是以大写字母开头的行,然后再查找以“.”结尾的行。(from a file start.txt in the search for begin with a capital letter in the line and find not begin with a capital letter, and then search for ". "at the end of the line.)

grep -n '^[A-Z]' start.txt---->回车

grep -n '^[^A-Z]' start.txt---->回车

grep -n '\.$' start.txt---->回车

(3)、从文件start.txt中查找包含至少含有两个t的字符串所在的行。(select  from start.txt where a string containing at least two 't' is found)

grep -n 'tt*' start.txt---->回车

(4)、使用sed工具从文件start.txt中删除第2到4行的内容。(Delete lines 2 to 4 from the file start.txt with the sed tool)

nl start.txt | sed '2,4d'----->回车

(5)、使用sed工具把start.txt中的2~4行替换成“hi tom”。(Use the sed tool to replace lines 2 to 4 in start. TXT with "Hi Tom".)

nl start.txt | sed '2,4c hi tom'---->回车

  • 10
    点赞
  • 149
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值