Tag: INF data read file glib Port Sync map Anaconda Operating system
Linux Common commands
In Linux, most commands refer to the command option parameter
Options: Applies to the ability to adjust commands
Parameter: Refers to the operand of the command, if omitted, is due to the default parameter
Directory Operations Command
LS Displays the contents of the directory
# ls [[email protected] ~]# lsanaconda-ks.cfg install.log install.log.syslog# ls--color =never does not display the color of the file name under the display directory [[email protected] ~]# ls--color=neveranaconda-ks.cfg install.log install.log.syslog# ls- A displays all files (including hidden files) [[email protected] ~]# ls-a. .. Anaconda-ks.cfg. bash_logout. Bash_profile bashrc. CSHRC install.log install.log.syslog. PKI. tcshrc# ls-l in long format file [[email protected] ~]# ls-l total usage 16-rw-------. 1 root root 1098 June 8 19:38 anaconda-ks.cfg-rw-r--r--. 1 root root 8025 June 8 19:38 install.log-rw-r--r--. 1 root root 3384 June 8 19:38 install.log.syslog# ls-d only display directory [[email protected] ~]# ls-l total usage 16-rw-------. 1 root root 1098 June 8 19:38 anaconda-ks.cfg-rw-r--r--. 1 root root 8025 June 8 19:38 install.log-rw-r--r--. 1 root root 3384 June 8 19:38 install.log.syslog# ls-i View inode node number [[email protected] ~]# ls-i260965 anaconda-ks.cfg 260611 install.log 260612 install.log.syslog
CD switch in the same directory
# cd[[email protected] ~]# cd/tmp/[[email protected] tmp]# # Enter relative path [[email protected]/]# cd/tmp/[[ Email protected] tmp]# CD. /etc/yum.repos.d/# enter absolute path [[email protected] yum.repos.d]# cd/etc/yum.repos.d/[[email protected] yum.repos.d]# ll total dosage 36drwxr-xr-x. 2 root root 4096 June 8 19:58 backup-rw-r--r--. 1 root root 1991 March Centos-base.repo-rw-r--r--. 1 root root 647 March centos-debuginfo.repo-rw-r--r--. 1 root root 289 March centos-fasttrack.repo-rw-r--r--. 1 root root 630 March centos-media.repo-rw-r--r--. 1 root root 7989 March centos-vault.repo-rw-r--r--. 1 root root 957 November 5 epel.repo-rw-r--r--. 1 root root 1056 November 5 epel-testing.repo# CD-Return to the last directory [[email protected] yum.repos.d]# pwd/etc/yum.repos.d[[e Mail protected] yum.repos.d]# CD/[[email protected]/]# CD-/etc/yum.repos.d[[email protected] yum.repos.d]# # cd ~ Enter the current user's home directory [[email protected] yum.repos.d]# CD ~[[email&Nbsp;protected] ~]# # CD. Go to the top level directory [[[email protected] ~]# cd/tmp/[[email protected] tmp]# pwd/tmp[[email protected] tmp]# CD. [[email protected]/]# pwd/
PWD Displays the directory where you are currently
# pwd[[email protected] yum.repos.d]# pwd/etc/yum.repos.d
mkdir Creating a Directory
# mkdir[[email protected] ~]# mkdir tmp[[email protected] ~]# lsanaconda-ks.cfg install.log install.log.syslog tmp# mkdir -p 递归创建目录[[email protected] ~]# mkdir -p a/b/c/d[[email protected] ~]# tree aa└── b └── c └── d3 directories, 0 files
RmDir Delete directory, only empty directory can be deleted
# rmdir[[email protected] ~]# rmdir d
RM-RF Deleting files and directories
# -r 递归,删除目录# -f 强制[[email protected] ~]# lsa anaconda-ks.cfg install.log install.log.syslog[[email protected] ~]# rm -rf a[[email protected] ~]# ll总用量 16-rw-------. 1 root root 1098 6月 8 19:38 anaconda-ks.cfg-rw-r--r--. 1 root root 8025 6月 8 19:38 install.log-rw-r--r--. 1 root root 3384 6月 8 19:38 install.log.syslog
The tree directory name displays all the contents of the directory trees in the specified directory
# tree~]# tree /etc/yum.repos.d//etc/yum.repos.d/├── backup├── CentOS-Base.repo├── CentOS-Debuginfo.repo├── CentOS-fasttrack.repo├── CentOS-Media.repo├── CentOS-Vault.repo├── epel.repo└── epel-testing.repo
File Operations Command
Touch create an empty file or modify the file last access time
# touch[[email protected] tmp]# touch replaceContent.py[[email protected] tmp]# lsreplaceContent.py yum.log# 这里需要注意的是:任何操作系统都不允许创建同名的文件和目录
Cat Viewing files
# cat[[email protected] ~]# cat install.log安装 libgcc-4.4.7-18.el6.x86_64warning: libgcc-4.4.7-18.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY安装 setup-2.8.14-23.el6.noarch安装 filesystem-2.4.30-3.el6.x86_64......# cat -n 显示行号[[email protected] ~]# cat -n install.log 1 安装 libgcc-4.4.7-18.el6.x86_64 2 warning: libgcc-4.4.7-18.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY 3 安装 setup-2.8.14-23.el6.noarch......
More split screen display file contents
# more b返回上一页,空格进入下一页[[email protected] ~]# more install.log安装 libgcc-4.4.7-18.el6.x86_64warning: libgcc-4.4.7-18.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY安装 setup-2.8.14-23.el6.noarch安装 filesystem-2.4.30-3.el6.x86_64
Less branches show file contents
# less 上下箭头分页[[email protected] ~]# less install.log安装 libgcc-4.4.7-18.el6.x86_64warning: libgcc-4.4.7-18.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY安装 setup-2.8.14-23.el6.noarch
Head display file header, default is 10 rows
# head[[email protected] ~]# head install.log安装 libgcc-4.4.7-18.el6.x86_64warning: libgcc-4.4.7-18.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY安装 setup-2.8.14-23.el6.noarch安装 filesystem-2.4.30-3.el6.x86_64安装 basesystem-10.0-4.el6.noarch安装 ncurses-base-5.7-4.20090207.el6.x86_64安装 kernel-firmware-2.6.32-696.el6.noarch安装 tzdata-2016j-1.el6.noarch安装 glibc-common-2.12-1.209.el6.x86_64安装 nss-softokn-freebl-3.14.3-23.3.el6_8.x86_64# head -n number 只显示Number行[[email protected] ~]# head -n 5 install.log安装 libgcc-4.4.7-18.el6.x86_64warning: libgcc-4.4.7-18.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY安装 setup-2.8.14-23.el6.noarch安装 filesystem-2.4.30-3.el6.x86_64安装 basesystem-10.0-4.el6.noarch
Tail display end of file
# tail 默认是文件的最后10行[[email protected] ~]# tail install.log安装 efibootmgr-0.5.4-15.el6.x86_64安装 sudo-1.8.6p3-27.el6.x86_64安装 audit-2.4.5-6.el6.x86_64安装 e2fsprogs-1.41.12-23.el6.x86_64安装 xfsprogs-3.1.1-20.el6.x86_64安装 acl-2.2.49-7.el6.x86_64安装 attr-2.4.44-7.el6.x86_64安装 bridge-utils-1.2-10.el6.x86_64安装 rootfiles-8.1-6.1.el6.noarch*** FINISHED INSTALLING PACKAGES ***[[email protected] ~]# # tail -n number 只显示文件尾部number行[[email protected] ~]# tail -n 3 install.log安装 bridge-utils-1.2-10.el6.x86_64安装 rootfiles-8.1-6.1.el6.noarch*** FINISHED INSTALLING PACKAGES ***[[email protected] ~]# # tailf 监听文件,用于监听实时日志[[email protected] ~]# touch 1.txt[[email protected] ~]# tailf 1.txt 11111
CP Copy File
cp -r 复制目录cp -p 连带文件属性复制cp -d 若源文件是链接文件,那么复制链接属性cp -a 相当于cp -rpd
MV move files or rename files
mv 源文件 目标地址mv 源文件 目标文件
ln link File
在linux文件中分为硬链接文件和软连接文件硬链接文件: 1.拥有相同的i节点和存储block块,可以看做是同一个文件。修改一个文件,另一个文件也会发生改变,删除其中一个,另一个文件还能打开 2.可以通过i节点识别 3.不能跨分区 4.不能针对目录使用 a.硬链接不能连接目录 b.硬链接不能跨分区软连接文件: 1.类似Windows快捷方式 2.软连接拥有自己的i节点和block块,但是数据中只保存原文件名和i节点号,并没有实际的文件数据,软连接目录大小不变 3.lrwxrwxrwx是软连接 a.软连接文件都是777 b.软连接的最大权限是假的,不影响实际访问,源文件受限制权限 4.删除任意文件,另一个都改变 5.删除源文件,软连接不能使用会报错,红点闪烁 ln -s 源文件 目标文件 文件名必须要写绝对路径 软连接需要绝对路径,不允许使用相对路径创建软连接的原因,照顾管理员的使用习惯,照顾版本升级需要
Permission bits
[[email protected] ~]# ll /etc总用量 1208-rw-r--r--. 1 root root 16 6月 8 19:38 adjtime-rw-r--r--. 1 root root 1512 1月 12 2010 aliases-rw-r--r--. 1 root root 12288 6月 8 19:40 aliases.dbdrwxr-xr-x. 2 root root 4096 6月 8 20:11 alternatives从redhat6更新的,第11位代表这个文件被SELinux所保护,权限位是10位,第1位代表文件类型:- 普通文件d 目录文件l 链接文件b 块设备文件c 字符设备文件s 套接字文件p 管道
chmod Modify Permissions
权限 644 标准的读写权限 755 标准的执行权限 777 最大权限 在服务器禁止出现777权限,除了系统自带的目录,不能手工更改apache权限,只需要把网页目录的所有者改成apache的管理员身份就可以了
The meaning of permissions
1.权限对文件的意义 r:读取文件的内容 more/cat/less/tail w:编辑、现在、修改文件内容,不包括删除文件 vi/echo r:可执行 对于文件来说:执行权限是最高权限2.权限对目录的意义 r:可以查询目录下的文件名 ls w:具有修改目录结构的权限。如新增文件和目录,删除此目录下的文件,重命名等操作 touch rm mv cp x:可以进入目录 对于目录来说:写权限才是最高权限,写权限要小心赋予
Chown change owner and owning group
# chown[[email protected] ~]# lltotal 8-rw-r--r-- 1 root root 856 Jun 2 19:33 client.pydrwxr-xr-x 2 root root 6 Jun 6 11:16 root-rw-r--r-- 1 root root 1024 Jun 2 19:26 server.py[[email protected] ~]# useradd xiaouseradd: user ‘xiao‘ already exists[[email protected] ~]# chown xiao:xiao server.py [[email protected] ~]# lltotal 8-rw-r--r-- 1 root root 856 Jun 2 19:33 client.pydrwxr-xr-x 2 root root 6 Jun 6 11:16 root-rw-r--r-- 1 xiao xiao 1024 Jun 2 19:26 server.py
CHRGP belongs to group file name
Find Command
which the command to find the command, you can see the related aliases
# which[[email protected] ~]# which vialias vi=‘vim‘ /usr/bin/vim # 实际上也相当于是查询别名的操作
Whereis command for query commands, and the path to the Help document
# whereis[[email protected] ~]# whereis vivi: /bin/vi /usr/share/man/man1/vi.1.gz和which相同点: 可以查找出命令的绝对路径和which不同点: whereis可以列出帮助文档的存放位置,而which可以查询命令的别名
Locate search by file name by database
# Locate # This command is available in CENTOS6, you need to install mlocate in Centos7, and then initialize the database updatedb[[email protected] ~]# locate inittab/etc/ Inittab/usr/share/man/man5/inittab.5.gz/usr/share/vim/vim74/syntax/inittab.vim Advantages: In the background to establish database/var/lib/mlocate, Record the file name of the current system, search by the database to find the least cost, the faster the first update of the data volume Slow Update Database command: UpdateDB configuration file Location:/etc/updatedb.conf# locate-i case-insensitive lookup [[email  ;p rotected] ~]# touch ABC. Conf[[email protected] ~]# Touch abc.conf[[email protected] ~]# updatedb[[email protected] ~]# Locate Abc.conf-i/root/abc. conf/root/abc.conf# configuration file contents [[email protected] ~]# more/etc/updatedb.conf prune_bind_mounts = "Yes" PRUNEFS = "9p AFS Anon_inodefs Auto AutoFS bdev binfmt_misc cgroup cifs coda Configfs cpuset debugfs devpts ecryptfs exofs Fuse Fusectl GFs GFS2 GPFs hugetlbfs inotifyfs iso9660 jffs2 lustre Mqueue ncpfs NFS nfs4 nfsd pipefs proc Ramfs rootfs rpc_pipefs Security FS Selinuxfs SFS sockfs sysfs tmpfs ubifs udf usbfs "prunenames =". Git. Hg. svn "prunepaths ="/afs/media/net/sfs/tmp/ Udev/vaR/cache/ccache/var/spool/cups/var/spool/squid/var/tmp "Prune_bind_mounts configuration file is in effect
Help for man viewing commands
Find
# Find File Search command (scan the entire root, the more files, the larger the hard disk, the slower the speed) according to the file name to find [[email protected] ~]# find/etc-name init # in the/etc directory to search for the init file (more than one character is not Line)/etc/sysconfig/init/etc/init[[email protected] ~]# find/etc-name *init* # Search for files containing init in/etc directory, * is a wildcard character/etc/ init.conf/etc/sysconfig/network-scripts/init.ipv6-global/etc/sysconfig/init/etc/inittab/etc/rc.sysinit/etc/ rc.d/rc.sysinit/etc/rc.d/init.d/etc/pam.d/run_init/etc/init.d/etc/init/etc/init/init-system-dbus.conf/etc/ Iscsi/initiatorname.iscsi/etc/selinux/targeted/contexts/initrc_context/etc/security/namespace.init[[email protected] ~]# find/etc-name init? #? Represents a single character-iname is not going to technician case [[email protected] ~]# find/etc-name Init??? /etc/inittab Search by Time [[email protected] ~]# find/etc-cmin-5 # Find files and directories with modified properties for 5 minutes in/etc more than 5 minutes with +/etc/etc/cron.daily/ Etc/cron.daily/makewhatis.cron/etc/man.config find Find/-size by size +27k Search by owner and owning group [[email protected] ~]# Find/- User Xiao[[email protected] ~]# Find/-group Xiao based on I-node lookup [[email protected] ~]# ll-I total dosage 20260617-rw-r--r--. 1 root root 6 June 23:05 1.txt260971-rw-r--r--. 1 root root 0 June 01:53 abc.conf260970-rw-r--r--. 1 root root 0 June 01:53 ABC. CONF260965-RW-------. 1 root root 1098 June 8 19:38 anaconda-ks.cfg260611-rw-r--r--. 1 root root 8025 June 8 19:38 install.log260612-rw-r--r--. 1 root root 3384 June 8 19:38 install.log.syslog[[email protected] ~]# find. -inum 260617./1.txtfind/etc–size +80m–a–size-100m # Find files larger than 80MB less than 100MB in/etc directory-a representation logic with and two conditions are established-O for logical OR OR Two conditions to set up one of them to execute
grep searches the contents of the file for string-matching rows and outputs
# grep -i[指定字符串] 文件名 输出包含指定字符串的行[[email protected] ~]# grep -i ‘root‘ /etc/passwdroot:x:0:0:root:/root:/bin/bashoperator:x:11:0:operator:/root:/sbin/nologin# grep -v [指定字符串] 文件名 输出不包含指定字符串的行[[email protected] ~]# cat 1.txt 12345[[email protected] ~]# grep -v 2 1.txt 1345find和grep的区别: find:在系统中搜索符合条件的文件名,如果需要匹配,使用通配符匹配,通配符是完全匹配的,find不支持文本刘操作,不支持管道符。 grep:在文件内容中搜索负责条件的字符串的行并输出,如果需要匹配,使用正则表达式,正则表达式是包含匹配。管道符是文本流。
Network commands
Netstat viewing system network status
netstat [options]-T TCP port-U UDP port-L Monitoring-n is displayed as IP and port number instead of host name and protocol name# netstat-tln[[Email protected]~]# NETSTAT-TLActive Internet connections (only servers) Proto RECV-Q Send-Q Local Address Foreign address State TCP0 0 *: SSH*:*LISTEN TCP0 0Localhost:smtp*:*LISTEN TCP0 0 *: SSH*:*LISTEN TCP0 0Localhost:smtp*:*LISTEN [[Email protected]~]# netstat-tlnActive Internet connections (only servers) Proto RECV-Q Send-Q Local Address Foreign address State TCP0 0 0.0.0.0: A 0.0.0.0:*LISTEN TCP0 0 127.0.0.1: - 0.0.0.0:*LISTEN TCP0 0::: A:::*LISTEN TCP0 0::1: -:::*LISTEN
W query all users who are currently logged on to the server
# w[[email protected] ~]# w 02:16:55 up 3:47, 2 users, load average: 0.00, 0.00, 0.00USER TTY FROM [email protected] IDLE JCPU PCPU WHATroot tty1 - 22:30 3:44m 0.09s 0.09s -bashroot pts/0 192.168.190.1 22:32 0.00s 0.50s 0.04s w其中第一行: 02:16:55 up 代表开机时间 3:47 代表登录时间 2 users 代表当前有几个用户登录 load average: 0.00, 0.00, 0.00 代表1/5/12分钟前的平均压力值第二行: USER 代表用户名 TTY 登录终端 IP 登录的IP [email protected] 登录的持续时间 IDLE idle用户的闲置时间 JCPU 所有进程占用CPU时间 PCPU 当前进程占用CPU时间 WHAT 正在执行什么操作
登录终端: tty1-tty6 字符终端 tty7 图形终端 pts/0-255 远程终端
Who queries the logged-on user
# who[[email protected] ~]# whoroot tty1 2018-06-10 22:30root pts/0 2018-06-10 22:32 (192.168.190.1)登录用户名 登录终端 登录时间 登录的主机IP地址
Last list information about the login system
# last[[email protected] ~]# lastroot pts/1 192.168.190.1 Sun Jun 10 23:05 - 01:39 (02:33) root pts/0 192.168.190.1 Sun Jun 10 22:32 still logged in root tty1 Sun Jun 10 22:30 still logged in reboot system boot 2.6.32-696.el6.x Sun Jun 10 22:29 - 02:22 (03:52) root pts/0 192.168.190.1 Fri Jun 8 20:01 - crash (2+02:28) root tty1 Fri Jun 8 19:41 - crash (2+02:48) reboot system boot 2.6.32-696.el6.x Fri Jun 8 19:40 - 02:22 (2+06:42) wtmp begins Fri Jun 8 19:40:12 2018# 所有登录信息都在/var/run/utmp下,但是是不能修改的
Ifconfig Viewing native Network information
All system common services are under/etc/services
Power off Restart command
# sync 数据同步,把内存中数据强制保存到硬盘里# 关机命令 1.shutdown -h now 2.init 0 3.halt 3.poweroff# 重启命令 1.shutdown -r now 2.reboot 3.init 6
System operating level in Linux
0 关机1 单用户2 不完全多用户,不含NFS服务3 完全多用户4 未分配5 图形界面6 重启
Mount command
# mountlinux中所有存储设备都必须挂载使用,包括硬盘# mount -l 查询系统中已经挂载的设备,-l会显示卷标名称[[email protected] ~]# mount -l/dev/mapper/VolGroup-lv_root on / type ext4 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")/dev/sda1 on /boot type ext4 (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)# mount -a 检测/etc/fstab的内容,自动挂载 在这里,如果挂载的是U盘或者光盘,如果下次开机没有放入,那么系统就不会启动 所以需要mount -a 检查下文件内容是否出错# mount [-t 文件系统] [-l 卷标名] [-o 特殊选项] 设备文件名挂载选项: -t 文件系统 ext3/ext4/iso9660 -l 卷标名 挂载指定卷标的分区,而不是安装设备文件名挂载 -o 特殊选项,可以指定挂载的额外选项,比如读写权限、同步异步等,如不制定默认值生效 # dumpe2fs 查看分区的详细信息[[email protected] ~]# dumpe2fs -h /dev/sda1
Linux Common commands