文件基础处理命令(Linux新手必学)

*文件命名规则*

1)除了/ 之外,所有的字符都合法。

2)有些字符最好不用,如空格符、制表符、退格符和字符@ # # & ( ) - 等。

3)避免使用. 作为普通文件名的第一个字符。

4)大小写敏感。

*命令格式*

命令格式:命令 -选项 参数

例: ls -la root

说明:1)当有多个选项时,可以写在一起。

​ 2)两个特殊的目录. 和… ,分别代表当前目录和当前目录的父目录。

[root@linux1 /]# ls -la /root/
总用量 10465360
dr-xr-x---.  6 root root        4096 728 16:54 .
dr-xr-xr-x. 18 root root        4096 716 19:27 ..
-rw-------.  1 root root        1032 66 04:28 anaconda-ks.cfg
-rw-------.  1 root root        8011 726 21:52 .bash_history
-rw-r--r--.  1 root root          18 315 2021 .bash_logout
-rw-r--r--.  1 root root         176 315 2021 .bash_profile
-rw-r--r--.  1 root root         176 315 2021 .bashrc
drwx------.  4 root root          44 66 05:06 .cache
-rw-r--r--.  1 root root         697 726 15:10 CreateFile.py
-rw-r--r--.  1 root root         100 315 2021 .cshrc
drwx------.  3 root root          25 66 05:06 .dbus
-rw-r--r--.  1 root root        2251 726 12:47 hhh.py
-rw-r--r--.  1 root root        1259 66 16:43 initial-setup-ks.cfg
-rw-r--r--.  1 root root          53 618 19:41 .nmcli-history
-rw-r--r--.  1 root root 10716446720 315 20:45 Rocky-8.5-x86_64-dvd1.iso
drwx------.  3 root root          92 76 15:09 .ssh
-rw-r--r--.  1 root root         129 315 2021 .tcshrc
drwxr-xr-x.  2 root root        4096 726 13:01 test
-rw-------.  1 root root       12487 728 16:54 .viminfo
-rw-------.  1 root root         124 76 14:53 .xauthgt9fU5

*文件处理命令:ls*

命令名称:ls

命令英文原意:list

命令所在路径:/bin/ls

执行权限:所有用户

功能描述:显示目录文件

语法:ls 选项[-ald] [文件或目录]

-a 显示所有文件,包括隐藏文件

-l 详细信息显示

-d 查看目录属性
[root@linux1 /]# ls -ald /root/
dr-xr-x---. 6 root root 4096 728 16:54 /root/
2硬链接数
root所有者
root所属组
4096目录及子目录大小
Jun 10 04:20目录创建时间或最后修改时间
bin目录名

*文件处理命令:cd*

命令名称:cd

命令英文原意:change directory

命令所在路径:shell内置命令

执行权限:所有用户

语法:cd [目录]

功能描述:切换目录

范例: # cd / 切换到根目录

     # cd .. 回到上一级目录
# ~,默认是root目录
[root@linux1 ~]# cd /
[root@linux1 /]# 
# cd ..
[root@linux1 /]# cd /etc/sysconfig/
[root@linux1 sysconfig]# cd ..
[root@linux1 etc]# 

*文件处理命令:pwd*

命令名称:pwd

命令英文原意:print working directory

命令所在路径:/bin/pwd

执行权限:所有用户

语法:pwd

功能描述:显示当前所在的工作目录

范例:# pwd
/etc/sysconfig
[root@linux1 etc]# cd /etc/sysconfig/
[root@linux1 sysconfig]# pwd
/etc/sysconfig

*文件处理命令:mkdir*

命令名称:mkdir

命令英文原意:make directories

命令所在路径:/bin/mkdir

执行权限:所有用户

语法:mkdir [目录名]

功能描述:创建新目录

范例: # mkdir newdir

范例: # mkdir –p /opt/new/dir  -p同时创建新文件new及子文件夹dir  
[root@linux1 /]# mkdir newdir
[root@linux1 /]# mkdir -p /opt/new/dir
[root@linux1 /]# 

*文件处理命令:touch*

命令名称:touch

命令所在路径:/bin/touch

执行权限:所有用户

语法:touch [文件名]

功能描述:修改文件时间戳,如果文件不存在则创建空文件

范例: # touch newfile

范例: # touch /opt/file  在opt目录文件夹内创建file文件 
[root@linux1 /]# touch newfile
[root@linux1 /]# touch /opt/file
[root@linux1 /]# 

