Linux基础命令注释(1)

Linux基础命令注释

cat 查看文件

[root@localhost ~]# cat anaconda-ks.cfg 
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability
repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8
...

ls 列出目录

  • ls 列出目录下所有文件(不包括以' . '开头的隐藏文件)
[root@localhost ~]# ls 
anaconda-ks.cfg

  • ls -a 列出文件下所有文件(包括以' . '开头的隐藏文件)
[root@localhost ~]# ls -a
.   anaconda-ks.cfg  .bash_logout   .bashrc  .tcshrc
..  .bash_history    .bash_profile  .cshrc


  • ls -l 列出文件详细信息 创建者,创建时间,文件读写权限
[root@localhost ~]# ls -l
总用量 4
-rw-------. 1 root root 1451 9月   6 22:57 anaconda-ks.cfg
        // 1 目录下只有一个文件   1451 文件大小


  • ls . 显示当前目录 = ls
basht@localhost ~]# ls .
anaconda-ks.cfg

  • ls .. 显示上一级目录 = ls /
bashot@localhost ~]# ls /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

  • ls a* 列出a开头的目录
[root@localhost ~]# ls a*
anaconda-ks.cfg

a:

  • ls /tmp/ /root/ 查看两个文件的目录
[root@localhost ~]# ls /tmp/ /root/
/root/:
a  abc  acd  anaconda-ks.cfg  bbb  c  cc  qwq  vbn  wqw

/tmp/:
ks-script-bCAQaW
systemd-private-11747351e8364d83b070d6be17400cce-chronyd.service-lGLDlY
systemd-private-11747351e8364d83b070d6be17400cce-vgauthd.service-g3JiUd
systemd-private-11747351e8364d83b070d6be17400cce-vmtoolsd.service-wE4Eut
yum.log


mkdir 创建目录

  • mkdir 创建目录
[root@localhost ~]# mkdir a
[root@localhost ~]# ls
a  anaconda-ks.cfg


  • mkdir -p 创建目录,若父目录不在则自动创建
[root@localhost ~]# mkdir -p a/b/{c,d/{e,f/g}}
[root@localhost ~]# ls a
b
[root@localhost ~]# ls a/b
c  d
[root@localhost ~]# ls a/b/d
e  f


  • mkdir -v 显示创建的目录的过程
[root@localhost ~]# mkdir -pv a/b/{c,d/{e,f/g}}
mkdir: 已创建目录 "a"
mkdir: 已创建目录 "a/b"
mkdir: 已创建目录 "a/b/c"
mkdir: 已创建目录 "a/b/d"
mkdir: 已创建目录 "a/b/d/e"
mkdir: 已创建目录 "a/b/d/f"
mkdir: 已创建目录 "a/b/d/f/g"



mv 移动文件(也可用于重命名)

[root@localhost ~]# ls
a  anaconda-ks.cfg
[root@localhost ~]# mv a aa
[root@localhost ~]# ls
aa  anaconda-ks.cfg



history 历史命令

  • history
