以下为我在使用中遇见的常用指令 后期遇到再丰富
快捷键
CTRL+L 清屏 |
CTRL+U 从起始位置删除 |
CTRL+A 回到行首 |
CTRL+E 回到行尾 |
基本概念
一些目录的含义
权限含义
命令
cd 路径 | 切换目录 |
|
[root@CentOS6 zookeeper-3.4.6]# cd bin/ |
cd.. | 返回上一层文件目录 |
|
[root@CentOS6 bin]# cd .. |
ll | 显示当前文件夹下文件并且包含具体信息 |
| [root@CentOS6 bin]# ll 总用量 44 -rwxr-xr-x. 1 1000 1000 238 2月 20 2014 README.txt -rwxr-xr-x. 1 1000 1000 1937 2月 20 2014 zkCleanup.sh -rwxr-xr-x. 1 1000 1000 1049 2月 20 2014 zkCli.cmd -rwxr-xr-x. 1 1000 1000 1534 2月 20 2014 zkCli.sh -rwxr-xr-x. 1 1000 1000 1333 2月 20 2014 zkEnv.cmd |
ls | 查看目录中内容 |
|
[root@CentOS6 bin]# ls |
cat 文本文件 | 查看某个文本文件 |
vim 文本文件 | 编辑某个文本文件 |
vim中按a或者i | 进入文本编辑模式 |
vim中按esc 输入:wq! | 编辑完成并保存结果 |
vim中按esc 输入:q! | 编辑结束但不保存结果 |
rm -rf 文件名 | 删除某个文件 |
|
-rw-rw-r--. 1 1000 1000 535 2月 20 2014 configuration.xsl |
mv 文件名 路径 | 移动文件到某个位置 |
| [root@CentOS6 conf]# ll 总用量 20 drwxr-xr-x. 2 root root 4096 7月 19 02:24 test -rw-r--r--. 1 root root 934 7月 19 02:22 zoo2.cfg -rw-r--r--. 1 root root 934 7月 18 22:00 zoo.cfg [root@CentOS6 conf]# mv zoo2.cfg test [root@CentOS6 conf]# ll 总用量 16 drwxr-xr-x. 2 root root 4096 7月 19 02:25 test -rw-r--r--. 1 root root 934 7月 18 22:00 zoo.cfg [root@CentOS6 conf]# cd test [root@CentOS6 test]# ll 总用量 4 -rw-r--r--. 1 root root 934 7月 19 02:22 zoo2.cfg [root@CentOS6 test]# ![]() |
mv 文件名 文件名 | 改名 |
| [root@CentOS6 conf]# mv zoo1.cfg zoo2.cfg [root@CentOS6 conf]# ll 总用量 16 -rw-rw-r--. 1 1000 1000 535 2月 20 2014 configuration.xsl -rw-rw-r--. 1 1000 1000 2161 2月 20 2014 log4j.properties -rw-r--r--. 1 root root 934 7月 19 02:22 zoo2.cfg -rw-r--r--. 1 root root 934 7月 18 22:00 zoo.cfg [root@CentOS6 conf]# |
tar zxvf 压缩包名gz | 解压缩文件 z代表文件格式,x代表解压缩,v代表显示解压过程,f代表文件名的意思 |
mkdir 路径 | 创建一个目录 |
| [root@CentOS6 conf]# mkdir test [root@CentOS6 conf]# ll 总用量 20 -rw-rw-r--. 1 1000 1000 535 2月 20 2014 configuration.xsl -rw-rw-r--. 1 1000 1000 2161 2月 20 2014 log4j.properties drwxr-xr-x. 2 root root 4096 7月 19 02:24 test -rw-r--r--. 1 root root 934 7月 19 02:22 zoo2.cfg -rw-r--r--. 1 root root 934 7月 18 22:00 zoo.cfg |
mkdir 路径 -p |
递归创建文件夹要加-p
|
|
mkdir /var/temp/nginx/client -p |
cp 文件名 新文件名 | 复制并改名 |
| [root@CentOS6 conf]# ll 总用量 12 -rw-rw-r--. 1 1000 1000 535 2月 20 2014 configuration.xsl -rw-rw-r--. 1 1000 1000 2161 2月 20 2014 log4j.properties -rw-r--r--. 1 root root 934 7月 18 22:00 zoo.cfg [root@CentOS6 conf]# cp zoo.cfg zoo1.cfg [root@CentOS6 conf]# ll 总用量 16 -rw-rw-r--. 1 1000 1000 535 2月 20 2014 configuration.xsl -rw-rw-r--. 1 1000 1000 2161 2月 20 2014 log4j.properties -rw-r--r--. 1 root root 934 7月 19 02:22 zoo1.cfg -rw-r--r--. 1 root root 934 7月 18 22:00 zoo.cfg ![]() |
cp -r 文件夹 新文件夹 | 复制整个文件夹 |
| [root@CentOS6 nginx]# ll 总用量 12 drwxr-xr-x. 2 root root 4096 7月 24 17:06 conf drwxr-xr-x. 2 root root 4096 7月 24 17:06 html drwxr-xr-x. 2 root root 4096 7月 24 17:06 sbin [root@CentOS6 nginx]# cp -r html html81 [root@CentOS6 nginx]# ll 总用量 16 drwxr-xr-x. 2 root root 4096 7月 24 17:06 conf drwxr-xr-x. 2 root root 4096 7月 24 17:06 html drwxr-xr-x. 2 root root 4096 7月 24 18:04 html81 drwxr-xr-x. 2 root root 4096 7月 24 17:06 sbin |
pwd | 查看当前目录的全路径 |
| [root@CentOS6 bin]# pwd /root/zookeeper-3.4.6/bin |
service iptables status | 查看防火墙是否开启 |
service iptables stop | 临时关闭防火墙 |
| root@CentOS6 bin]# service iptables stop iptables:将链设置为政策 ACCEPT:filter [确定] iptables:清除防火墙规则: [确定] iptables:正在卸载模块: [确定] |
chkconfig iptables off | 永久关闭防火墙,修改配置开机不启动防火墙 |
| [root@CentOS6 bin]# chkconfig iptables off |
tail -f logs/catalina.out | 尾部打印查看,用于服务器中查看tomcat的控制台使用..查看最后100行日志:tail -100 info.log -- 100为行数,info.log为日志文件名 |
| [root@CentOS6 apache-tomcat-7.0.47]# tail -f logs/catalina.out 七月 19, 2018 6:27:44 上午 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory /root/apache-tomcat-7.0.47/webapps/docs 七月 19, 2018 6:27:44 上午 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory /root/apache-tomcat-7.0.47/webapps/ROOT 七月 19, 2018 6:27:44 上午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-bio-8080"] 七月 19, 2018 6:27:44 上午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-bio-8009"] 七月 19, 2018 6:27:44 上午 org.apache.catalina.startup.Catalina start 信息: Server startup in 42122 ms |
ps aux|grep nginx | 其中ps -aux 显示所有用户进程,grep nginx 是过滤条件 此处是过滤所有带有nginx的进程 |
| [root@CentOS6 sbin]# ps aux|grep nginx root 1858 0.0 0.0 23852 796 ? Ss 17:18 0:00 nginx: master process ./nginx nobody 1859 0.0 0.1 24280 1388 ? S 17:18 0:00 nginx: worker process root 1877 0.0 0.0 103328 844 pts/0 S+ 17:24 0:00 grep nginx |
sudo netstat -antup | grep pid | 根据pid查询端口号 |
| [root@localhost bin]# sudo netstat -antup |grep 1782 tcp 0 0 :::58109 :::* LISTEN 1782/java tcp 0 0 :::8161 :::* LISTEN 1782/java tcp 0 0 :::5672 :::* LISTEN 1782/java |
-console | 打印控制台 |
| [root@localhost bin]# ./activemq -console INFO: Loading '/root/apache-activemq-5.12.0//bin/env' INFO: Using java '/usr/java/jdk1.7.0_71/bin/java' |
find | 查找文件 |
|
(1)find / -name httpd.conf #在根目录下查找文件httpd.conf,表示在整个硬盘查找
[root@centOS6 ~]# find /root -name "12[34]"
|
/8080 | 文本中查询关键字 |
| vi 进入编辑模式以后 输入/8080会高亮所有8080关键字 |
locate | 文件搜索命令 比find快 缺点:1.不是实时的 会在数据库中找 新建的查询不到,一天一更新,2.只能根据文件名查询,功能单一 |
| ![]() |
whereis | 搜索命令的命令 |
|
[root@centOS6 ~]# whereis ls whatis 是什么 [root@centOS6 ~]# whatis ls |
grep | |
|
|
man | 帮助选项 |
| [root@centOS6 ~]# man ls |
zip | 压缩解压zip文件 |
|
|
gzip | 压缩解压gz文件 |
|
|
tar | 打包命令 |
|
不解压只查看压缩包里面的内容
[root@centOS6 ~]# tar -ztvf 124.tar.gz |
showdown | 定时关机重启 shutdown会保存服务器上正在运行的服务数据。建议使用 |
|
[root@centOS6 ~]# shutdown -r 21:03 Broadcast message from root@centOS6.8 The system is going down for reboot in 2 minutes! ^Cshutdown: Shutdown cancelled
[root@centOS6 ~]# shutdown -r 21:40 & The system is going down for reboot in 37 minutes! [root@centOS6 ~]# |
logout | 当前用户退出登录 一定要记住 不然会占用 |
| |
w、who | 登录用户信息查询 |
|
|
netstat | 查询网络状态 |
![]() | |
wc | 统计文件中有多少行 多少单词 多少个字符 |
wc -l 显示多少行 | |
netstat -rn | 查看网关 |
![]() | |
nslookup | 域名 IP地址翻译 |
![]() | |
nslookup --> service | 查看本机网关 |
![]() | |
telent | 一般不用在远程管理不安全,一般用在判断端口是否开放,或者防火墙是否允许访问该端口 |
![]() | |
traceroute | 路由跟踪命令 |
![]() | |
wget | 下载命令 |
![]() | |
tcpdump | 抓包 |
![]() | |
ssh | 远程控制 |
![]() | |
adduser 用户名 | 添加用户 linux中添加用户既会添加一个用户组 |
[root@localhost user1]# adduser testuser | |
passwd 用户名 | 设置密码 |
[root@localhost user1]# passwd testuser 更改用户 testuser 的密码 。 新的 密码: 无效的密码: 过于简单化/系统化 无效的密码: 过于简单 重新输入新的 密码: passwd: 所有的身份验证令牌已经成功更新。 | |
chmod 755 文件名 | 设置修改权限 |
[root@localhost user1]# ll 总用量 4 drwxr-xr-x. 2 root root 4096 2月 18 05:20 123 [root@localhost user1]# chmod 750 123 [root@localhost user1]# ll 总用量 4 drwxr-x---. 2 root root 4096 2月 18 05:20 123 | |
chown 用户名 文件名 | 改变文件所有者 |
[root@localhost user1]# chown user1 123/abc 衍生用法 同时修改用户和用户组 chown 用户名:用户组 文件名 [root@localhost user1]# ll 123/abc
|
chgrp | 切换所属用户组 |
root@localhost user1]# ll 123/ 总用量 0 -rwxr-xr-x. 1 user1 root 0 2月 18 05:20 abc [root@localhost user1]# chgrp user1 123/abc [root@localhost user1]# ll 123/abc -rwxr-xr-x. 1 user1 user1 0 2月 18 05:20 123/abc | |
groupadd 用户组名 | 创建用户组 |
[root@localhost user1]# groupadd user | |
gpasswd -a 用户名 目标用户组 | 将用户添加到指定组 |
[root@localhost user1]# gpasswd -a user1 user 正在将用户“user1”加入到“user”组中 | |
df | 查看系统分区情况 |
[root@localhost ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda5 13203792 2542852 9983564 21% / tmpfs 502068 0 502068 0% /dev/shm /dev/sda1 194241 33773 150228 19% /boot /dev/sda2 4908544 10124 4642420 1% /home | |
mount | 挂载命令,类似于给U盘或者光盘指定盘符 |
| |
mount 设备文件名 挂载点 | 挂载光盘 |
| |
umount | 卸载光盘 卸载前要退出挂载点目录 |
![]() | |
fdisk | 挂载U盘 先查询U盘设备文件名 移动硬盘是NTFS文件系统,不能识别除非编译内核 |
| |
sed |
|
[root@pwgh bin]# sed -n '/09:22:50/','/09:22:58/p' ../logs/catalina.out | |