文件处理命令:cp

命令名称:cp

命令英文原意:copy

命令所在路径:/bin/cp

执行权限:所有用户

语法:cp -R [源文件或目录] [目的目录]

-R 复制目录

功能描述:复制文件或目录

范例:
# cp file1 file2 dir1

将文件file1、file2复制到目录dir1
[root@linux1 /]# touch file1
[root@linux1 /]# touch file2
[root@linux1 /]# cp file1 file2 dir1

# cp -R dir1 dir2

将dir1下的所有文件及子目录复制到dir2
[root@linux1 /]# cp -R dir1 dir2
[root@linux1 /]# ll dir2/
总用量 0
-rw-r--r--. 1 root root 0 729 09:57 file1
-rw-r--r--. 1 root root 0 729 09:57 file2
# cp -p dir1/file1 dir2

将dir1下的所有文件、子目录及属性复制到dir2
[root@linux1 /]# cp -p dir1/file1 dir2
[root@linux1 /]# cp -p dir1/file2 dir2
[root@linux1 /]# ll dir2/
总用量 0
-rw-r--r--. 1 root root 0 729 09:57 file1
-rw-r--r--. 1 root root 0 729 09:57 file2

文件处理命令:mv

命令名称:mv

命令英文原意:move

命令所在路径:/bin/mv

执行权限:所有用户

语法:mv [源文件或目录] [目的目录]

功能描述:移动文件、更名

范例:

# mv file1 file3

将当前目录下文件file1更名为file3
[root@linux1 /]# cd dir1/
[root@linux1 dir1]# ls
file1  file2
[root@linux1 dir1]# mv file1 file3
[root@linux1 dir1]# ls
file2  file3
[root@linux1 dir1]# 

# mv file2 dir2

将文件file2移动到目录dir2下
[root@linux1 dir1]# mv file2 /dir2/
mv:是否覆盖'/dir2/file2'? y
[root@linux1 dir1]# ll /dir2/
总用量 0
-rw-r--r--. 1 root root 0 729 10:06 file2

文件处理命令:rm

命令名称:rm

命令英文原意:remove

命令所在路径:/bin/rm

执行权限:所有用户

语法:rm -r [文件或目录]

-r 删除目录

功能描述:删除文件

范例:

# rm file3  删除文件file3有提示是否删除
[root@linux1 /]# rm dir1/file3 
rm:是否删除普通空文件 'dir1/file3'?y
[root@linux1 /]# 
# rm -f file3  强制删除文件file3,无提示
[root@linux1 /]# touch /dir1/file3
[root@linux1 /]# rm -f /dir1/file3 
[root@linux1 /]# 
# rm -r dir1  删除目录dir1
[root@linux1 /]# rm -r dir1/
rm:是否删除目录 'dir1/'?y
[root@linux1 /]# 
# rm -rf dir1  强制删除目录dir1,无提示
[root@linux1 /]# mkdir dir1
[root@linux1 /]# 
[root@linux1 /]# rm -rf dir1/

*文件处理命令:cat*

命令名称:cat

命令英文原意:concatenate and display files

命令所在路径:/bin/cat

执行权限:所有用户

语法:cat [文件名]

功能描述:显示文件内容

范例: 

# cat /etc/issue
[root@linux1 /]# cat /etc/issue
\S
Kernel \r on an \m
# cat /etc/fstab
[root@linux1 /]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Sun Jun  5 20:03:49 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rl-root     /                       xfs     defaults        0 0
UUID=e51517c6-af2c-4a53-85cd-c483b7bfd445 /boot                   xfs     defaults        0 0
/dev/mapper/rl-swap     none                    swap    defaults        0 0
[root@linux1 /]# 

*文件处理命令:more*

命令名称:more

命令所在路径:/bin/more

执行权限:所有用户

语法:more [文件名]

(空格) 或f 显示下一页

(Enter) 显示下一行

q或Q 退出

功能描述:分页显示文件内容

范例: # more /etc/services 
[root@linux1 /]# more /etc/services 
# /etc/services:
# $Id: services,v 1.49 2017/08/18 12:43:23 ovasik Exp $
#
# Network services, Internet style
# IANA services version: last updated 2016-07-08
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994).  Not all ports
# are included, only the more common ones.
#
# The latest IANA port assignments can be gotten from
#       http://www.iana.org/assignments/port-numbers
# The Well Known Ports are those from 0 through 1023.
# The Registered Ports are those from 1024 through 49151
# The Dynamic and/or Private Ports are those from 49152 through 65535
#
# Each line describes one service, and is of the form:
#
# service-name  port/protocol  [aliases ...]   [# comment]

