Site Overlay

CentOS 常用指令

一、文件目录类:

.建立目录:mkdir 目录名

.删除空目录:rmdir 目录名

.无条件删除子目录: rm -rf 目录名

.改变当前目录:cd 目录名 (进入用户home目录:cd ~;进入上一级目录:cd -)

.查看自己所在目录:pwd

.查看当前目录大小:du

.显示目录文件列表:ls -l (-a:增加显cp 源文件目标文件 (-r:包含目录)

示隐含目录)其中:蓝:目录;绿:可执行文件;红: 压缩文件;浅蓝:链接文件;灰:其他文件;红底白字:错误的链接文件

.浏览文件:more 文件名.txt;less 文件名.txt

.复制文件: .查找文件:(1)find (2)locate 命令名

.链接:(1)建立hard链接:ln 来源文件链接文件(-d:创建目录链接);(2)建立符号链接: ln -s 来源文件链接文件

.删除文价夹以及文件夹的文件:

rm -r + 目录/文件名 : 使用递归删除,好处是能看到,缺点是对于文件夹删除的话会特别的慢

rm -rf + 目录/文件名 : 彻底删除文件夹,好处是一次性干净,缺点是如果看的不仔细误删别的文件就GG了

rm -ir + 目录/文件名 : 交互式删除文件,好处就是每次删东西都会让你确认一下,缺点还是对于整个不要的文件就显得有些慢了

.创建脚本:vi + 目录/文件名

.将xxx移动到xxx文件夹:mv xxx /xxx

.find命令: 基本格式:find  path expression

1.按照文件名查找:

(1)find / -name httpd.conf #在根目录下查找文件httpd.conf,表示在整个硬盘查找。

(2)find /etc -name httpd.conf  #在/etc目录下文件httpd.conf。

(3)find /etc -name ‘*srm*’  #使用通配符*(0或者任意多个)。表示在/etc目录下 查找文件名中含有字符串‘srm’的文件。

(4)find . -name ‘srm*’   #表示当前目录下查找文件名开头是字符串‘srm’的文件。

2.按照文件特征查找:

(1)find / -amin -10   # 查找在系统中最后10分钟访问的文件(access time)。

(2)find / -atime -2   # 查找在系统中最后48小时访问的文件。

(3)find / -empty   # 查找在系统中为空的文件或者文件夹。

(4)find / -group cat   # 查找在系统中属于 group为cat的文件。

(5)find / -mmin -5   # 查找在系统中最后5分钟里修改过的文件(modify time)。

(6)find / -mtime -1   #查找在系统中最后24小时里修改过的文件。

(7)find / -user fred   #查找在系统中属于fred这个用户的文件。

(8)find / -size +10000c  #查找出大于10000000字节的文件(c:字节,w:双字,k:KB, M:MB,G:GB)。

(9)find / -size -1000k   #查找出小于1000KB的文件。

3.使用混合查找方式查找文件: 参数有: !,-and(-a),-or(-o)。

(1)find /tmp -size +10000c -and -mtime +2   #在/tmp目录下查找大于10000字节 并在最后2分钟内修改的文件。

(2)find / -user fred -or -user george   #在/目录下查找用户是fred或者george 的文件文件。

(3)find /tmp ! -user panda #在/tmp目录中查找所有不属于panda用户的文件。

 

Javac编译: javac <options> <source files>

where possible options include:

-g Generate all debugging info

-g:none Generate no debugging info

-g:{lines,vars,source} Generate only some debugging info

-nowarn Generate no warnings

-verbose Output messages about what the compiler is doing

-deprecation Output source locations where deprecated APIs are used

-classpath <path> Specify where to find user class files and annotation processors

-cp <path> Specify where to find user class files and annotation processors

-sourcepath <path> Specify where to find input source files

-bootclasspath <path> Override location of bootstrap class files

-extdirs <dirs> Override location of installed extensions

