Linux文件处理命令

命令格式

1、目录处理命令

ls命令
Linux文件处理命令_第1张图片
文件信息
Linux文件处理命令_第2张图片
mkdir命令
Linux文件处理命令_第3张图片

[root@localhost tmp]# mkdir -p dry1/dry2
[root@localhost tmp]# mkdir dry1/dry3 dry1/dry4

rmdir命令
Linux文件处理命令_第4张图片

[root@localhost tmp]# rmdir dry1/dry2/

cp命令
Linux文件处理命令_第5张图片

[root@localhost dry1]# cp -rp dry3/test1.txt dry4/
[root@localhost dry1]# ls dry4/
test1.txt  test2.txt
[root@localhost dry1]# mkdir dry5
[root@localhost dry1]# ls
dry3  dry4  dry5
[root@localhost dry1]# cp -rp dry5/ dry3/
[root@localhost dry1]# ls dry3
dry5  test1.txt
[root@localhost dry1]# 

复制的同时改名

[root@localhost dry1]# cp -r dry3/test1.txt dry4/test4.txt
[root@localhost dry1]# ls dry4/
test1.txt  test2.txt  test4.txt

Crtl+L清屏

mv命令
Linux文件处理命令_第6张图片

 [root@localhost dry1]# touch test.txt
[root@localhost dry1]# ls
dry3  dry4  dry5  test.txt
[root@localhost dry1]# mv test.txt test_copy.txt 
[root@localhost dry1]# ls
dry3  dry4  dry5  test_copy.txt
[root@localhost dry1]# mv dry3/test1.txt dry4/test5.txt
[root@localhost dry1]# ls dry3/
dry5
[root@localhost dry1]# ls dry4/
test1.txt  test2.txt  test4.txt  test5.txt
[root@localhost dry1]# 

rm命令
Linux文件处理命令_第7张图片

[root@localhost dry1]# ls
dry3  dry4  dry5  test_copy.txt
[root@localhost dry1]# rm -rf test_copy.txt 
[root@localhost dry1]# ls
dry3  dry4  dry5
[root@localhost dry1]# rm -rf dry5/
[root@localhost dry1]# ls
dry3  dry4
[root@localhost dry1]# 

touch命令
Linux文件处理命令_第8张图片

[root@localhost dry1]# touch test.txt
[root@localhost dry1]# ls
dry3  dry4  test.txt
[root@localhost dry1]# 

cat命令
Linux文件处理命令_第9张图片

[root@localhost dry1]# cat test.txt -n
     1	hello helli 
     2	
     3	
     4	hello
     5	bkshfka
     6	bfkabkja
[root@localhost dry1]# 

tac命令
Linux文件处理命令_第10张图片

[root@localhost dry1]# tac test.txt 
bfkabkja
bkshfka
hello


hello helli 
[root@localhost dry1]# 

more命令
Linux文件处理命令_第11张图片

[root@localhost dry1]# more /etc/services 

less命令
Linux文件处理命令_第12张图片

[root@localhost dry1]# less /etc/services 

head命令
Linux文件处理命令_第13张图片

[root@localhost dry1]# head -n 20 /etc/services 

tail命令
Linux文件处理命令_第14张图片

[root@localhost dry1]# tail -n 20 /etc/services 

ln命令
Linux文件处理命令_第15张图片
Linux文件处理命令_第16张图片

[root@localhost dry1]# ln -s /etc/issue /tmp/issue.sooft
[root@localhost dry1]# ls /tmp/issue.sooft 
/tmp/issue.sooft
[root@localhost dry1]# ln /etc/issue /tmp/issue.hard
[root@localhost dry1]# ls /tmp/issue.hard 
/tmp/issue.hard
[root@localhost dry1]# 

Linux文件处理命令_第17张图片

[root@localhost dry1]# ls
dry3  dry4  dry test  test.txt  test.txt1  test.txt_hard
[root@localhost dry1]# ls -i test.txt test.txt1 test.txt_hard 
262272 test.txt  262283 test.txt1  262272 test.txt_hard

chmod命令

Linux文件处理命令_第18张图片

[root@localhost dry1]# ll test.txt
-rw-r--r--. 2 root root 38 May 25 19:31 test.txt
[root@localhost dry1]# chmod u+x test.txt
[root@localhost dry1]# ll test.txt
-rwxr--r--. 2 root root 38 May 25 19:31 test.txt
[root@localhost dry1]# 

添加多个权限