tcpmux          1/tcp                           # TCP port service multiplexer
tcpmux          1/udp                           # TCP port service multiplexer
rje             5/tcp                           # Remote Job Entry
rje             5/udp                           # Remote Job Entry
echo            7/tcp
echo            7/udp
discard         9/tcp           sink null
discard         9/udp           sink null
systat          11/tcp          users
systat          11/udp          users
daytime         13/tcp
daytime         13/udp
qotd            17/tcp          quote
qotd            17/udp          quote
chargen         19/tcp          ttytst source
chargen         19/udp          ttytst source
ftp-data        20/tcp
ftp-data        20/udp
# 21 is registered to ftp, but also used by fsp
ftp             21/tcp
ftp             21/udp          fsp fspd
ssh             22/tcp                          # The Secure Shell (SSH) Protocol
ssh             22/udp                          # The Secure Shell (SSH) Protocol
telnet          23/tcp
telnet          23/udp
# 24 - private mail system
lmtp            24/tcp                          # LMTP Mail Delivery
lmtp            24/udp                          # LMTP Mail Delivery
<<more>>

*文件处理指令:head*

指令名称:head

指令所在路径:/bin/head

执行权限:All User

语法:head -num [文件名]

-num 显示文件的前num行

功能描述:查看文件的前几行

范例:# head -20 /etc/services
[root@linux1 /]# head -20 /etc/services
# /etc/services:
# $Id: services,v 1.49 2017/08/18 12:43:23 ovasik Exp $
#
# Network services, Internet style
# IANA services version: last updated 2016-07-08
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994).  Not all ports
# are included, only the more common ones.
#
# The latest IANA port assignments can be gotten from
#       http://www.iana.org/assignments/port-numbers
# The Well Known Ports are those from 0 through 1023.
# The Registered Ports are those from 1024 through 49151
# The Dynamic and/or Private Ports are those from 49152 through 65535
#
# Each line describes one service, and is of the form:
#
[root@linux1 /]# 

*文件处理指令:tail*

指令名称:tail

指令所在路径:/bin/tail

执行权限:All User

语法:tail -num [文件名]

-num 显示文件的后num行

-f 动态显示文件内容

功能描述:查看文件的后几行

范例: # tail -30 /etc/services
[root@linux1 /]# tail -30 /etc/services
bolt            7687/tcp                # Bolt database connection
nfapi           7701/sctp               # SCF nFAPI defining MAC/PHY split
wpl-analytics   8006/tcp                # World Programming analytics
wpl-disc        8006/udp                # World Programming analytics discovery
ucs-isc         8070/tcp                # Oracle Communication Indexed Search Converter
mles            8077/tcp                # Client-server data distribution
opsmessaging    8090/tcp                # Vehicle to station messaging
robot-remote    8270/tcp                # Robot Framework Remote Library Interface
aritts          8423/tcp                # Aristech text-to-speech server
ssports-bcast   8808/udp                # STATSports Broadcast Service
CardWeb-IO      9060/tcp                # CardWeb request-response I/O exchange
CardWeb-RT      9060/udp                # CardWeb realtime device data
pumpkindb       9981/tcp                # Event sourcing database engine/language
abb-hw          10020/tcp               # Hardware configuration and maintenance
tile-ml         10261/tcp               # Tile remote machine learning
xpra            14500/tcp               # xpra network protocol
vdmmesh-disc    18668/udp               # Manufacturing Execution Systems Mesh Comm
vdmmesh         18668/tcp               # Manufacturing Execution Systems Mesh Comm
cora-disc       19220/udp               # Discovery for Client Connection ... Service
cora            19220/tcp               # Client Connection Mgmt/Data Exchange Service
aigairserver    21221/tcp               # Services for Air Server
ka-kdp          31016/udp               # Kollective Agent Kollective Delivery
ka-sddp         31016/tcp               # Kollective Agent Secure Distributed Delivery
edi_service     34567/udp               # dhanalakshmi.org EDI Service
axio-disc       35100/tcp               # Axiomatic discovery protocol
axio-disc       35100/udp               # Axiomatic discovery protocol
pmwebapi        44323/tcp               # Performance Co-Pilot client HTTP API
cloudcheck-ping 45514/udp               # ASSIA CloudCheck WiFi Management keepalive
cloudcheck      45514/tcp               # ASSIA CloudCheck WiFi Management System
spremotetablet  46998/tcp               # Capture handwritten signatures
[root@linux1 /]# 

