终于开始接触Linux,现在是一个标准的菜鸟,那么就踏踏实实,一步一步开始进阶,希望我的博客慢慢可以给后来人带来帮助。

    废话少说,下面就是我所接触的Linux系统管理的一些基础命令,以及我个人添加的命令的释义,还望大大们多多指教。

  

一、Linux命令行基础


[[email protected] ~]# uname -r       //查看内核版本

[[email protected] ~]# uname -a       //查看内核相关详细信息

[[email protected] ~]# hostname          //查看主机名

localhost.localdomain

[[email protected] ~]# ifconfig          //查看网卡信息

[[email protected] ~]# ifconfig eth0             //查看eth0这块网卡的信息

[[email protected] ~]# cat /proc/cpuinfo           //查看CPU信息

[[email protected] ~]# cat /proc/meminfo              //查看内存信息

[[email protected] ~]# shutdown -h +15 'Host will be shutdown !!'           //将在15分后关机

[[email protected] ~]# type cd                //查看“cd”是内部还是外部命令

[[email protected] ~]# help cd          //查看内部命令“cd”的帮助信息

[[email protected] ~]# ls –help       //查看外部命令“ls”的帮助信息

[[email protected] ~]# manpath       //man手册存放位置


[[email protected] ~]# makewhatis               //生成“whatis”数据库

[[email protected] ~]# whatispasswd                //查看简化版手册页信息

[[email protected] ~]# whatis passwd  =  man-f passwd

二、目录和文件基本管理

pwd 查看当前位置

[[email protected] ~]# pwd

cd 目录切换   

[[email protected] src]# cd -              //返回之前目录

[[email protected] grub]# cd ..           //返回上级目录

[[email protected] boot]# cd             //进入家目录

[[email protected] ~]# cd ~root              //进入家目录


[[email protected] Desktop]# cd ../..        //返回上一级的上一级

[[email protected] /]# cd .            //当前目录

[[email protected] ~]# cd ~               //进入家目录

ls List查看

[[email protected] ~]# ls              //列表查看目录内容

[[email protected] ~]# ls –l                //长格式列表查看目录内容

[[email protected] ~]# ls -l -h

[[email protected] ~]# ls –lh             

-h             //提供易读容量单位

[[email protected] ~]# ls -lhd /boot/ /home/

                                          -d             //查看当前目录本身属性

[[email protected] boot]# ls –A               //显示隐藏文件

[[email protected] boot]# ls –a                //显示. ..所有隐藏

[[email protected] boot]# ls –R                //递归显示内容

通配符

[[email protected] opt]# touch file1.txt               //创建文件file1.txt

[[email protected] opt]# touch file2.txt

[[email protected] opt]# touch file3.txt

[[email protected] opt]# touch filea.txt fileb.txt filec.txt

[[email protected] opt]# ls file*

*                //匹配任意多个字符

[[email protected] opt]# ls file?

                                                ?              //匹配任意单个字符

[[email protected] opt]# ls file??.txt

[[email protected] opt]# ls file?.txt

[[email protected] opt]# touch file12.txt

[[email protected] opt]# touch file123.txt

[[email protected] opt]# touch fileab.txt

[[email protected] opt]# ls

[[email protected] opt]# ls file[0-9].txt

[[email protected] opt]# ls file[0-9][0-9].txt

[[email protected] opt]# ls file??.txt

[[email protected] opt]# ls file{1,ab,12}.txt

[[email protected] opt]# ls file{1,ab,12,abc}.txt

 

du  评估目录或文件大小

[[email protected] opt]# du -sh /boot/ /etc/pki/

[[email protected] opt]# mkdir 1406                        //创建文件夹1406

[[email protected] opt]# ls

[[email protected] opt]# mkdir abc mp4 mp3

[[email protected] opt]# ls

[[email protected] opt]# mkdir -p aaa/bbb/ccc/ddd

                                          -p                         //创建递归目录

[[email protected] opt]# ls -R aaa

                                     -R                   //查看递归目录信息 各层目录内容

[[email protected] opt]# mkdir -p /test1 data/mp4 mp3

[[email protected] opt]# ls -ld /test1/ data/ mp3         

[[email protected] opt]# ls -l file1.txt

[[email protected] opt]# touch file1.txt        //创建文件file1.txt

[[email protected] opt]# ls -l file1.txt

[[email protected] opt]# ls -l /sbin/network

[[email protected] opt]# ln -s /usr/sbin/system-config-network-tui  /sbin/network                      -s         //创建链接 源  目标

[[email protected] opt]# ls -l /sbin/network

[[email protected] opt]# ls /root/file1.txt

[[email protected] opt]# cp file1.txt /root/     //复制file1到/root

[[email protected] opt]# ls /root/file1.txt

[[email protected] opt]# ls

[[email protected] opt]# cp aaa /root/

[[email protected] opt]# ls /root/aaa

[[email protected] opt]# cp -r aaa /root/

                                     -r                    //复制目录

[[email protected] opt]# ls /root/aaa

[[email protected] opt]# ls /root/file1.txt

[[email protected] opt]# cp file1.txt /root/

[[email protected] opt]# cp -f file1.txt /root/

                                     -f                         //强制覆盖

[[email protected] opt]# alias                       //查看别名

[[email protected] opt]# unalias cp          //临时取消别名

[[email protected] opt]# cp -f file1.txt /root/

[[email protected] opt]# \cp -f file1.txt /root/

                                     \               //洗脚水(可以让-i失效,这里跟我的老师讲的一个典故有关)

 

三、程序和文件检索 [locate/find]

