Linux常用命令

来源:互联网 发布:淘宝店铺信用卡套现 编辑:程序博客网 时间:2024/05/27 09:48

一、基本命令格式


[root@mook ~]# 

root : 代表当前登录用户
mook : 主机名
~ : 当前目录(家目录)
root用户的家目录是/root
# : 超级用户的提示符(普通用户的提示符是$)

这里写图片描述

[root@mook ~]# lsanaconda-ks.cfg  install.log  install.log.syslog
[root@mook ~]# ls -l总用量 44-rw-------. 1 root root  1208 7月  28 10:11 anaconda-ks.cfg-rw-r--r--. 1 root root 24772 7月  28 10:11 install.log-rw-r--r--. 1 root root  7690 7月  28 10:10 install.log.syslog

“.”代表ACL权限
“1”代表引用计数
“root”代表文件所有者
“root”代表文件所属组
“1208”代表文件大小(字节)
“时间”代表文件最后一次被修改的时间
这里写图片描述

[root@mook ~]# ls -lh总用量 44K-rw-------. 1 root root 1.2K 7月  28 10:11 anaconda-ks.cfg-rw-r--r--. 1 root root  25K 7月  28 10:11 install.log-rw-r--r--. 1 root root 7.6K 7月  28 10:10 install.log.syslog

二、文件处理命令


目录处理命令

建立目录:mkdir

这里写图片描述

切换所在目录:cd

这里写图片描述
“ctrl+L”:清屏

查询所在目录位置:pwd

删除空目录:rmdir

文件处理命令

删除文件或目录:rm

这里写图片描述

复制命令:cp

这里写图片描述

剪切或改名命令:mv

这里写图片描述

常见目录的作用

这里写图片描述

这里写图片描述
bin目录下的命令用户都可以使用,但是sbin下的命令只有root用户可以使用。

这里写图片描述

这里写图片描述
这里写图片描述

链接命令

这里写图片描述

这里写图片描述
这里写图片描述
硬链接:引用计数会增加;删除一个不会影响另一个,但是它们的文件内容一致。

这里写图片描述
这里写图片描述
软链接:源文件要写绝对路径!


三、文件搜索命令


文件搜索命令:locate

只能搜索文件,按文件名搜索文件,速度快
这里写图片描述
数据库不是实时更新的,可以强制更新。
locate和命令搜索命令会遵循如下的配置文件规则:
这里写图片描述

命令搜索命令:whereis和which

只能搜索系统命令!
这里写图片描述

[root@mook ~]# whereis lsls: /bin/ls /usr/share/man/man1p/ls.1p.gz /usr/share/man/man1/ls.1.gz[root@mook ~]# whoamiroot[root@mook ~]# whatis lsls                   (1)  - list directory contentsls                   (1p)  - list directory contents

这里写图片描述

[root@mook ~]# which lsalias ls='ls --color=auto'    /bin/ls
[root@mook ~]# whereis cdcd: /usr/share/man/man1p/cd.1p.gz /usr/share/man/man1/cd.1.gz[root@mook ~]# which cd/usr/bin/which: no cd in (/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)

cd命令是shell的内置命令,所以没有执行文件!

这里写图片描述

文件搜索命令:find

强大!
完全匹配!!
这里写图片描述

这里写图片描述
注意:文件名加双引号!

这里写图片描述

这里写图片描述

这里写图片描述

[root@mook ~]# find . -size 25k./install.log[root@mook ~]# find /etc -size +2M/etc/selinux/targeted/policy/policy.24/etc/selinux/targeted/modules/active/policy.kern

这里写图片描述

字符串搜索命令:grep

搜索文件当中的内容
这里写图片描述

[root@mook ~]# grep "size" anaconda-ks.cfg #part /boot --fstype=ext4 --size=200#part /home --fstype=ext4 --size=3000#part swap --size=1000#part / --fstype=ext4 --grow --size=200
[root@mook ~]# grep -v "size" anaconda-ks.cfg # Kickstart file automatically generated by anaconda.#version=DEVELinstallcdromlang zh_CN.UTF-8keyboard us

这里写图片描述

四、帮助命令


帮助命令:man

[root@mook ~]# man ls
LS(1)                            User Commands                           LS(1)NAME       ls - list directory contentsSYNOPSIS       ls [OPTION]... [FILE]...DESCRIPTION       List  information  about  the FILEs (the current       directory by default).  Sort entries  alphabeti-       cally if none of -cftuvSUX nor --sort.       Mandatory  arguments  to long options are manda-       tory for short options too.       -a, --all              do not ignore entries starting with ./d

“/d”然后回车,按“n”,选择带“d”字符串
“/-d”然后回车,按“n”,选择查看“-d”命令选项

这里写图片描述

这里写图片描述
数字前不需要加“-”!