[root@localhost dry1]# ll test.txt
-rwxr--r--. 2 root root 38 May 25 19:31 test.txt
[root@localhost dry1]# chmod g+w,o-r test.txt
[root@localhost dry1]# ll test.txt
-rwxrw----. 2 root root 38 May 25 19:31 test.txt
[root@localhost dry1]# chmod o=rwx test.txt
[root@localhost dry1]# ll test.txt
-rwxrw-rwx. 2 root root 38 May 25 19:31 test.txt
[root@localhost dry1]# 

Linux文件处理命令_第19张图片

[root@localhost dry1]# chmod 777 test.txt
[root@localhost dry1]# ll test.txt
-rwxrwxrwx. 2 root root 38 May 25 19:31 test.txt
[root@localhost dry1]# 

Linux文件处理命令_第20张图片
chown命令
Linux文件处理命令_第21张图片

  [root@localhost ~]# touch test
[root@localhost ~]# ls 
1.sh            abc              Desktop    hello.sh            Pictures   test
2020-05-23.log  abc1             Documents  install.log         Public     test.txt
2.sh            access_log.2020  Downloads  install.log.syslog  shtest     Videos
3.sh            anaconda-ks.cfg  dry        Music               Templates
[root@localhost ~]# ll test
-rw-r--r--. 1 root root 0 May 26 02:25 test
[root@localhost ~]# useradd test
[root@localhost ~]# chown test test
[root@localhost ~]# ll test
-rw-r--r--. 1 test root 0 May 26 02:25 test
[root@localhost ~]# 

chgrp命令
Linux文件处理命令_第22张图片

[root@localhost ~]# ll test
-rw-r--r--. 1 test root 0 May 26 02:25 test
[root@localhost ~]# groupadd dry1
[root@localhost ~]# chgrp dry1 test
[root@localhost ~]# ll test
-rw-r--r--. 1 test dry1 0 May 26 02:25 test
[root@localhost ~]# 

umask命令
Linux文件处理命令_第23张图片

[root@localhost ~]# mkdir dd
[root@localhost ~]# ls -ld dd
drwxr-xr-x. 2 root root 4096 May 26 02:34 dd
[root@localhost ~]#  touch dd.txt
[root@localhost ~]# ll dd.txt 
-rw-r--r--. 1 root root 0 May 26 02:35 dd.txt

find命令
Linux文件处理命令_第24张图片

Linux文件处理命令_第25张图片

[root@localhost ~]# find /etc -name init
/etc/kdump-adv-conf/kdump_initscripts/init
/etc/init
/etc/sysconfig/init
[root@localhost ~]# find /etc -name *init*
/etc/selinux/targeted/contexts/initrc_context
/etc/rc.sysinit
/etc/festival/siteinit.scm
/etc/init.conf
[root@localhost ~]# find /etc -name init*
[root@localhost ~]# find /etc -name init???
/etc/inittab
[root@localhost ~]# 
[root@localhost ~]# find -user test
./test
[root@localhost ~]# 
[root@localhost ~]# find / -size +204800

Linux文件处理命令_第26张图片

[root@localhost ~]# find /etc -cmin -6

Linux文件处理命令_第27张图片

[root@localhost ~]# find /etc/ -size +163840 -a -size -204800
[root@localhost ~]# find /etc/ -size +163840 -o -size -204800
[root@localhost ~]# find /etc/ -name inittab -exec ls -l {} \;

Linux文件处理命令_第28张图片

[root@localhost ~]# find /etc/ -name init* -a -type d
/etc/init
/etc/rc.d/init.d
[root@localhost ~]# 
[root@localhost ~]# ls -i 
144158 1.sh             144592 anaconda-ks.cfg  144170 dry                 144092 shtest
144118 2020-05-23.log   144249 dd               144136 hello.sh            144653 Templates
144157 2.sh             144117 dd dd            131075 install.log         144169 test
144174 3.sh             144263 dd.txt           131076 install.log.syslog  144139 test.txt
144119 abc              144651 Desktop          144656 Music               272526 Videos
144125 abc1             144655 Documents        272525 Pictures
136757 access_log.2020  144652 Downloads        144654 Public
[root@localhost ~]# find . -inum 144117 -exec rm {} \;
[root@localhost ~]# ls -i 
144158 1.sh             144592 anaconda-ks.cfg  144136 hello.sh            144653 Templates
144118 2020-05-23.log   144249 dd               131075 install.log         144169 test
144157 2.sh             144263 dd.txt           131076 install.log.syslog  144139 test.txt
144174 3.sh             144651 Desktop          144656 Music               272526 Videos
144119 abc              144655 Documents        272525 Pictures
144125 abc1             144652 Downloads        144654 Public
136757 access_log.2020  144170 dry              144092 shtest
[root@localhost ~]# 