[[email protected] ~]# echo $PATH                  //查看命令路径

[[email protected] ~]# which ls cd              //查找命令cd路径(外)

[[email protected] ~]# updatedb               //创建/更新数据库

[[email protected] ~]# touch myhttpd.conf         

[[email protected] ~]# ls

[[email protected] ~]# locate myhttpd.conf //基于数据库查找

[[email protected] ~]# updatedb          //更新数据库

[[email protected] ~]# locate myhttpd.conf

[[email protected] ~]# rm myhttpd.conf

[[email protected] ~]# locate myhttpd.conf

[[email protected] ~]# updatedb

[[email protected] ~]# locate myhttpd.conf

 

find

[[email protected] ~]# find /boot -type l     //查找boot下的链接

[[email protected] ~]# ls -l/boot/grub/menu.lst //查看链接文件

[[email protected] ~]# find /boot -type d       //查找boot下目录

[[email protected] ~]# find /etc -name"resolv*conf"         //按名字查找

        

[[email protected] ~]# find /dev -type c -a -name "tty[1-3]"

                       -type        //按文件类型查找

整句释义//查找dev下的字符设备文件必须匹配tty和编号1-3

[[email protected] ~]# ls -lh /boot/*  //人性化方式长格式显示boot下内容

[[email protected] ~]# find /boot -size +2M //查找大于2M的文件或目录               //按照文件大小查找

[[email protected] ~]# cp install.loginstall.new

[[email protected] ~]# ls -lh install.???

[[email protected] ~]# find -name"install.???" -mtime +30

                            //查找30天修改的以install.开头的文件

                           //按内容修改时间

[[email protected] ~]# find /boot -size +2M

[[email protected] ~]# find /boot -size +2M -exec ls -lh {} \;

                                 //处理find找到的文件//固定格式

                                  //-exec只用于find

           //以人性化长格式显示找到的2M以上的文件

Dmesg:系统启动时所加载的硬件信息

[[email protected] ~]# cat /etc/resolv.conf  //查看文件内容 

[[email protected] ~]# cat -n /etc/resolv.conf  //行数编号查看

[[email protected] ~]# cat /root/install.log  

[[email protected] ~]# cat -n/root/install.log

[[email protected] ~]# cat -n /etc/passwd

[[email protected] ~]# more /root/install.log  //分页查看大文件

[[email protected] ~]# type ls

[[email protected] ~]# ls --help

[[email protected] ~]# ls --help | more   //|”管道,管道前的执行结果作为管道后的输入

[[email protected] ~]# cat /root/install.log |more

[[email protected] ~]# more /root/install.log

[[email protected] ~]#less /root/install.log  //分页查看大文件

                                                                         more更灵活方便

[[email protected] ~]#head /etc/passwd  //显示前几行内容

                                                                         默认前十行

[[email protected] ~]# head -n 2 /etc/passwd  //打开file前两行

[[email protected] ~]# tail /var/log/messages  //打开文件末尾

                                                                   //默认打开后10

[[email protected] ~]#tail -n 2 /etc/passwd  //打开文件后两行

[[email protected] ~]# head -n 12 /etc/passwd | tail -n 5

           //打开812  打开前12行,再打开其中后5

[[email protected] ~]# touch news.txt

[[email protected] ~]# tail -f news.txt  //实时检查文件内容变化

切换终端(Ctrl + Shift + t

>                      //写入,覆盖之前文件

>>         //追加

[[email protected] ~]# echo 111111111 >>news.txt

                                                  //111111111写进文件

[[email protected] ~]# echo 222222222 >>news.txt

[[email protected] ~]# echo 333333333 >>news.txt

[[email protected] ~]# wc /etc/passwd   //显示文件行数,大小

[[email protected] ~]# wc -l /etc/passwd   //只显示文件行数

[[email protected] ~]# find /etc -name "*.conf" -a -type f | wc

等同于find /etc -type f -name "*.conf"|wc

                 //查找以.conf结尾的普通文件然后显示其数量

                                      这里的-a可以省略

[[email protected] ~]# cat /etc/hosts

[[email protected] ~]# grep 127.0.0.1 /etc/hosts                                                                           //过滤含有关键字的内容

[[email protected] ~]# grep --color 127.0.0.1 /etc/hosts

                                  //将关键字以其他颜色显示

[[email protected] ~]# grep -v 127.0.0.1 /etc/hosts

                                  //过滤显示含关键字以外的内容

[[email protected] ~]# grep root /etc/passwd

[[email protected] ~]# grep Root /etc/passwd

[[email protected] ~]# grep -i Root /etc/passwd

                                  //不严格区分大小写过滤

[[email protected] ~]# dmesg | grep eth

                                  //系统启动时的硬件信息

[[email protected] ~]# dmesg | grep sda

[[email protected] ~]#grep "^#" /etc/hosts

                                  //过滤#开头(注释)的内容

[[email protected] ~]# grep -v "^#"/etc/hosts

[[email protected] ~]# grep "bash$" /etc/passwd

                                  //过滤bash结尾的内容

[[email protected] ~]# grep -v "^#"/etc/xinetd.conf | grep -v "^$"

                            //显示除#开头和$结尾以外的内容

[[email protected] ~]# grep -vE "^#|^$"/etc/xinetd.conf

                            //扩展查找模式  将管道应用到中间


[[email protected] ~]# grep -c "/bin/bash$" /etc/passwd

                            //匹配的行数

Linux系统管理——基础命令篇

Linux系统管理——基础命令篇

Linux系统管理——基础命令篇

Linux系统管理——基础命令篇

Linux系统管理——基础命令篇