[root@mook ~]# man -f passwordpassword-auth-ac [system-auth-ac] (5)  - Common configuration files for PAMified services written by authconfig(8)[root@mook ~]# whatis passwordpassword-auth-ac [system-auth-ac] (5)  - Common configuration files for PAMified services written by authconfig(8)

这里写图片描述

[root@mook ~]# apropos passwdchpasswd             (8)  - update passwords in batch modefgetpwent_r [getpwent_r] (3)  - get passwd file entry reentrantlygetpwent_r           (3)  - get passwd file entry reentrantlygpasswd              (1)  - administer /etc/group and /etc/gshadowkpasswd              (1)  - change a user's Kerberos passwordlpasswd              (1)  - Change group or user passwordlppasswd             (1)  - add, change, or delete digest passwordspam_localuser        (8)  - require users to be listed in /etc/passwdpam_passwdqc         (8)  - Password quality-control PAM modulepasswd               (1)  - update user's authentication token

其他帮助命令

这里写图片描述

[root@mook ~]# ls --help用法:ls [选项]... [文件]...列出 FILE 的信息(默认为当前目录)。如果不指定-cftuvSUX 或--sort 选项,则根据字母大小排序。长选项必须使用的参数对于短选项时也是必需使用的。  -a, --all         不隐藏任何以. 开始的项目  -A, --almost-all      列出除. 及.. 以外的任何项目      --author          与-l 同时使用时列出每个文件的

这里写图片描述

[root@mook ~]# whereis cdcd: /usr/share/man/man1p/cd.1p.gz /usr/share/man/man1/cd.1.gz[root@mook ~]# help cdcd: cd [-L|-P] [dir]    Change the shell working directory.    Change the current directory to DIR.  The default DIR is the value of the    HOME shell variable.

whereis cd 无可执行文件

[root@mook ~]# whereis lsls: /bin/ls /usr/share/man/man1p/ls.1p.gz /usr/share/man/man1/ls.1.gz

这里写图片描述

五、压缩与解压缩命令


.zip格式压缩

这里写图片描述

[root@mook ~]# touch file[root@mook ~]# zip file.zip file  adding: file (stored 0%)[root@mook ~]# ll总用量 48-rw-------. 1 root root  1208 728 10:11 anaconda-ks.cfg-rw-r--r--. 1 root root     0 81 00:20 file-rw-r--r--. 1 root root   158 81 00:21 file.zip-rw-r--r--. 1 root root 24772 728 10:11 install.log-rw-r--r--. 1 root root  7690 728 10:10 install.log.syslog[root@mook ~]# 
[root@mook ~]# mkdir dir[root@mook ~]# touch dir/file1[root@mook ~]# touch dir/file2[root@mook ~]# touch dir/file3[root@mook ~]# cd dir/[root@mook dir]# lsfile1  file2  file3[root@mook dir]# cd .. [root@mook ~]# lsanaconda-ks.cfg  file      install.logdir              file.zip  install.log.syslog[root@mook ~]# zip -r dir.zip dir  adding: dir/ (stored 0%)  adding: dir/file2 (stored 0%)  adding: dir/file3 (stored 0%)  adding: dir/file1 (stored 0%)[root@mook ~]# ll总用量 56-rw-------. 1 root root  1208 728 10:11 anaconda-ks.cfgdrwxr-xr-x. 2 root root  4096 81 00:22 dir-rw-r--r--. 1 root root   596 81 00:22 dir.zip-rw-r--r--. 1 root root     0 81 00:20 file-rw-r--r--. 1 root root   158 81 00:21 file.zip-rw-r--r--. 1 root root 24772 728 10:11 install.log-rw-r--r--. 1 root root  7690 728 10:10 install.log.syslo

这里写图片描述

.gz格式压缩

这里写图片描述

[root@mook ~]# lsanaconda-ks.cfg  dir  file  install.log  install.log.syslog[root@mook ~]# gzip file[root@mook ~]# lsanaconda-ks.cfg  file.gz      install.log.syslogdir              install.log
[root@mook ~]# gzip dirgzip: dir is a directory -- ignored[root@mook ~]# gzip -r dir[root@mook ~]# ll总用量 52-rw-------. 1 root root  1208 7月  28 10:11 anaconda-ks.cfgdrwxr-xr-x. 2 root root  4096 8月   1 00:36 dir-rw-r--r--. 1 root root    25 8月   1 00:20 file.gz-rw-r--r--. 1 root root 24772 7月  28 10:11 install.log-rw-r--r--. 1 root root  7690 7月  28 10:10 install.log.syslog[root@mook ~]# cd dir/[root@mook dir]# ll总用量 12-rw-r--r--. 1 root root 26 8月   1 00:22 file1.gz-rw-r--r--. 1 root root 26 8月   1 00:22 file2.gz-rw-r--r--. 1 root root 26 8月   1 00:22 file3.gz