*文件处理命令:ln*

命令名称:ln

命令英文原意:link

命令所在路径:/bin/ln

执行权限:所有用户

语法:ln -s [源文件] [目标文件]

-s 创建软链接

功能描述:产生链接文件

范例:

# ln -s /etc/issue /issue.soft

创建文件/etc/issue的软链接/issue.soft
[root@linux1 /]# ln -s /etc/issue /issue.soft
[root@linux1 /]# 

# ln /etc/issue /issue.hard

创建文件/etc/issue的硬链接/issue.hard
[root@linux1 /]# ln /etc/issue /issue.hard
[root@linux1 /]# 

[root@linux1 /]# ll
总用量 40
-rw-r--r--.   1 root root   74 76 15:12 123.sh
lrwxrwxrwx.   1 root root    7 1011 2021 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 66 05:06 boot
-rw-r--r--.   1 root root 1109 76 15:18 chrony.conf
drwxr-xr-x.  20 root root 3180 76 15:25 dev
drwxr-xr-x.   2 root root   19 729 10:06 dir2
drwxr-xr-x. 146 root root 8192 728 21:19 etc
-rw-r--r--.   1 root root    0 729 09:57 file1
-rw-r--r--.   1 root root    0 729 09:57 file2
drwxr-xr-x.   4 root root   26 728 11:15 home
-rw-r--r--.   2 root root   23 109 2021 issue.hard	#硬链接
lrwxrwxrwx.   1 root root   10 729 10:20 issue.soft -> /etc/issue  #软链接
lrwxrwxrwx.   1 root root    7 1011 2021 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 1011 2021 lib64 -> usr/lib64
drwxr-xr-x.   3 root root   19 619 09:45 media
drwxr-xr-x.   3 root root   18 66 04:11 mnt
drwxr-xr-x.   2 root root    6 729 09:53 newdir
-rw-r--r--.   1 root root    0 729 09:54 newfile
drwxr-xr-x.   3 root root   29 729 09:54 opt
dr-xr-xr-x. 260 root root    0 76 12:58 proc
dr-xr-x---.   6 root root 4096 728 16:54 root
drwxr-xr-x.  45 root root 1280 728 11:16 run
lrwxrwxrwx.   1 root root    8 1011 2021 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 1011 2021 srv
dr-xr-xr-x.  13 root root    0 76 12:58 sys
drwxrwxrwt.  12 root root 4096 729 10:23 tmp
drwxr-xr-x.  13 root root  158 66 04:12 usr
drwxr-xr-x.  23 root root 4096 619 10:06 var
[root@linux1 /]# 

*权限管理命令:chmod*

命令名称:chmod

命令英文原意:change the permissions mode of a file

命令所在路径:/bin/chmod

执行权限:所有用户

语法:chmod [{ugo}{±=}{rwx}] [文件或目录]

[mode=421 ] [文件或目录]

功能描述:改变文件或目录权限

#r-4 w-2 x-1
-rw-rw-r--.	554
drwxrwxrwx. 777
# u g o 解释
chmod u+r		u-所有者
chmod g-w		g-所属组
chmod o=x		o-其他人
rwx 可读可写可执行 chmod u+wx chmod o-rx chmod g=rwx
文件
r-cat、more、head、 tail
w-echo、vi
命令、脚本目录
r-ls
w-touch、mkdir、rm
x-cd

[root@linux1 /]# mkdir /dir1
[root@linux1 /]# cd /dir1/
[root@linux1 dir1]# touch file1
[root@linux1 dir1]# touch file2
[root@linux1 dir1]# 
[root@linux1 dir1]# ll
总用量 0
-rw-r--r--. 1 root root 0 729 10:27 file1
-rw-r--r--. 1 root root 0 729 10:27 file2
范例:

# chmod g+w file1

赋予文件file1所属组写权限
[root@linux1 dir1]# chmod g+w file1 
[root@linux1 dir1]# ls -ld file1
-rw-rw-r--. 1 root root 0 729 10:32 file1
[root@linux1 dir1]# 

