一、基本命令的学习
ls 的命令
[root@localhost ~]# ls
anaconda-ks.cfg  Desktop  install.log  install.log.syslog
Linux的命令格式:
命令    选项      命令的对象
输入命令后以回车执行
ctrl+c的组合键取消
Linux的命令严格区分大小写
[root@localhost ~]# ls /etc/sysconfig/
/etc/sysconfig 是ls这个命令的对象
[root@localhost ~]# ls -l /etc/sysconfig/
-l 在这里是ls命令的选项,选项作用是启用命令的一些特定的功能(非默认)。
[root@localhost ~]# ls -l
总计 52
-rw------- 1 root root  960 04-03 20:02 anaconda-ks.cfg
drwxr-xr-x 2 root root  4096 04-03 22:14 Desktop
-rw-r--r-- 1 root root 25841 04-03 20:02 install.log
-rw-r--r-- 1 root root  3671 04-03 20:01 install.log.syslog
[root@localhost ~]# ls -l -h
总计 52K
-rw------- 1 root root  960 04-03 20:02 anaconda-ks.cfg
drwxr-xr-x 2 root root 4.0K 04-03 22:14 Desktop
-rw-r--r-- 1 root root  26K 04-03 20:02 install.log
-rw-r--r-- 1 root root 3.6K 04-03 20:01 install.log.syslog
[root@localhost ~]# ls -lh
>>>>>>>##
在系统中获得命令使用帮助的方法:
1)ls --help
获得ls命令的常用帮助
[root@localhost ~]# ls -a
[root@localhost ~]# ls --all
通过命令的帮助获得-a 和--all的作用相同。
2)通过man命令来获得帮助
[root@localhost ~]# man ls
>>>>>>>##
Linux命令行中常用的快捷键:
Tab键 ====>命令和路径自动补全;
[root@localhost ~]# system-config-display
[root@localhost ~]# ls /etc/sysconfig/network-scripts/ifcfg-eth0
按照你输入的字符为开头自动补全,如果结果不唯一,按两下Tab键,例有可能的结果,如果唯一,就自动补全。
ctrl+l(这是L键) ====>清屏,等同于命令clear
ctrl+c  ====>不执行输入的命令
上下方向键 ====>回曾经输入过的命令
>>>>>>>###
cd的命令
切换工作路径。(进入指定的目录)
[root@localhost ~]# pwd
/root
查看我现在所在的目录。
[root@localhost ~]# cd /usr/share/doc
去到指定的doc目录,查看结果。
[root@localhost doc]# pwd
/usr/share/doc
理解Linux的倒树目录结构,以及相对路径和绝对路径的概念。
[root@localhost doc]# cd zip-2.31/
[root@localhost zip-2.31]# pwd
/usr/share/doc/zip-2.31
[root@localhost zip-2.31]# cd ..
[root@localhost doc]# pwd
/usr/share/doc
[root@localhost doc]# cd /usr/share/doc/zip-2.31/
[root@localhost zip-2.31]# pwd
/usr/share/doc/zip-2.31
[root@localhost zip-2.31]# cd ..
[root@localhost doc]# cd /zip-2.31
-
bash: cd: /zip-2.31: 没有那个文件或目录
cd的其他用法:
cd ..  ===>去到上一级目录
cd .  ===>.是表示当前目录
cd    ===>去到用户的家目录
[root@localhost doc]# cd
[root@localhost ~]# pwd
/root
cd -  ===>去到上一次工作的目录
>>>>>>>>>
关于文件的权限的概念 (考点)
[root@localhost ~]# ls -l /root
总计 52
-rw-------      1      root    root    960 04-03 20:02 anaconda-ks.cfg
drwxr-xr-x      2      root    root    4096 04-03 22:14 Desktop
-rw-r--r--      1      root    root  25841 04-03 20:02 install.log
-rw-r--r--      1      root    root    3671 04-03 20:01 install.log.syslog
文件类型和权限  链接数  拥有者  所属组  文件大小  时间    文件名
文件类型:
-  表示普通文件
d  表示目录
b  表示块设备文件
[root@localhost ~]# ll /dev/sda
brw-r----- 1 root disk 8, 0 04-03 22:04 /
还有其他文件类型暂不作介绍。
文件拥有者和所属组:
user :  group
更改文件的拥有者和所属组:(考点)
[root@localhost ~]# useradd zhangsan
在系统中创建一个用户,稍后详细介绍该命令。
[root@localhost ~]# groupadd training
在系统中创建一个组。
linux命令查看文件夹大小[root@localhost ~]# ls -l install.log
-
rw-r--r-- 1 root root 25841 04-03 20:02 install.log
[root@localhost ~]# chown zhangsan install.log
更改用户
[root@localhost ~]# ls -l install.log
-rw-r--r-- 1 zhangsan root 25841 04-03 20:02 install.log
[root@localhost ~]# chgrp training install.log
更改组。
[root@localhost ~]# ls -l install.log
-rw-r--r-- 1 zhangsan training 25841 04-03 20:02 install.log
文件的权限基本概念:
[root@localhost ~]# ls -l install.log
-
rw-r--r-- 1 zhangsan training 25841 04-03 20:02 install.log
9个权限位,每三个为一组,分别表示拥有者,所属组,其他人的权限。
r表示读,w表示写,x表示执行,-表示没有相关权限。
rw-r--r-- 表示:拥有者rw- (zhangsan可读可写) 所属组 r-- (training只读) 其他人 只读。
更改文件的权限:(考点)
[root@localhost ~]# chmod  u+x,g+w,o+x install.log
[root@localhost ~]# ls -l install.log
-rwxrw-r-x 1 zhangsan training 25841 04-03 20:02 install.log
其他灵活的写法:
[root@localhost ~]# chmod g-w install.log
[root@localhost ~]# chmod o=r install.log
用8进制来表示权限:
r = 4  w = 2  x = 1
[root@localhost ~]# ll install.log
-rwxr--r-- 1 zhangsan training 25841 04-03 20:02 install.log
该权限用8进制来表示是“ 744 ”
思考:将install.log的权限更改为拥有者可读可写可执行,所属组可读可执行,其他人没有权限。
[root@localhost ~]# chmod 750  install.log
[root@localhost ~]# ls -l install.log
-rwxr-x--- 1 zhangsan training 25841 04-03 20:02 install.log
>>>>>>>>>>>
文件和目录的创建,复制,删除,移动,重命名的操作:(考点)
创建一个目录:mkdir
[root@localhost ~]# mkdir /test
[root@localhost ~]# ls -l -d /test
drwxr-xr-x 2 root root 4096 04-04 00:03 /test
注意mkdir不能创建多级目录,除非加上-p的参数。
创建一个空文件:touch
[root@localhost ~]# cd /test/
[root@lo
calhost test]#
[root@localhost test]# ls -l
总计 0
-
rw-r--r-- 1 root root 0 04-04 00:
复制一个文件:cp
[root@localhost test]# cp /fig /test/
[root@localhost test]# ls /test
<  fig
注意:cp 命令不能复制目录,除非加上一个-r的参数。
在复制文件的过程可以重命名,例:
[root@localhost test]# cp /fig /f.backup
[root@localhost test]# ls /test
<  f.backup  fig
移动(剪切)文件:mv
[root@localhost test]# fig  /root/
[root@localhost test]# ls
<  f.backup
[root@localhost test]# ls /root/
<          Desktop      install.log.syslog
anaconda-ks.cfg  install.log  fig
注意:mv可以进行文件重命名的操作。
[root@localhost test]# ls
<  f.backup
[root@localhost test]# bb.txt
[root@localhost test]# ls
<  f.backup
删除文件和目录:rm
[root@localhost test]#
rm:是否删除 一般空文件 “bb.txt”? y
[root@localhost test]# ls
注意:rm 不能删除目录,除非加上一个-r参数。还以使用-f的参数不提示强制删除。
[root@localhost ~]# rm -rf /test
注意:rm -rf 这条命令具有超级牛力。如果这条命令后面的对象搞错了(比如说/),那后果请你想象一下。
>>>>>>>>>###
操作题:请考生在系统的根目录下创建一个考生文件夹,以姓名的全拼命名,然后复制/fig文件到该目录下。进入考生目录,创建一个空文件,改变其拥有者为考生姓名,组为exam,改变其权限为拥有者可读可写可执行,组为可读,其他人可读。
在该考生文件夹内在创建一个子目录为exam,将刚刚复制过来的fig移动到exam目录中,并改名为fig.backup
答案:
[root@localhost ~]# mkdir /wangwu    #创建考生目录
[root@localhost ~]# cp /fig /wangwu/    #复制指定文件到考生目录
[root@localhost ~]# cd /wangwu/  #进入考生目录
[root@localhost wangwu]# ls        #查看考生目录内的文件
[root@localhost wangwu]#     #在当前目录下创建一个空文件
[root@localhost wangwu]# useradd wangwu  #添加一个要求的用户wangwu
[root@localhost wangwu]# chown   #将的拥有者改为wangwu
[root@localhost wangwu]# ls -    #查看一下操作的结果
-rw-r--r-- 1 wangwu root 0 04-04 00: 
[root@localhost wangwu]# groupadd exam    #按要求添加一个组exam
[root@localhost wangwu]# chgrp   #将的组改为exam
[root@localhost wangwu]# chmod   #将的权限更改为要求的权限
[root@localhost wangwu]# mkdir exam  #在当前目录下创建一个目录exam
[root@localhost wangwu]# fig fig.back 
#移动fig
>>>>>>>>>##
查看文件的内容:cat less head tail (考点)
[root@localhost ~]# ls /etc/passwd
/etc/passwd
ls命令是查看有没有这个文件。
[root@localhost ~]# cat /etc/passwd
cat命令是查看文件里面的内容。
[root@localhost ~]# less /etc/passwd
less命令和cat的功能一样,但支持用方向键上下翻页,按q键退出。
[root@localhost ~]# head -3 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
head命令是查看文件的开头的n行(这里是查看/etc/passwd 的头3行)
[root@localhost ~]# tail -3 /etc/passwd
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
zhangsan:x:500:500::/home/zhangsan:/bin/bash
wangwu:x:501:502::/home/wangwu:/bin/bash
tail命令的作用是查看文件的末n行。
[root@localhost ~]# tail -3 /etc/passwd >/
这个>号在这里的作用是将前面的命令输出的结果保存到文件中去。考试中有这样的要求。
[root@localhost ~]# cat /
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
zhangsan:x:500:500::/home/zhangsan:/bin/bash
wangwu:x:501:502::/home/wangwu:/bin/bash
[root@localhost ~]# head -3 /etc/passwd >>/
这里使用两个>>号的作用是在文件中追加新的内容,防止新的内容覆盖上一题的操作结果。
[root@localhost ~]# cat /
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
zhangsan:x:500:500::/home/zhangsan:/bin/bash
wangwu:x:501:502::/home/wangwu:/bin/bash
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
>>>>>>>>>>####
查看系统信息:free df date  (考点)
查看系统内存使用状况:
[root@localhost ~]# free -m
total      used      free    shared    buffers    cached
Mem:          788        765        23          0        68        551
-/+ buffers/cache:        145        643
Swap:        1027          0      1027
free的命令是查看系统内存,-m表示用M为单位显示大小。
[root@localhost ~]# df -h
文件系统              容量  已用 可用 已用% 挂载点
/
dev/sda2            9.7G  1.9G  7.4G  21% /
/dev/sda1              99M  12M  83M  12% /boot
df的命令是查看系统的磁盘使用情况,-h的参数是显示单位。
[root@localhost ~]# date
2011年 04月 04日 星期一 01:16:16 CST
查看时间
[root@localhost ~]# date -s "2011-4-3 17:16"
2011年 04月 03日 星期日 17:16:00 CST
修改时间。
>>>>>>>>>>>#
操作题2:查看/etc/passwd的前10行,将查看到结果记录到/中;查看/fi
g的后10行,将查看到结果追加到/中;查看系统的硬盘和内存的使用
状况,并将结果记录到/中;查看当前的时间。
首先确定有了/wangwu这个文件夹。
[root@localhost ~]# head -10 /etc/passwd >/  #看前10行并保存;
[root@localhost ~]# tail -10 /fig >>//  #看后10后并保存;
[root@localhost ~]# cat /
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/etc/news:
#
# Decompress with given decompressor when input file has given extension
# The command given must act as a filter.
#
.gz            /usr/bin/gunzip -c
.bz2            /usr/bin/bzip2 -c -d
.
z
.Z              /bin/zcat
.F
.Y
验证作的效果。
[root@localhost ~]# df -h >/  #看硬盘使用状况并保存;
[root@localhost ~]# free -m >>/  #看内存使用状况并保存;
[root@localhost ~]# cat /
文件系统              容量  已用 可用 已用% 挂载点
/dev/sda2            9.7G  1.9G  7.4G  21% /
/dev/sda1              99M  12M  83M  12% /boot
tmpfs                395M    0  395M  0% /dev/shm
/dev/hdc              2.9G  2.9G    0 100% /media/RHEL_5.5 i386 DVD
total      used      free    shared    buffers    cached
Mem:          788        765        23          0        68        551
-/+ buffers/cache:        144        643
Swap:        1027          0      1027
验证做的效果。
[root@localhost ~]# date "+%F %H:%M" #看当前时间,注意我自定义了时间输出格式哟。
2011-04-03 17:27
>>>>>>>>>>>##
在系统进行查的操作:which  locate  find (考点)
[root@localhost ~]# which mkdir
/bin/mkdir
which命令主要是用来查系统中的可执行的命令是放在哪个文件夹里面。
[root@localhost ~]# fig
/fig
/usr/share/man/bg/
locate命令主要是用来查系统中文件,出符合你指定的文件名(包含)的文件。因为该命令是通过系统的数据库进行查,所以速度比较快。
[root@localhost ~]# find /  -fig
/fig
/fig
find的命令是用来查系统中的文件,通过对全盘扫描进行搜索,所以速度较慢,但功能强大。
其格式为: find    在哪个目录查(/表示在整个系统中查) 查条件  匹配内容
[root@localhost ~]# find /wangwu/  -type f -user wangwu
/
上面的命令表示在/wangwu目录中查拥有者是wangwu且文件类型是普通文件的文件。
注意:find支持的查条件很多(比如说,根据文件

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。

linux命令题目
« 上一篇
虚拟机常用命令
下一篇 »

发表评论