locate命令
Linux文件处理命令_第29张图片

[root@localhost ~]# locate inittab
/etc/inittab
/usr/share/augeas/lenses/dist/inittab.aug
/usr/share/man/man5/inittab.5.gz
/usr/share/vim/vim74/syntax/inittab.vim
[root@localhost ~]# 
[root@localhost ~]# updatedb  更新文件资料库

which命令
Linux文件处理命令_第30张图片

[root@localhost ~]# which ls
alias ls='ls --color=auto'
	/bin/ls
[root@localhost ~]#  

whereis命令
Linux文件处理命令_第31张图片

[root@localhost ~]# whereis ls
ls: /bin/ls /usr/share/man/man1p/ls.1p.gz /usr/share/man/man1/ls.1.gz
[root@localhost ~]# whereis useradd
useradd: /usr/sbin/useradd /usr/share/man/man8/useradd.8.gz
[root@localhost ~]# 

grep命令
Linux文件处理命令_第32张图片

[root@localhost ~]# more /etc/inittab 
[root@localhost ~]# grep reboot /etc/inittab 
#   6 - reboot (Do NOT set initdefault to this)
[root@localhost ~]# 
[root@localhost ~]# grep -v ^# /etc/inittab 
id:5:initdefault:
[root@localhost ~]# 

man命令

Linux文件处理命令_第33张图片

[root@localhost ~]# man ls
[root@localhost ~]# man services

help命令
Linux文件处理命令_第34张图片

[root@localhost ~]# help umask

useradd命令
Linux文件处理命令_第35张图片

passwd命令
Linux文件处理命令_第36张图片

[root@localhost ~]# useradd xiaocui
[root@localhost ~]# passwd xiaocui
Changing password for user xiaocui.
New password: 
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost ~]# 
[xiaocui@localhost root]$ passwd 修改用户密码

who命令
Linux文件处理命令_第37张图片
w命令
Linux文件处理命令_第38张图片

 [root@localhost ~]# w
 04:02:42 up 4 days, 18:56,  5 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1     :0               Thu09    4days 28.28s 28.28s /usr/bin/Xorg :0 -br -verbose
root     pts/0    192.168.137.1    18:48    7:50m  0.23s  0.23s -bash
root     pts/1    :0.0             Thu09    4days  0.02s  0.02s bash
root     pts/2    192.168.137.1    02:23    0.00s  0.63s  0.21s w
root     pts/3    192.168.137.1    02:24    2:40   0.02s  0.02s -bash
[root@localhost ~]# uptime
 04:03:56 up 4 days, 18:57,  5 users,  load average: 0.00, 0.00, 0.00
[root@localhost ~]# 

gzip命令
Linux文件处理命令_第39张图片

[root@localhost tmp]# touch test.txt
[root@localhost tmp]# gzip test.txt 

gunzip命令
Linux文件处理命令_第40张图片

[root@localhost tmp]# gunzip test.txt.gz 

tar命令
Linux文件处理命令_第41张图片

[root@localhost tmp]# tar -zcf test1.tar test.txt 
[root@localhost tmp]# tar -zcf test1.tar.gz test.txt

Linux文件处理命令_第42张图片

[root@localhost tmp]# tar -zxvf test1.tar.gz 
test.txt

zip命令
Linux文件处理命令_第43张图片

 [root@localhost tmp]# zip test.zip test.txt 
 [root@localhost tmp]# zip -r test.zip test

unzip命令
Linux文件处理命令_第44张图片

[root@localhost tmp]# unzip test.zip 

bzip2命令
Linux文件处理命令_第45张图片
bunzip命令
Linux文件处理命令_第46张图片
write命令
Linux文件处理命令_第47张图片
last命令
Linux文件处理命令_第48张图片
lastlog命令Linux文件处理命令_第49张图片

[root@localhost tmp]# lastlog

traceroute命令
Linux文件处理命令_第50张图片

[root@localhost tmp]# traceroute www.baidu.com

netstat命令
Linux文件处理命令_第51张图片
Linux文件处理命令_第52张图片

setup命令
Linux文件处理命令_第53张图片
mount命令
Linux文件处理命令_第54张图片

你可能感兴趣的:(Linux)