# chmod 777 dir1

设定目录dir1为所有用户具有全部权限
[root@linux1 /]# chmod 777 /dir1
[root@linux1 /]# ls -ld /dir1
drwxrwxrwx. 2 root root 32 729 10:27 /dir1
[root@linux1 /]# 

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5D9WqftG-1665309144071)(新建 文本文档.assets/wps25.jpg)]

*权限管理命令:chown*

命令名称:chown

命令英文原意:change file ownership

命令所在路径:/bin/chown

执行权限:所有用户

语法:chown [用户] [文件或目录]

功能描述:改变文件或目录的所有者

[root@linux1 /]# cd dir1/
[root@linux1 dir1]# ll
总用量 0
-rw-rw-r--. 1 root root 0 729 10:32 file1
-rw-r--r--. 1 root root 0 729 10:32 file2
范例:# chown nobody file1

改变文件file1的所有者为nobody
[root@linux1 dir1]# chown nobody file1
[root@linux1 dir1]# ll -d file1
-rw-rw-r--. 1 nobody root 0 729 10:32 file1
[root@linux1 dir1]# 

*权限管理命令:chgrp*

命令名称:chgrp

命令英文原意:change file group ownership

命令所在路径:/bin/chgrp

执行权限:所有用户

语法:chgrp [用户组] [文件或目录]

功能描述:改变文件或目录的所属组

[root@linux1 dir1]# ll -d file1
-rw-rw-r--. 1 nobody root 0 729 10:32 file1
范例:# chgrp adm file1

改变文件file1的所属组为adm
[root@linux1 dir1]# chgrp adm file1
[root@linux1 dir1]# ll -d file1
-rw-rw-r--. 1 nobody adm 0 729 10:32 file1

*权限管理命令:umask*

命令名称:umask

命令所在路径:/bin/umask

执行权限:所有用户

语法:umask [-S]

-S 以rwx形式显示新建文件或目录缺省权限

功能描述:显示、设置文件的缺省权限

在默认权限的属性上,目录与文件是不一样的。由于我们不希望文件具有可执行的权力,默认情况中,文件是没有可执行(x)权限的。因此:
? 若用户建立为”文件”则默认“没有可执行(x)项目”,即只有rw这两个项目,也就是最大为666分,默认属性如下:
-rw-rw-rw-
? 若用户建立为”目录”,则由于x与是否可以进入此目录有关,因此默认为所有权限均开放,即为777分,默认属性如下:
drwxrwxrwx
umask指定的是“该默认值需要减掉的权限”。因为r、w、x分别是4、2、1,所以。也就是说,当要去掉能写的权限,就是输入2,而如果要去掉能读的权限,也就是4,那么要去掉读与写的权限,也就是6,而要去掉执行与写入的权限,也就是3。

范例: # umask
[root@linux1 dir1]# umask
0022
# umask -S

[root@linux1 dir1]# umask -S
u=rwx,g=rx,o=rx
[root@linux1 dir1]# 

*文件搜索命令:which*

命令名称:which

命令所在路径:/usr/bin/which

执行权限:所有用户

语法:which [命令名称]

功能描述:显示系统命令所在目录

范例:# which ls
[root@linux1 dir1]# which ls
alias ls='ls --color=auto'
        /usr/bin/ls
[root@linux1 dir1]# 
[root@linux1 dir1]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz

*文件搜索命令:find*

命令名称:find

命令所在路径:/usr/bin/find

执行权限:所有用户

语法:find [搜索路径] [搜寻关键字]

功能描述:查找文件或目录

范例: #-name 文件名
# find /etc -name init

在目录/etc中查找文件init
[root@linux1 /]# find /etc/ -name init.d 
/etc/init.d
/etc/rc.d/init.d
[root@linux1 /]# find /etc/ -name init*
/etc/selinux/targeted/contexts/initrc_context
/etc/inittab
/etc/init.d
/etc/rc.d/init.d
/etc/iscsi/initiatorname.iscsi
/etc/initial-setup
[root@linux1 /]# 

