linux-d1-基础命令

CentOS 6默认启动6个虚拟终端
ctrl+alt+f#:[1,6]
查看当前终端设备:tty

显示当前使用的shell # echo ${shell}

命令提示符:prompt:
# 管理员

$ 普通用户

命令:    
which 查看ls脚本位置
[root@izm5e5qf7n47jhwufk5eo9z ~]# which ls
alias ls='ls --color=auto'
        /usr/bin/ls
[root@izm5e5qf7n47jhwufk5eo9z ~]# whereis ls

ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

在shell中可执行命令有两类
内bu命令:由shell自带的,而且通过某命令形式提供
外部命令 : 在当前系统的某文件系统路径下有对应的可执行程序文件:which whereis

区别内部或外部命令:# type COMMAND

[root@izm5e5qf7n47jhwufk5eo9z ~]# type cd
cd is a shell builtin
[root@izm5e5qf7n47jhwufk5eo9z ~]# type ls

ls is aliased to `ls --color=auto'

文件系统
文件有两类数据
元数据:metadata ( 文件属性)
数据: data
文件名严格区分大小写
.开头为隐藏文件
路径 
           当前路径表示
1  ./
2  省略上述符号

  ../当前命令的上级目录

运行命令:  


linux命令帮助的获取
内部命令
help
外部命令 都有一个可执行程序位于文件系统目录下 which whereis shell程序搜寻可执行程序文件的路径定义在PATH环境变量中 #echo $PATH
shell搜寻到的外部命令的路径结果会缓存至(key-value)存储中
hash
history 管理命令历史 在登出之前不会记录登出后记录命令信息 
记录在 / .bash_history
cat .bash_history 查看文本文件
登录shell时会读取命令历史中记录下的命令
登录进shell后新执行的命令会记录在缓存中 这些命令会在用户退出时追加到history

history:
-a 追加本次会话执行的命令
-d 删除历史中指定命令
-c 清空命令历史
快捷操作:
!#:调用历史中第#条命令
String: 调用历史中最近一个以string开头的命令
!!  :上条命令
外部命令获取:
(2) man COMMAND
手册页: /usr/share/man
man1 ... man8
man1:用户命令
man2:系统调用
man3:库调用
man4:设备文件及特殊文件
man5:配置文件格式
man8:管理类命令
man 命令的配置文件 :/etc/man.config
MANPATH /PATH/TO/SOMEWHERE :指明新的手册文件的搜索位置
#man -M /PATH/TO/SOMEWHERE COMMAND :指定位置下搜索COMMAND命令的手册并显示之

帮助手册中的段落说明】
NAME
SYNOPSIS



SYNOPSIS:
[]可选
<>必选
a|b 二选一
...:同一内容可出现多次

man命令的操作方法
Space,^V,^F,^f:向文件尾翻屏
b,^B           向文件首部翻
q:退出
#:跳至第#行
1G:回到文件尾部
G:翻至文件尾部
文本搜索
/keyword
   以keyword指定的字符串为关键字,从当前位置向文件尾部搜 不区分字符大小写
        n:下一个
N:上一个
?keyword
   以keyword指定的字符串为关键字,从当前位置向文件首部搜 不区分字符大小写
        n: 与搜索命令同方向:下一个

N:跟搜索命令反方向:上一个

[root@izm5e5qf7n47jhwufk5eo9z ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin


1 COMMAND --help
  COMMAND -h
  2 使用手册(manual)
  # man COMMAND
3 信息页 
  # info COMMAND


4 程序自带的帮助文档
    README
INSTALL

Changelog

基础命令 
date:
  
       date [OPTION]... [+FORMAT]
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
   MM:月份
   DD:几号
   hh:小时
   mm:分钟
           YY:两位年份
   CCYY:四位年份
           .css:秒
   Linux两种时钟
           hwclock:显示硬件时钟
              -s,--hctosys
              -w,--systohc


edg:
No manual entry for -m
[root@izm5e5qf7n47jhwufk5eo9z ~]# date +%a
Thu
[root@izm5e5qf7n47jhwufk5eo9z ~]# date +%D
04/12/18





命令格式  命令  [-选型][参数]
选项:用于启用或关闭命令的某些功能
短选项: -c 例如: -l ,-h
    多个短选项可合并
长选项: --word 
` 参数:命令的作用对象
      向命令提供数据




edg: ls -la /etc




目录相关
主目录或工作目录
         主目录:家目录:HOME
             root:/root
             普通用户:/home/USERNAME
                  /home/tom
           ~:用户主目录 
   
cd:
   cd - 上个目录和当前目录来回切换
