Efficient instructions under Linux
查看当前磁盘使用情况:df -h fdisk -l (查看所有的硬盘)
服务器添加硬盘:在系统设置添加
分区: fdisk /dev/sdb (sdb, sdc, sde) 指令:m(帮助信息), n (新加分区) 第二步: 指令p (主分区) 第三步:写入磁盘 w 使用:挂载: mount /dev/sdb1 /data/ 挂载到/data目录下,挂载成功如下
可以挂载到多个设备
mount /dev/cdrom /mnt
所有的指令都是在指令行下输入的,不是在编辑模式下进行的!
复制多行/单行:输入yy,然后按k
删除某一行:按dd; 删除某个字符: 光标选中某个字符,按x
删错某个字符/某一行想返回:u
替换某个文件所有内容:%s/failymao/momo/g (ESC后:替换文件中所有【g表示所有】falilymao的内容为momo
替换某一行某个内容:%s/momo/failymao/1 (替换最后一行)
在首行添加某个字符或者空白字符:%s/my/ my/g
第二种方法(my后面添加空格) :%s/my/& /
首行添加:%s/^/& /(^正则首行,&表示追加)
末尾行添加:%s/$/& hello($表示末尾)
匹配行前插入空白行:某个字符下按 O(大写),行后插入空白行按o(小写)
跳转:
跳转最后一个字符:GG
跳转第一个字符:gg
查找: /my
删除匹配的项目之后的所有内容:dG
替换某个文件所有的内容:
sed 's/momo/failymao/g' test.txt(查看替换,s表示查找) sed -i 's/momo/failymao/g' test.txt替换(加参数 -i 表示写入) 匹配行前插入:sed -i '/IS/i 123456' test.txt 匹配行后插入:sed -i '/IS/a 123456' test.txt (a 表示after) 修改某个配置文件信息:sed '/SELINUX/s/disabled/123456/g' /etc/selinux/config (修改 /etc/selinux/config配置文件中SELTINUX后面的disabled为123456)
查找当前目录某个文件:*find . -name "test.txt" 查找根目录某个文件:find / -name "test.txt" 查找以固定格式结尾的所有文件:find . name "*.py" 查找以固定格式结尾的目录或者文件: find . name "*.py" -typt d (d表示类型目录) 查找以固定格式结尾的目录或者文件: find . name "*.py" -typt d -mtime +1 -size +10M (d表示类型为目录,-mtime +1 表示一天以上,-1表示1天之内,-size表示大小为10M的文件目录) 查找文件包含有某些内容的文件: find /tmp/ -name "*" -type f -name "momo" 查找的文件进行拷贝:find /root/ -name "*" -type f -name "*server*" -exec cp {}/samba \;(查找/root目录下,查找以文件中包含有server的文件,并(-exec)复制(cp)到 ({}接目录)/samba目录下,(;)固定格式) 打包:find /root/ -name "*.py" -exec tar czf zip_python.tar.gz {} \; (将查找/root目录下以py结尾的文件并在当前目录下打包) 删除文件:find /samba -name "*" -type f -name "*server*" -exec rm -rf {} \;(删除/samba下,包含文件名中含有“server”的所有的文件!) 删除文件 == 等同于exec:find /root/ -name "*.py" | xargs rm -rf {} \; (管道符| xargs 等同于 -exec)
过滤文件:前面的结果作为后面的输入: cat test.txt |grep "hou"(查看text.txt文件中有“hou”的内容) == grep "hou" test.txt 排除文件:cat /etc/passwd |grep -v "mysql"(过滤掉/etc/passwd中含有“mysql”的内容,打印出结果!) 打印过滤的固定的某一行:ifconfig |grep "net" |awk '{print $1}'(打印ifconfig命令中含有net的字符的,第一列内容)
grep '^10' text.txt 匹配以10`开头 grep '10$' text.txt匹配以10结尾 grep "[0-9][0-9][0-9] " test.txt 匹配三位数的任意组成的数 grep "[a-z]" test.txt匹配 包含有a-z字母的字段(小写) grep "^112$" text.txt匹配以112开头结尾的 (grep -E "[0-9]{1,3}\."){3}匹配0-9的任意数字1-3次,. 表示匹配.,{3}出现三次
查看内存信息:free -m 查看cup: top 查看httpd:ps -ef |grep httpd 查看tcp端口:netstat -tnl 查看udp: netstat -nul 查看当前目录文件大小: du -sh
其他应用实例:输出文本数据中最大最小的数
112 1223 444 334 444 11 22 444 578 23123 1234 3443 234553 122 908 123445 12 14 567 456 23478 执行 :cat number.txt |sed 's/ /\n/g' |grep -v "^$"|sort -nr |sed -n '1p;$p' 指令详解: 1) sed 's/ /\n/g' 将所有空格转化成换行 2) |grep -v "^$"把开头结尾都是空格的组 排除掉, -v 表示排除 3) |sort -nr从大到小排序 4) |sed -n '1p;$p' -n表示多行打印, 1p表示第一个,$p表示最后一个
指定打印匹配的某一行
cat test.txt |awk '{print $4}' --->打印匹配的第四列 ($NF表示最后一列) cat /etc/passwd |awk -F: '{print $1}'---> -F表示format,自定义格式,打印第一列 示例 ifconfig 匹配出IP地址 方法1: ifconfig eth1|grep "broadcast" |awk '{print $2}'|sed 's/addr://g'打印ip 地址 方法2:ifconfig eth1|grep "broadcase"|awk '{print $2}'|awk -F: '{print $2}' df -h |grep "/$" |awk '{print $5}'|sed 's/%//g' 打印硬盘使用率 ,去掉百分号
linux指令的熟练度决定了你是否能成为一个运维届的老司机,能否开五菱宏光顺利上秋名山!切记多练!多练!多练!
The above is the detailed content of Efficient instructions under Linux. For more information, please follow other related articles on the PHP Chinese website!

Linux and Windows differ in hardware compatibility: Windows has extensive driver support, and Linux depends on the community and vendors. To solve Linux compatibility problems, you can manually compile drivers, such as cloning RTL8188EU driver repository, compiling and installing; Windows users need to manage drivers to optimize performance.

The main differences between Linux and Windows in virtualization support are: 1) Linux provides KVM and Xen, with outstanding performance and flexibility, suitable for high customization environments; 2) Windows supports virtualization through Hyper-V, with a friendly interface, and is closely integrated with the Microsoft ecosystem, suitable for enterprises that rely on Microsoft software.

The main tasks of Linux system administrators include system monitoring and performance tuning, user management, software package management, security management and backup, troubleshooting and resolution, performance optimization and best practices. 1. Use top, htop and other tools to monitor system performance and tune it. 2. Manage user accounts and permissions through useradd commands and other commands. 3. Use apt and yum to manage software packages to ensure system updates and security. 4. Configure a firewall, monitor logs, and perform data backup to ensure system security. 5. Troubleshoot and resolve through log analysis and tool use. 6. Optimize kernel parameters and application configuration, and follow best practices to improve system performance and stability.

Learning Linux is not difficult. 1.Linux is an open source operating system based on Unix and is widely used in servers, embedded systems and personal computers. 2. Understanding file system and permission management is the key. The file system is hierarchical, and permissions include reading, writing and execution. 3. Package management systems such as apt and dnf make software management convenient. 4. Process management is implemented through ps and top commands. 5. Start learning from basic commands such as mkdir, cd, touch and nano, and then try advanced usage such as shell scripts and text processing. 6. Common errors such as permission problems can be solved through sudo and chmod. 7. Performance optimization suggestions include using htop to monitor resources, cleaning unnecessary files, and using sy

The average annual salary of Linux administrators is $75,000 to $95,000 in the United States and €40,000 to €60,000 in Europe. To increase salary, you can: 1. Continuously learn new technologies, such as cloud computing and container technology; 2. Accumulate project experience and establish Portfolio; 3. Establish a professional network and expand your network.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

The core of the Linux operating system is its command line interface, which can perform various operations through the command line. 1. File and directory operations use ls, cd, mkdir, rm and other commands to manage files and directories. 2. User and permission management ensures system security and resource allocation through useradd, passwd, chmod and other commands. 3. Process management uses ps, kill and other commands to monitor and control system processes. 4. Network operations include ping, ifconfig, ssh and other commands to configure and manage network connections. 5. System monitoring and maintenance use commands such as top, df, du to understand the system's operating status and resource usage.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),