# find / -size +204800
#-size	512字节=0.5KB 100MB=102400KB=204800block
在根目录下查找大于100MB的文件
[root@linux1 /]# find / -size +204800
/boot/initramfs-0-rescue-0a2ec218b6604540be10b88c8f85b888.img
/proc/kcore
find: ‘/proc/241273/task/241273/fd/5’: 没有那个文件或目录
find: ‘/proc/241273/task/241273/fdinfo/5’: 没有那个文件或目录
find: ‘/proc/241273/fd/6’: 没有那个文件或目录
find: ‘/proc/241273/fdinfo/6’: 没有那个文件或目录
/sys/devices/pci0000:00/0000:00:0f.0/resource1
/sys/devices/pci0000:00/0000:00:0f.0/resource1_wc

# find /home -user redking

在/home目录下查找所有者为redking的文件
[root@linux1 /]# useradd a
[root@linux1 /]# find /home/ -user a
/home/a
/home/a/.mozilla
/home/a/.mozilla/extensions
/home/a/.mozilla/plugins
/home/a/.bash_logout
/home/a/.bash_profile
/home/a/.bashrc
[root@linux1 /]#
# find /etc -ctime -1

在/etc下查找24小时内被修改过属性的文件和目录
[root@linux1 /]# find /etc/ -ctime -1
/etc/
/etc/pki/tls
/etc/pki/tls/openssl.cnf
/etc/pki/CA
/etc/pki/CA/newcerts
/etc/pki/CA/newcerts/03.pem
/etc/pki/CA/newcerts/04.pem
/etc/pki/CA/serial.old
/etc/pki/CA/index.txt.old
/etc/pki/CA/index.txt.attr.old
/etc/pki/CA/crl.pem
/etc/pki/CA/crlnumber.old
/etc/pki/CA/crlnumber
/etc/pki/CA/serial
/etc/pki/CA/index.txt
/etc/pki/CA/index.txt.attr
/etc/issue
/etc/ssl
/etc/ssl/2.csr
/etc/ssl/1
/etc/ssl/1/skills.crt
/etc/ssl/1/skills.key
/etc/ssl/skills.key
/etc/ssl/skills.csr
/etc/ssl/skills.crt
/etc/ssl/client.pfx
/etc/adjtime
/etc/systemd/system/multi-user.target.wants
/etc/systemd/system/multi-user.target.wants/chronyd.service
/etc/chrony.conf
[root@linux1 /]# 
# find /etc -size +2048 -a -size -204800

在/etc下查找大于1MB小于100MB的文件
[root@linux1 /]# find /etc/ -size +2048 -a -size -204800
/etc/selinux/targeted/policy/policy.31
/etc/udev/hwdb.bin
/etc/insights-client/rpm.egg
[root@linux1 /]# 
# find /etc -name inittab -exec ls -l {} \;

在/etc下查找inittab文件并显示其详细信息
[root@linux1 /]# find /etc/ -name inittab -exec ls -l {} \;
-rw-r--r--. 1 root root 490 119 2021 /etc/inittab
[root@linux1 /]# 
# 查找非常规名文件 
-nane文件名
*匹配任意字符init*
?匹配单个字符init???
-size文件大小block数据块512字节=0.5KB
-user文件所有者
时间
1、天 ctime、atime、mtime
2、分钟 cmin、amin、mmin
c-change改变,表示文件属性被修改过,所有者、所属组、权限a-access访问
m-modify修改,表示文件内容被修改过
find /etc -mmin -120
-type文件类型	f二进制文件	1软链接文件 d目录
1、连接符 -a and逻辑与-o or逻辑或
2、连接符find .... -exec命令 {} \;
							{}find查询的结果
						\转义符,符号命令使用本身的含义
						; 结果
						-ok	(询问确认)
-inum	i节点

*文件搜索指令:locate*

指令名称:locate

指令英文原义:list files in databases

指令所在路径:/usr/bin/locate

执行权限:All User

语法:locate [搜索关键字]

功能描述:寻找文件或目录

范例: # locate sshd

列出所有跟sshd相关的文件
[root@linux1 ~]# locate sshd
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd
/etc/sysconfig/sshd-permitrootlogin
/etc/systemd/system/multi-user.target.wants/sshd.service
/usr/lib/systemd/system/anaconda-sshd.service
/usr/lib/systemd/system/sshd-keygen.target
/usr/lib/systemd/system/sshd-keygen@.service
/usr/lib/systemd/system/sshd.service
/usr/lib/systemd/system/sshd.socket
/usr/lib/systemd/system/sshd@.service
/usr/libexec/openssh/sshd-keygen
/usr/sbin/sshd
/usr/share/augeas/lenses/dist/sshd.aug
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sshd.8.gz
/usr/share/setroubleshoot/plugins/sshd_root.py
/usr/share/setroubleshoot/plugins/__pycache__/sshd_root.cpython-36.opt-1.pyc
/usr/share/setroubleshoot/plugins/__pycache__/sshd_root.cpython-36.pyc
/usr/share/vim/vim80/syntax/sshdconfig.vim
/var/empty/sshd
[root@linux1 ~]#  