这里写图片描述

[root@mook ~]# ll总用量 52-rw-------. 1 root root  1208 7月  28 10:11 anaconda-ks.cfgdrwxr-xr-x. 2 root root  4096 81 00:36 dir-rw-r--r--. 1 root root    25 8月   1 00:20 file.gz-rw-r--r--. 1 root root 24772 7月  28 10:11 install.log-rw-r--r--. 1 root root  7690 7月  28 10:10 install.log.syslog[root@mook ~]# gzip -d file.gz [root@mook ~]# ll总用量 48-rw-------. 1 root root  1208 7月  28 10:11 anaconda-ks.cfgdrwxr-xr-x. 2 root root  4096 81 00:36 dir-rw-r--r--. 1 root root     0 8月   1 00:20 file-rw-r--r--. 1 root root 24772 7月  28 10:11 install.log-rw-r--r--. 1 root root  7690 7月  28 10:10 install.log.syslog[root@mook ~]# gzip -d dir gzip: dir is a directory -- ignored[root@mook ~]# gunzip dirgzip: dir is a directory -- ignored[root@mook ~]# gunzip -r dir[root@mook ~]# cd dir/[root@mook dir]# ll总用量 0-rw-r--r--. 1 root root 0 8月   1 00:22 file1-rw-r--r--. 1 root root 0 8月   1 00:22 file2-rw-r--r--. 1 root root 0 8月   1 00:22 file3

.bz2格式压缩

这里写图片描述

这里写图片描述

.tar.gz和.tar.bz2压缩格式

这里写图片描述

这里写图片描述

[root@mook ~]# lsanaconda-ks.cfg  dir  file  install.log  install.log.syslog[root@mook ~]# tar -zcvf dir.tar.gz dirdir/dir/file2dir/file3dir/file1[root@mook ~]# lsanaconda-ks.cfg  dir.tar.gz  install.logdir              file        install.log.syslog[root@mook ~]# tar -jcvf dir.tar.bz2 dirdir/dir/file2dir/file3dir/file1[root@mook ~]# lsanaconda-ks.cfg  dir.tar.bz2  file         install.log.syslogdir              dir.tar.gz   install.log

解压到指定目录下:

[root@mook ~]# lsanaconda-ks.cfg  dir.tar.bz2  file         install.log.syslogdir              dir.tar.gz   install.log[root@mook ~]# tar -jxvf dir.tar.bz2 -C /tmp/dir/dir/file2dir/file3dir/file1[root@mook tmp]# lsdir  yum.log

多个文件压缩并将压缩包放到指定目录下:

[root@mook ~]# tar -zcvf /tmp/test.tar.gz dir anaconda-ks.cfg dir/dir/file2dir/file3dir/file1anaconda-ks.cfg[root@mook ~]# cd /tmp/[root@mook tmp]# lstest.tar.gz  yum.log
[root@mook tmp]# tar -zxvf test.tar.gz dir/dir/file2dir/file3dir/file1anaconda-ks.cfg[root@mook tmp]# lsanaconda-ks.cfg  dir  test.tar.gz  yum.log

查看压缩文件中的内容:

[root@mook tmp]# lsanaconda-ks.cfg  dir  test.tar.gz  yum.log[root@mook tmp]# tar -ztvf test.tar.gz drwxr-xr-x root/root         0 2016-08-01 00:41 dir/-rw-r--r-- root/root         0 2016-08-01 00:22 dir/file2-rw-r--r-- root/root         0 2016-08-01 00:22 dir/file3-rw-r--r-- root/root         0 2016-08-01 00:22 dir/file1-rw------- root/root      1208 2016-07-28 10:11 anaconda-ks.cfg

六、关机和重启命令


这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

查看之前和当前系统的运行级别:

[root@mook tmp]# runlevelN 3

这里写图片描述

这里写图片描述

七、其他常用命令


挂载命令

这里写图片描述

这里写图片描述

[root@mook home]# lslost+found[root@mook home]# vi hello.sh[root@mook home]# chmod 755 hello.sh [root@mook home]# ll总用量 20-rwxr-xr-x. 1 root root    34 81 02:56 hello.shdrwx------. 2 root root 16384 728 09:59 lost+found[root@mook home]# ./hello.sh hello mook!!![root@mook home]# /home/hello.sh hello mook!!!
[root@mook home]# mount -o remount,noexec /home/[root@mook home]# lshello.sh  lost+found[root@mook home]# ./hello.sh-bash: ./hello.sh: 权限不够[root@mook home]# mount -o remount,exec /home/[root@mook home]# ./hello.shhello mook!!!
0 0
原创粉丝点击