-endorseddirs <dirs> Override location of endorsed standards path

-proc:{none,only} Control whether annotation processing and/or compilation is done.

-processor <class1>[,<class2>,<class3>…] Names of the annotation processors to run; bypasses default discovery process

-processorpath <path> Specify where to find annotation processors

-parameters Generate metadata for reflection on method parameters

-d <directory> Specify where to place generated class files

-s <directory> Specify where to place generated source files

-h <directory> Specify where to place generated native header files

-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files

-encoding <encoding> Specify character encoding used by source files

-source <release> Provide source compatibility with specified release

-target <release> Generate class files for specific VM version

-profile <profile> Check that API used is available in the specified profile

-version Version information

-help Print a synopsis of standard options

-Akey[=value] Options to pass to annotation processors

-X Print a synopsis of nonstandard options

-J<flag> Pass <flag> directly to the runtime system

-Werror Terminate compilation if warnings occur

@<filename> Read options and filenames from file

  grep命令: 

               基本格式:

              find  expression

     1.主要参数

    [options]主要参数:

    -c:只输出匹配行的计数。

    -i:不区分大小写

    -h:查询多文件时不显示文件名。

    -l:查询多文件时只输出包含匹配字符的文件名。

    -n:显示匹配行及行号。

    -s:不显示不存在或无匹配文本的错误信息。

    -v:显示不包含匹配文本的所有行。

    pattern正则表达式主要参数:

    \: 忽略正则表达式中特殊字符的原有含义。

    ^:匹配正则表达式的开始行。

    $: 匹配正则表达式的结束行。

    \<:从匹配正则表达 式的行开始。

    \>:到匹配正则表达式的行结束。

    [ ]:单个字符,如[A]即A符合要求 。

    [ – ]:范围,如[A-Z],即A、B、C一直到Z都符合要求 。

    .:所有的单个字符。

    * :有字符,长度可以为0。

    2.实例  

  (1)grep ‘test’ d*  #显示所有以d开头的文件中包含 test的行

  (2)grep ‘test’ aa bb cc    #显示在aa,bb,cc文件中包含test的行

  (3)grep ‘[a-z]\{5\}’ aa   #显示所有包含每行字符串至少有5个连续小写字符的字符串的行

  (4)grep magic /usr/src  #显示/usr/src目录下的文件(不含子目录)包含magic的行

  (5)grep -r magic /usr/src  #显示/usr/src目录下的文件(包含子目录)包含magic的行

  1. grep -w pattern files :只匹配整个单词,而不是字符串的一部分(如匹配’magic’,而不是’magical’),

二、驱动挂载类:

.检查硬盘使用情况:df -T -h

.检查磁盘分区:fdisk -l

.挂载软硬光区:mount -t /dev/fdx|hdax /mnt/目录名

其中::modos–FAT16;vfat–FAT32;ntfs–NTFS;光驱–iso9660