*文件搜索指令:updatedb*

指令名称:updatedb

指令英文原义:update the slocate database

指令所在路径:/usr/bin/updatedb

执行权限:root

语法:updatedb

功能描述:建立整个系统目录文件的数据库

范例:# updatedb
[root@linux1 ~]# updatedb

*文件搜索命令:grep*

命令名称:grep

命令所在路径:/bin/grep

执行权限:所有用户

语法:grep [指定字串] [源文件]

功能描述:在文件中搜寻字串匹配的行并输出

范例:# grep ftp /etc/services
[root@linux1 ~]# grep tftp /etc/services 
tftp            69/tcp
tftp            69/udp
tftp-mcast      1758/tcp
tftp-mcast      1758/udp
mtftp           1759/udp        spss-lm
subntbcst_tftp  247/tcp   subntbcst-tftp     # SUBNTBCST_TFTP
subntbcst_tftp  247/udp   subntbcst-tftp     # SUBNTBCST_TFTP
etftp           1818/tcp                # Enhanced Trivial File Transfer Protocol
etftp           1818/udp                # Enhanced Trivial File Transfer Protocol
tftps           3713/tcp                # TFTP over TLS
tftps           3713/udp                # TFTP over TLS
[root@linux1 ~]# 

*帮助命令:man*

命令名称:man

命令英文原意:manual

命令所在路径:/usr/bin/man

执行权限:所有用户

语法:man [命令或配置文件]

功能描述:获得帮助信息

范例: # man ls

查看ls命令的帮助信息
[root@linux1 ~]# man ls
# man services

查看配置文件services的帮助信息

[root@linux1 ~]# man services
man passwd 查询passwd命令的帮助信息等价于man 1 passwd

查询/etc/passwd配置文件的帮助信息可以使用man 5 passwd
[root@linux1 ~]# man passwd
[root@linux1 ~]# man 5 passwd

*帮助指令:info*

指令名称:info

指令英文原义:information

指令所在路径:/usr/bin/info

执行权限:All User

语法:info [任何关键字]

功能描述:获得帮助信息

范例: # info ls

查看ls指令的帮助信息
[root@linux1 ~]# info ls

*压缩解压命令:gzip*

命令名称:gzip

命令英文原意:GNU zip

命令所在路径:/bin/gzip

执行权限:所有用户

语法:gzip 选项[文件]

功能描述:压缩文件

压缩后文件格式:.gz

#只能压缩文件,不能压缩目录
[root@linux1 dir1]# touch install.log
[root@linux1 dir1]# ls
1.conf  file1  file2  install.log
[root@linux1 dir1]# gzip install.log 
[root@linux1 dir1]# ls
1.conf  file1  file2  install.log.gz

[root@linux1 /]# gzip dir1
gzip: dir1 is a directory -- ignored

*压缩解压命令:gunzip*

命令名称:gunzip

命令英文原意:GNU unzip

命令所在路径:/bin/gunzip

执行权限:所有用户

语法:gunzip 选项[压缩文件]

功能描述:解压缩.gz的压缩文件

范例: # gunzip file1.gz
[root@linux1 dir1]# 
[root@linux1 dir1]# ls
file1  file2  install.log.gz
[root@linux1 dir1]# gunzip install.log.gz 
[root@linux1 dir1]# ls
file1  file2  install.log

*压缩解压命令:tar*

命令名称:tar

命令所在路径:/bin/tar

执行权限:所有用户

语法:tar 选项[cvf] [目录]

-c 产生.tar打包文件

-v 显示详细信息

-f 指定压缩后的文件名

-z 打包同时压缩

功能描述:打包目录

压缩后文件格式:.tar.gz

[root@linux1 dir1]# 
[root@linux1 dir1]# tar -zcvf test.tar.gz test/
test/
[root@linux1 dir1]# ls
file1  file2  install.log  test  test.tar.gz
[root@linux1 dir1]# 
范例:

# tar -zcvf test.tar.gz test