useradd user1 添加用户
        cd  ~user1    切换到用户1




[root@izm5e5qf7n47jhwufk5eo9z ~]# useradd user1
[root@izm5e5qf7n47jhwufk5eo9z ~]# cd ~user1
[root@izm5e5qf7n47jhwufk5eo9z user1]# pwd
/home/user1
[root@izm5e5qf7n47jhwufk5eo9z user1]# cd ~
[root@izm5e5qf7n47jhwufk5eo9z ~]# pwd
/root
[root@izm5e5qf7n47jhwufk5eo9z ~]# 






目录命令 ls
名称 ls
命令所在路径 /bin/ls
执行权限 所有用户
功能显示目录文件
语法 ls选项[-ald][目录或文件]
-a 显示所有,包括隐藏 all
-l 详细信息显示  lenght
-d 查看目录自身属性
-r 逆序显示
-R  递归显示


edg: .dsf  隐藏文件

ls -1/
                              


  引用计数    owner  所属组(group)  文件大小字节      最后修改时间   文件名


lrwxrwxrwx.  1 root root     7 Oct 15 23:19 bin -> usr/bin
dr-xr-xr-x.  5 root root  4096 Oct 15 23:24 boot
drwxr-xr-x  20 root root  3040 Mar 12 12:51 dev
drwxr-xr-x. 86 root root  4096 Mar 12 15:13 etc

ls -lh /   h 人性化显示

total 68K
lrwxrwxrwx.  1 root root    7 Oct 15 23:19 bin -> usr/bin
dr-xr-xr-x.  5 root root 4.0K Oct 15 23:24 boot
drwxr-xr-x  20 root root 3.0K Mar 12 12:51 dev
drwxr-xr-x. 86 root root 4.0K Mar 12 15:13 etc
drwxr-xr-x.  3 root root 4.0K Mar 12 09:23 home
lrwxrwxrwx.  1 root root    7 Oct 15 23:19 lib -> usr/lib

lrwxrwxrwx.  1 root root    9 Oct 15 23:19 lib64 -> usr/lib64

-文件 d目录 l软连接


-rw-r--r--
- 文件类型 
rw- r-- r--
u   g   o
u所有者  g所属组 o其他人
r读 w写 x执行
ls -ld /
对应目录信息
dr-xr-xr-x. 20 root root 4096 Mar 12 13:56 /


-i i节点 (文件id)

目录处理命令 mkdir 


[root@izm5e5qf7n47jhwufk5eo9z temp]# mkdir abc.txt
[root@izm5e5qf7n47jhwufk5eo9z temp]# ls
abc.txt  mysql-community-release-el7-5.noarch.rpm


[root@izm5e5qf7n47jhwufk5eo9z temp]# mkdir  /jp/bu
mkdir: cannot create directory 鈥jp/bu鈥 No such file or directory 
-p 递归创建不存在的目录也行
[root@izm5e5qf7n47jhwufk5eo9z temp]# mkdir -p /jp/bu
[root@izm5e5qf7n47jhwufk5eo9z temp]# ls
同时创建多个目录 
[root@izm5e5qf7n47jhwufk5eo9z ~]# mkdir /temp/jp/11   /temp/jp/22
[root@izm5e5qf7n47jhwufk5eo9z ~]# ls -l /temp/jp
total 8
drwxr-xr-x 2 root root 4096 Apr 12 15:44 11
drwxr-xr-x 2 root root 4096 Apr 12 15:44 22
目录处理命令 cd
pwd显示当前目录绝对路径


[root@izm5e5qf7n47jhwufk5eo9z temp]# pwd
/temp


.当前目录 .. 当前目录的上级目录

[root@izm5e5qf7n47jhwufk5eo9z temp]# cd /temp/jp
[root@izm5e5qf7n47jhwufk5eo9z jp]# pwd
/temp/jp
[root@izm5e5qf7n47jhwufk5eo9z jp]# cd ..
[root@izm5e5qf7n47jhwufk5eo9z temp]# cd .
[root@izm5e5qf7n47jhwufk5eo9z temp]# 




删除目录 rmdir 只能删除空目录
[root@izm5e5qf7n47jhwufk5eo9z temp]# rmdir /temp/jp/11
[root@izm5e5qf7n47jhwufk5eo9z temp]# ls /temp/jp

22