.支持中文名:mount -o iocharset=x /dev/hdax /mnt/目录名(其中:x=cp936或 挂载光驱: mount -t auto /dev/cdrom /mnt/cdrom

.挂载ISO文件:mount -t iso9660 -o loop xxx.iso /path

.解除挂载:umount /mnt/目录名

.解除所有挂载:umount -a

.建立文件系统:mkfs -t /dev/hdxx。其中:ftype:ext2、ext3、swap等

三、程序安装类:

下载命令:wget 网站/文件名

.RPM包安装:

(1)安装: rpm -ivh somesoft.rpm

(2)反安装(卸载): rpm -e somefost.rpm

(3)查询: rpm -q somefost 或 rpm -qpi somefost.rpm(其中:p未安装;i包含的信息)

(4)查询安装后位置:rpm -ql somefost.rpm

(5)升级安装:rpm -Uvh somesoft.rpm

(6)强制安装:rpm -ivh –nodeps somesoft.rpm 或 rpm -ivh –nodeps –force omesoft.rpm

.源代码包安装:查阅README基本用法

(1)配置:解压目录下 ./configure

(2)编译:解压目录下 make

(3)安装:解压目录下 make install

.src.rpm的安装:

重启mysql数据库: service mysqld restart

切换到mysql命令: mysql -u root

mysql设置密码: mysql>set password for ‘root’@’localhost’ =password(‘password’)

Mysql指令:

clear (\c) 清除当前输入语句。

connect (\r) 重新连接到服务器。可选的参数是DB和主机。

delimiter (\d) 设置语句定界符。

edit (\e) 用$编辑器编辑命令。

ego (\G) 将命令发送到MySQL服务器,垂直显示结果。

exit (\q) 退出MySQL。

go (\g) 将命令发送到MySQL服务器。

help (\h) 显示此帮助。

nopager (\n) Disable pager, print to stdout.

notee (\t) 不要写在文件外。

pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.

print (\p) Print current command.

prompt (\R) 更改MySQL提示.

quit (\q) 退出 mysql.

rehash (\#) 重建完成的散列。

source (\.) 执行SQL脚本文件。将文件名作为参数。

status (\s) 从服务器获取状态信息。

system (\!) 执行系统外壳命令。

tee (\T) 设置OutFoo[ to-OutFooFr]。将所有内容附加到给定的OutFlash中。

use (\u) 使用另一个数据库。将数据库名称作为参数。

charset (\C) 切换到另一个字符集。可能需要用多字节字符集来处理BILCONG。

warnings (\W) 在每个语句之后显示警告.

nowarning (\w) 每次陈述后不要显示警告。

四、压缩解压类:

.命令:tar [-cxtzjvfpPN] 文件与目录 ….

命令参数:

c :建立一个压缩文件的参数指令(create 的意思);

x :解开一个压缩文件的参数指令!

t :查看 tarfile 里面的文件!

特别注意,在参数的下达中, c/x/t 仅能存在一个!不可同时存在!因为不可能同时压缩与解 压缩。

z :是否同时具有 gzip 的属性?亦即是否需要用 gzip 压缩?

j :是否同时具有 bzip2 的属性?亦即是否需要用 bzip2 压缩?

v :压缩的过程中显示文件!这个常用,但不建议用在背景执行过程!

f :使用档名,请留意,在 f 之后要立即接档名喔!不要再加参数!

例如使用『 tar -zcvfP tfile sfile』就是错误的写法,要写成『 tar -zcvPf tfile sfile』才对喔!

p :使用原文件的原来属性(属性不会依据使用者而变)

P :可以使用绝对路径来压缩!

N :比后面接的日期(yyyy/mm/dd)还要新的才会被打包进新建的文件中!

–exclude FILE:在压缩的过程中,不要将 FILE 打包!

范例一:

将整个 /etc 目录下的文件全部打包成为 /tmp/etc.tar

[root@linux ~]# tar -cvf /tmp/etc.tar /etc&lt;==仅打包,不压缩! tar -cvf 目标文件源文件 (以下同)例如:tar -cvf a.txt.tar a.txt

[root@linux ~]# tar -zcvf /tmp/etc.tar.gz /etc&lt;==打包后,以 gzip 压缩

[root@linux ~]# tar -jcvf /tmp/etc.tar.bz2 /etc&lt;==打包后,以 bzip2 压缩

# 特别注意,在参数 f 之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。 # 如果加 z 参数,则以tar.gz 或 .tgz 来代表 gzip 压缩过的 tar file ~

# 如果加 j 参数,则以 .tar.bz2 来作为附档名啊~

# 上述指令在执行的时候,会显示一个警告讯息:

# 『tar: Removing leading `/” from member names』那是关於绝对路径的特殊设定。

范例二:

查阅上述 /tmp/etc.tar.gz 文件内有哪些文件?

[root@linux ~]# tar -ztvf /tmp/etc.tar.gz

# 由於我们使用 gzip 压缩,所以要查阅该 tar file 内的文件时,

# 就得要加上 z 这个参数了!这很重要的!

范例三:

将 /tmp/etc.tar.gz 文件解压缩在 /usr/local/src 底下

[root@linux ~]# cd /usr/local/src

[root@linux src]# tar -zxvf /tmp/etc.tar.gz

# 在预设的情况下,我们可以将压缩档在任何地方解开的!以这个范例来说,

# 我先将工作目录变换到 /usr/local/src 底下,并且解开 /tmp/etc.tar.gz ,

# 则解开的目录会在 /usr/local/src/etc 呢!另外,如果您进入 /usr/local/src/etc # 则会发现,该目录下的文件属性与 /etc/ 可能会有所不同喔!

范例四:

在 /tmp 底下,我只想要将 /tmp/etc.tar.gz 内的 etc/passwd 解开而已

[root@linux ~]# cd /tmp

[root@linux tmp]# tar -zxvf /tmp/etc.tar.gz etc/passwd

# 我可以透过 tar -ztvf 来查阅 tarfile 内的文件名称,如果单只要一个文件,

# 就可以透过这个方式来下达!注意到! etc.tar.gz 内的根目录 / 是被拿掉了!

范例五:

将 /etc/ 内的所有文件备份下来,并且保存其权限!

[root@linux ~]# tar -zxvpf /tmp/etc.tar.gz /etc

# 这个 -p 的属性是很重要的,尤其是当您要保留原本文件的属性时!

范例六:

在 /home 当中,比 2005/06/01 新的文件才备份

[root@linux ~]# tar -N “2005/06/01″ -zcvf home.tar.gz /home

范例七:

我要备份 /home, /etc ,但不要 /home/dmtsai

[root@linux ~]# tar –exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc

范例八:

将 /etc/ 打包后直接解开在 /tmp 底下,而不产生文件!

[root@linux ~]# cd /tmp

[root@linux tmp]# tar -cvf – /etc | tar -xvf –

# 这个动作有点像是 cp -r /etc /tmp 啦~依旧是有其有用途的!

# 要注意的地方在於输出档变成 – 而输入档也变成 – ,又有一个 | 存在~

# 这分别代表 standard output, standard input 与管线命令啦!

五、进程控制类:

.列出当前进程ID:ps -auxw

.终止进程:

(1)终止单一进程:kill 进程ID号

(2)终止该程序所有进程:Killall 程序名

(3)终止X-Window程序:xkill

.查看资源占用情况:(1)top (2)free (3)dmesg

.查看环境变量值:env

.重启:(1)reboot (2)Ctrl Alt Del (3)init 6

.关机:(1)shutdown -h now (2)halt (3)init 0

.切换桌面:switchdesk gnome|KDE|…

六、使用CentOS常用命令查看cpu:

more/proc/cpuinfo | grep “model name”

grep “model name” /proc/cpuinfo

[root@localhost/]# grep “CPU”/proc/cpuinfo

model name : Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz

model name : Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz

如果觉得需要看的更加舒服

grep “model name” /proc/cpuinfo | cut -f2 -d:

七、使用CentOS常用命令查看内存:

grep MemTotal /proc/meminfo grep MemTotal /proc/meminfo | cut -f2 -d: free -m |grep “Mem”| awk ‘{print $2}’

八、使用CentOS常用命令查看cpu是32位还是64位:

getconf LONG_BIT

九、使用CentOS常用命令查看当前linux的版本:

more/etc/redhat-release

cat/etc/redhat-release

十、使用CentOS常用命令查看内核版本:

uname -r

uname -a

十一、使用CentOS常用命令查看当前时间:

十二、使用CentOS常用命令查看硬盘和分区:

df -h

查看分区: fdisk -l

看全部占用的空间: du -sh

看这个目录的大小: du/etc -sh

十三、使用CentOS常用命令查看安装的软件包:

查看系统安装的时候装的软件包:

cat -n /root/install.log

more /root/install.log | wc -l

查看现在已经安装了那些软件包:

rpm -qa

rpm -qa | wc -l

yum list installed | wc -l

不过很奇怪,通过rpm,和yum这两种方式查询的安装软件包,数量不一样。没有找到原因。

十四、使用CentOS常用命令查看键盘布局:

cat/etc/sysconfig/keyboard

cat/etc/sysconfig/keyboard | grep KEYTABLE | cut -f2 -d=

十五、使用CentOS常用命令查看selinux情况:

sestatus | cut -f2 -d:

cat/etc/sysconfig/selinux

十六、使用CentOS常用命令查看ip,mac地址:

在ifcfg-eth0 文件里你可以看到mac,网关等信息:

cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR cat

/etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR | cut -f2 -d= ifconfig eth0 |grep “inet addr:” |awk ‘{print $2}’|cut -c 6- ifconfig | grep ‘inet addr:’| grep -v ‘127.0.0.1’ | cut -d: -f2 | awk ‘ {print $1}’

查看网关: cat /etc/sysconfig/network

查看dns: cat /etc/resolv.conf

十七、使用CentOS常用命令查看默认语言:

echo $LANG $LANGUAGE

cat /etc/sysconfig/i18n

十八、使用CentOS常用命令查看所属时区和是否使用UTC时间:

cat /etc/sysconfig/clock

十九、使用CentOS常用命令查看主机名:

hostname: cat /etc/sysconfig/network

修改主机名就是修改个文件,同时最好也把host文件也修改。

二十、使用CentOS常用命令查看开机运行时间:

uptime: 09:44:45 up 67 days, 23:32, …

二十一、systemctl 的用法:

systemctl is-enabled iptables.service

systemctl is-enabled servicename.service #查询服务是否开机启动

systemctl enable *.service #开机运行服务

systemctl disable *.service #取消开机运行

systemctl start *.service #启动服务

systemctl stop *.service #停止服务

systemctl restart *.service #重启服务

systemctl reload *.service #重新加载服务配置文件

systemctl status *.service #查询服务运行状态

systemctl –failed #显示启动失败的服务

注:*代表某个服务的名字,如http的服务名为httpd

例如在CentOS 7 上安装http

[root@CentOS7 ~]# yum -y install httpd

启动服务(等同于service httpd start)

systemctl start httpd.service

停止服务(等同于service httpd stop)

systemctl stop httpd.service

重启服务(等同于service httpd restart)

systemctl restart httpd.service

查看服务是否运行(等同于service httpd status)

systemctl status httpd.service

开机自启动服务(等同于chkconfig httpd on)

systemctl enable httpd.service

开机时禁用服务(等同于chkconfig httpd on)

systemctl disable httpd.service

查看服务是否开机启动 (等同于chkconfig –list)

查看某文件的权限:ls -l /文件路径

给某文件添加权限:chmod -v u+w /文件路径

去掉某权限: chmod -v u-w /文件路径

  1. chmod:改变权限的方法
  2. +:代表添加权限

3. x:代表执行权限

4. /usr/java/jdk1.8.0_161/bin/javac :文件名

查看进程(以zookeeper为例):Ps -ef | grep zookeeper

查看日志:tail -f logs/catalina.out

tomcat 默认端口是 8080 ,如需更改,在tomcat / conf目录下 ,编辑server.xml 找到

<Connector port=”8080″ protocol=”HTTP/1.1″

connectionTimeout=”20000″

redirectPort=”8443″ />

yum安装  yum install -y lrzsz

上传  rz

下载  sz

 

发表回复

您的电子邮箱地址不会被公开。

A beliving heart is your magic My heart
欢迎来到Diuut的个人博客,这里是我的一些零零碎碎的知识汇总,希望有能帮到你的内容。 | 蜀ICP备2021011635号-1 | Copyright © 2024 Diuut. All Rights Reserved.