将目录test压缩成一个打包并压缩的文件

tar命令解压缩语法:

-x 解包.tar文件

-v 显示详细信息

-f 指定解压文件

-z 解压缩

范例:# tar -zxvf test.tar.gz
file1  file2  install.log  test  test.tar.gz
[root@linux1 dir1]# rm -rf test
[root@linux1 dir1]# 
[root@linux1 dir1]# 
[root@linux1 dir1]# ls
file1  file2  install.log  test.tar.gz
[root@linux1 dir1]# 
[root@linux1 dir1]# tar -zxvf test.tar.gz test
test/
[root@linux1 dir1]# ls
file1  file2  install.log  test  test.tar.gz
[root@linux1 dir1]# 

*压缩解压命令:zip*

命令名称:zip

命令所在路径:/usr/bin/zip

执行权限:所有用户

语法:

zip 选项[-r] [压缩后文件名称] [文件或目录]

-r 压缩目录

功能描述:压缩文件或目录

压缩后文件格式:.zip

范例:

# zip services.zip /etc/services

压缩文件
[root@linux1 dir1]# zip install.log.zip /dir1/
  adding: dir1/ (stored 0%)
[root@linux1 dir1]# ls
file1  file2  install.log  install.log.zip  test  test.tar.gz  test.zip
[root@linux1 dir1]# 

# zip -r test.zip /test

#压缩目录,把目录里的东西全部压缩
[root@linux1 dir1]# 
[root@linux1 dir1]# zip -r test.zip /dir1
  adding: dir1/ (stored 0%)
  adding: dir1/file2 (stored 0%)
  adding: dir1/file1 (stored 0%)
  adding: dir1/install.log (stored 0%)
  adding: dir1/test.tar.gz (stored 0%)
  adding: dir1/test/ (stored 0%)
  adding: dir1/install.log.zip (stored 0%)
[root@linux1 dir1]# ls
file1  file2  install.log  install.log.zip  test  test.tar.gz  test.zip
[root@linux1 dir1]# 


*压缩解压命令:unzip*

命令名称:unzip

命令所在路径:/usr/bin/unzip

执行权限:所有用户

语法:unzip [压缩文件]

功能描述:解压.zip的压缩文件

范例:# unzip test.zip
[root@linux1 dir1]# 
[root@linux1 dir1]# unzip test.zip 
Archive:  test.zip
   creating: dir1/
 extracting: dir1/file2              
 extracting: dir1/file1              
 extracting: dir1/install.log        
 extracting: dir1/test.tar.gz        
   creating: dir1/test/
 extracting: dir1/install.log.zip    
[root@linux1 dir1]# 

*网络通信命令:ping*

命令名称:ping

命令所在路径:/usr/sbin/ping

执行权限:root

语法:ping 选项IP地址

功能描述:测试网络连通性

范例: # ping 127.0.0.1	ctrl+c 退出
[root@linux1 /]# ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.094 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.159 ms
^C
--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1055ms
rtt min/avg/max/mdev = 0.094/0.126/0.159/0.034 ms
[root@linux1 dir1]# 

*网络通信命令:ifconfig*

命令名称:ifconfig

命令所在路径:/usr/sbin/ifconfig

执行权限:root

语法:ifconfig 选项[-a] [网卡设备标识]

-a 显示所有网卡信息

功能描述:查看网络设置信息

范例:# ifconfig -a
[root@linux1 /]# ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.201  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::20c:29ff:fee8:cdbe  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:e8:cd:be  txqueuelen 1000  (Ethernet)
        RX packets 22324125  bytes 12810399234 (11.9 GiB)
        RX errors 0  dropped 1163  overruns 0  frame 0
        TX packets 3420886  bytes 1871218845 (1.7 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 13975  bytes 4211941 (4.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 13975  bytes 4211941 (4.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:00:b4:a7  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0-nic: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 52:54:00:00:b4:a7  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@linux1 /]# 

系统关机命令

*系统关机命令:shutdown*

命令名称:shutdown

命令所在路径:/usr/sbin/shutdown

执行权限:root

语法:shutdown

功能描述:关机

范例:# shutdown -h now
[root@linux1 /]# shutdown -h now       

*系统关机命令:reboot*

命令名称:reboot

命令所在路径:/usr/sbin/reboot

执行权限:root

语法:reboot

功能描述:重启系统

范例:# reboot
范例:# reboot

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

耗同学一米八

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值