一、 基础命令之ls
1. ls解释;
列出文件及目录
2. 常用参数;
①. -l: 详细信息
[root@Centos2 ~]# ls -l total 20-rw-------. 1 root root 1109 Jan 20 18:08 anaconda-ks.cfg………………/省略
②. -a: 查看所有的文件或目录
[root@Centos2 ~]# ls -la total 60dr-xr-x---. 2 root root 4096 Mar 9 22:16 .dr-xr-xr-x. 22 root root 4096 Mar 9 21:36 ..-rw-------. 1 root root 2778 Mar 9 22:41 .bash_history-rw-r--r--. 1 root root 18 May 20 2009 .bash_logout-rw-r--r--. 1 root root 176 May 20 2009 .bash_profile………………/省略
③. -d: 只查看目录本身, 不列出目录下面的文件和目录
[root@Centos2 ~]# ls -ld #查看当前目录($home);dr-xr-x---. 2 root root 4096 Mar 9 22:16 .[root@Centos2 ~]# ls -ld /etc/ #查看/etc目录;drwxr-xr-x. 83 root root 4096 Mar 9 22:16 /etc/
④. -i : 显示每个文件的索引节点信息(inode)
[root@Centos2 ~]# ls -li #查看当前目录下的索引节点;total 20914021 -rw-------. 1 root root 1109 Jan 20 18:08 anaconda-ks.cfg #红色标记为inode节点913922 -rw-r--r--. 1 root root 9169 Jan 20 18:08 install.log………………/省略
⑤. -t: 以修改时间排序(从大到小)
[root@Centos2 ~]# ls -lt #查看当前目录下文件及目录并详细输出;total 20-rw-------. 1 root root 1109 Jan 20 18:08 anaconda-ks.cfg-rw-r--r--. 1 root root 9169 Jan 20 18:08 install.log
二、 为grub加密及init级别介绍
1. 为GRUB设置sha加密;
[root@Centos1 ~]# grub-crypt --sha-256 #为grub设置sha加密Password: #输入要设置的密码Retype password: #重复密码$5$YIx2RS5TT48oxjKY$DRI6a4fr.Q8C9YSMHv.kcGa8HzU4ajcfTghLkMBZbd5 #复制sha[root@Centos1 ~]# vim /etc/grun.compassword --encrypted $5$YIx2RS5TT48oxjKY$DRI6a4fr.Q8C9YSMHv.kcGa8HzU4ajcfTg #新增此行[root@Centos1 ~]# vim /etc/inittab #修改启动运行级别id:3:initdefault: #在文件末尾行能看见默认启动级别(我这默认从init 3级别启动)
2. Linux7个运行级别详解;
① init0: 关机
② init1: 单用户模式
③ init2: 不带网络NFS服务的3级别
④ init3: 没有安装图形化界面的默认命令明亮行模式
⑤ init4: 无
⑥ init5: 切换到图形化界面
⑦ init6: 重启操作系统
3. 查看当前运行级别;
[root@Centos2 ~]# runlevel N 3 #当前运行级别为init 3
三、 alias别名介绍
alias: 每个人都有自己的大名和小名, 当然Linux也不另外, 在Linux中对于alias而言大名为绝对路径,小名为相对路径
疑问: 对于alias而言什么叫绝对路径?
答: 比如说ls命令. 它的绝对路径(大名) 为/bin/ls
疑问: 对于alias而言什么叫相对路径?
答: 相对路径(小名)ls
1. 设置别名(aslias)
①. 查看当前别名;
[root@Centos2 ~]# alias alias cp='cp -i'alias l.='ls -d .* --color=auto'alias ll='ls -l --color=auto'alias ls='ls --color=auto'alias mv='mv -i'alias rm='rm -i'alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
②. 查看当前进程;
[root@Centos2 ~]# ps -efroot 3343 1546 0 Mar09 tty1 00:00:00 -bashroot 3494 2335 0 Mar09 ? 00:00:02 sshd: root@pts/2………………/省略
③. 将ps -ef的别名设置为ps;
[root@Centos2 ~]# alias jinchen='ps -ef'[root@Centos2 ~]# jinchenroot 3343 1546 0 Mar09 tty1 00:00:00 -bashroot 3494 2335 0 Mar09 ? 00:00:02 sshd: root@pts/2………………/省略
④. 取消别名;
[root@Centos2 ~]# unalias jinchen
⑤. 如何让当前用户alias永久生效;
[root@Centos2 ~]# vim $home/.bashrc alias p='pwd' #在末尾行新增[root@Centos2 ~]# p
/root
四、 Linux系统目录结构
/bin, /sbin, /usr/bin, /usr/sbin #放命令的目录, sbin是超级用户root才可以用的命令
/boot #引导程序
/dev #硬盘、光盘、等块设备
/etc #配置文件
/home #家目录所在路径
/lib #库文件,命令ldd(可以帮我们查看某一个命令依赖的库),so:动态库,a:静态库
/media,/mnt #临时目录
/opt #存放某些大型软件或者某些特殊软件
/proc #与进程、内核相关
/tmp #临时文件
/usr # 用户程序存放目录
/var # 日志目录
五、 环境变量(PATH)
1. 配置环境变量(PATH)
①. 查看当前环境变量(PATH);
[root@Centos2 ~]# echo $PATH/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
②. 将/bin/pwd复制一份到/home/chenjunhan;
[root@Centos2 ~]# cp /bin/pwd /home/chenjunhan[root@Centos2 ~]# /home/chenjunhan /root
③. 将/home加入到环境变量中;
[root@Centos2 ~]# PATH=$PATH:/home[root@Centos2 ~]# chenjunhan/root
2. 配置永久环境变量(PATH)
①. 修改/etc/profile文件;
[root@Centos2 ~]# vim /etc/profile PATH=$PATH:/home #在末尾行添加
②. 加载环境变量(PATH);
[root@Centos2 ~]# source /etc/profile
六、快捷命令
Ctrl+c 取消命令
Ctrl+z 暂停命令
Ctrl+a 光标到行首
Ctrl+e 光标到行尾
Ctrl+u 删除光标前所有字符
Ctrl+k 删除光标后所有字符
Ctrl+l 清屏
Ctrl+d 退出登录 == exit
Ctrl+s 锁住命令终端,按任何键都不会有反应
Ctrl+q 解锁命令终端
七、扩展知识
1. 按ctrl+c, 命令后面会出现^C, 如何去掉呢?
例子: [root@Centos2 home]# ls /etc/profile^C #去掉^C 方法: [root@Centos2 home]# stty -ctlecho [root@Centos2 home]# ls /etc/profile [root@Centos2 ~]# vim .bashrc #让root用户用就生效 stty -ctlecho #末尾行添加
2. 更改内核参数, 让别人无法ping通此自己
[root@Centos1 ~]# ping 192.168.15.12 #利用其它机器ping自己PING 192.168.15.11 (192.168.15.11) 56(84) bytes of data.64 bytes from 192.168.15.11: icmp_seq=1 ttl=64 time=0.098 ms #能ping通[root@Centos2 home]# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all #默认为0[root@Centos1 ~]# ping 192.168.15.12 #利用其它机器ping不通自己PING 192.168.15.12 (192.168.15.12) 56(84) bytes of data.