[root@localhost ~]# history
    1  ls
    2  file anaconda-ks.cfg 
    3  vi anaconda-ks.cfg 
    4  shutdown -h now
    5  cd /etc/sysconfig/network-scripts/
    6  vi ifcfg-ens33 
    7  systemctl restrat network
    8  systemctl restart network
    9  ip a
   10  cdnte
   11  cdnet
   12  cdnte
   13  `
   14  cdnte
   15  .
   16  cdnte
   17  cdnet
   18  ls /tmp
   19  ls
   20  cd



  • ![n] 调用历史命令
[root@localhost ~]# !9
ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:3a:87:11 brd ff:ff:ff:ff:ff:ff
    inet 192.168.213.128/24 brd 192.168.213.255 scope global dynamic ens33
       valid_lft 1309sec preferred_lft 1309sec
    inet6 fe80::c862:f7d8:eac7:83ae/64 scope link 
       valid_lft forever preferred_lft forever



  • !! 上一条命令也可以用键盘上键
[root@localhost ~]# cd -
/etc
[root@localhost etc]# !!
cd -
/root



  • history -d[n] 删除历史命令 -c删除所有
[root@localhost ~]# history
    1  history 
    2  pwd
    3  cd
    4  ls
    5  ll
    6  history 
    7  history -n1
    8  history -n 1
    9  history
[root@localhost ~]# history -d1
[root@localhost ~]# history 
    1  pwd
    2  cd
    3  ls
    4  ll
    5  history 
    6  history -n1
    7  history -n 1
    8  history
    9  history -d1
   10  history 



cd 切换目录

  • cd 切换目录
[root@localhost ~]# cd /etc/
[root@localhost etc]# pwd
/etc



  • cd ~ 返回用户目录
[root@localhost ~]# cd ~tom
[root@localhost tom]# pwd
/home/tom

[root@localhost etc]# cd ~
[root@localhost ~]# 

[root@localhost etc]# cd
[root@localhost ~]# pwd
/root
//直接输入cd 也可返回当前用户目录



  • cd ~tom 进入tom家目录
[root@localhost ~]# cd ~tom
[root@localhost tom]# 


  • cd -返回上次目录
[root@localhost ~]# cd /etc
[root@localhost etc]# cd -
/root
[root@localhost ~]# cd -
/etc



  • cd .. 返回上级目录
[root@localhost /]# cd /etc/sysconfig/
[root@localhost sysconfig]# cd ..
[root@localhost etc]# 


管道符过滤文件

  • cat anaconda-ks.cfg |grep rootpw过滤文件anaconda-ks.cfg中有关rootpw行
[root@localhost ~]# cat anaconda-ks.cfg |grep rootpw
rootpw --iscrypted $6$15KaJSMJ1CnXnZP6$i.4EoTpZwTUTcZhK0oYRIjgyP9UTYbXsq//IV4xIiaB.2RfwtJP7SzhiAN4KcrAZP1ABjRIPx9pdl7vXdHoJk.



  • [root@localhost ~]# cat anaconda-ks.cfg |grep rootpw > qwq 过滤文件并打印大qwq文件中
[root@localhost ~]# cat anaconda-ks.cfg |grep rootpw > qwq
[root@localhost ~]# ls
anaconda-ks.cfg  qwq
[root@localhost ~]# cat qwq 
rootpw --iscrypted $6$15KaJSMJ1CnXnZP6$i.4EoTpZwTUTcZhK0oYRIjgyP9UTYbXsq//IV4xIiaB.2RfwtJP7SzhiAN4KcrAZP1ABjRIPx9pdl7vXdHoJk.



rm 删除文件

  • rm 删除文件
[root@localhost ~]# ls
aa  anaconda-ks.cfg  qwq
[root@localhost ~]# rm qwq
rm:是否删除普通文件 "qwq"?y
[root@localhost ~]# ls
aa  anaconda-ks.cfg


  • rm -r 递归删除,删除文件目录必须用
[root@localhost ~]# ls
aa  anaconda-ks.cfg
[root@localhost ~]# rm -r aa
rm:是否进入目录"aa"? y
rm:是否进入目录"aa/b"? y
rm:是否删除目录 "aa/b/c"?y
rm:是否进入目录"aa/b/d"? y
rm:是否删除目录 "aa/b/d/e"?y
rm:是否进入目录"aa/b/d/f"? y
rm:是否删除目录 "aa/b/d/f/g"?y
rm:是否删除目录 "aa/b/d/f"?y
rm:是否删除目录 "aa/b/d"?y
rm:是否删除目录 "aa/b"?y
rm:是否删除目录 "aa"?y


  • -f 强制删除,不询问
[root@localhost ~]# mkdir -p a/b/c/d/f/c
[root@localhost ~]# ls
a  anaconda-ks.cfg
[root@localhost ~]# rm -rf a
[root@localhost ~]# ls
anaconda-ks.cfg

stat : 显示文件或文件系统的状态

[root@localhost ~]# stat qwq
  文件:"qwq"
  大小:126       	块:8          IO 块:4096   普通文件
设备:fd00h/64768d	Inode:100663379   硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2019-09-07 14:41:58.769032865 +0800
最近更改:2019-09-07 14:41:58.769032865 +0800
最近改动:2019-09-07 14:41:58.769032865 +0800
创建时间:-

touch 创建空文件或者更新时间戳

[root@localhost ~]# touch qwq
[root@localhost ~]# stat qwq
  文件:"qwq"
  大小:126       	块:8          IO 块:4096   普通文件
设备:fd00h/64768d	Inode:100663379   硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2019-09-07 14:41:58.769032865 +0800
最近更改:2019-09-07 14:41:58.769032865 +0800
最近改动:2019-09-07 14:41:58.769032865 +0800
创建时间:-

alias 命令别名

  • alias 命令别名(临时别名重启后失效)
[root@localhost ~]# alias cdent='cd /etc/sysconfig/network-scripts'
[root@localhost ~]# cdent
[root@localhost network-scripts]# pwd
/etc/sysconfig/network-scripts


  • 命令别名
[root@localhost ~]# vi .bashrc 

# .bashrc

# User specific aliases and functions       //用户命令别名当前用户有效
alias cdnet='cd /etc/sysconfig/network-scripts'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions                 // 公用命令别名所有用户有效
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
~                                                       
~                                                                                         
".bashrc" 12L, 223C


原文地址:https://www.cnblogs.com/guilai/p/11527440.html