cat 查看文件
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s), or standard input, to standard output.


  -A, --show-all           equivalent to -vET
  -b, --number-nonblank    number nonempty output lines, overrides -n
  -e                       equivalent to -vE
  -E, --show-ends          display $ at end of each line
  -n, --number             number all output lines
  -s, --squeeze-blank      suppress repeated empty output lines
  -t                       equivalent to -vT
  -T, --show-tabs          display TAB characters as ^I
  -u                       (ignored)
  -v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB
      --help     display this help and exit
      --version  output version information and exit




复制命令 cp
cp -rp[原文件或目录][目标目录]
   -r 复制目录
   -p 保留文件属性


文件内容查看 file




[root@izm5e5qf7n47jhwufk5eo9z temp]# file /etc/fstab

/etc/fstab: ASCII text

[root@izm5e5qf7n47jhwufk5eo9z temp]# file /bin/cat
/bin/cat: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=fac04659ab9a437b5384c09f4731023373821a39, stripped




回显命令 echo
     -n: 禁止自动添加换行符
     -e: 允许使用转意符




whatis:
     使用mkwhatis命令可将当前系统上所有的帮助手册及与之对应的关键字创建为一个数据库
     系统管理类命令
        关机:
           halt 

[root@izm5e5qf7n47jhwufk5eo9z temp]# echo "ddd"
ddd
[root@izm5e5qf7n47jhwufk5eo9z temp]# echo  "$SHELL"
/bin/bash


[root@izm5e5qf7n47jhwufk5eo9z temp]# mkdir /temp/jp/11 /temp/jp/33
[root@izm5e5qf7n47jhwufk5eo9z temp]# mkdir /temp/jp/44 55
[root@izm5e5qf7n47jhwufk5eo9z temp]# ls -l /temp/jp
total 16
drwxr-xr-x 2 root root 4096 Apr 12 15:55 11
drwxr-xr-x 2 root root 4096 Apr 12 15:44 22
drwxr-xr-x 2 root root 4096 Apr 12 15:55 33
drwxr-xr-x 2 root root 4096 Apr 12 15:56 44
[root@izm5e5qf7n47jhwufk5eo9z temp]# cp -r /temp/jp/11 /temp/jp/22
[root@izm5e5qf7n47jhwufk5eo9z temp]# ls l /temp/jp/11
ls: cannot access l: No such file or directory
/temp/jp/11:
[root@izm5e5qf7n47jhwufk5eo9z temp]# ls -l /temp/jp/22
total 4
drwxr-xr-x 2 root root 4096 Apr 12 15:57 11
[root@izm5e5qf7n47jhwufk5eo9z temp]# 


目录处理命令 mv 
语法 mv[原文件或目录][目标目录]
功能描述:剪切,改名 


clear 清屏


[root@izm5e5qf7n47jhwufk5eo9z jp]# ls
11  22  33  44
[root@izm5e5qf7n47jhwufk5eo9z jp]# mv /temp/jp/11 /temp/jp/44
[root@izm5e5qf7n47jhwufk5eo9z jp]# ls /temp/jp
22  33  44
[root@izm5e5qf7n47jhwufk5eo9z jp]# ls /temp/jp/44
11
[root@izm5e5qf7n47jhwufk5eo9z jp]# 




剪切文件并改名 
[root@izm5e5qf7n47jhwufk5eo9z ~]# ls /temp/jp
22  33  44
[root@izm5e5qf7n47jhwufk5eo9z ~]# mv /temp/22 /temp/44/222
mv: cannot stat 鈥temp/22鈥 No such file or directory
[root@izm5e5qf7n47jhwufk5eo9z ~]# mv /temp/22 /temp/44
mv: cannot stat 鈥temp/22鈥 No such file or directory
[root@izm5e5qf7n47jhwufk5eo9z ~]# mv /temp/jp/22 /temp/jp/44/222
[root@izm5e5qf7n47jhwufk5eo9z ~]# ls /temp/jp/44
11  222
[root@izm5e5qf7n47jhwufk5eo9z ~]# ls /temp/jp
33  44




改文件名
[root@izm5e5qf7n47jhwufk5eo9z ~]# mv /temp/jp/33 /temp/jp/333
[root@izm5e5qf7n47jhwufk5eo9z ~]# ls /temp/jp
333  44
[root@izm5e5qf7n47jhwufk5eo9z ~]# 




删除命令 rm


语法 rm -rf[文件或目录]
      -r 删除目录
     -f 强制执行
 
[root@izm5e5qf7n47jhwufk5eo9z ~]# rm -rf /temp/jp/333
[root@izm5e5qf7n47jhwufk5eo9z ~]# ls -l /temp/jp
total 4
drwxr-xr-x 4 root root 4096 Apr 12 16:38 44
[root@izm5e5qf7n47jhwufk5eo9z ~]# 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值