1.linux命令[ 复制粘贴 | 剪切 | 删除 | 查看 | 编辑vim | 压缩tar |
FQ:如果服务器里面加了一块硬盘也只有一个根是吗
windows多根的
linux 一切皆文件。
文件
目录
1 文件管理之:创建,复制,移动,删除
1.创建了一堆文件,文件要进行分门别类存储起来
1)创建一堆文件 {/data/filea-filez}
2) 创建一个目录 {/tata/dir}
3) 将文件剪贴到对应目录
4)删除文件
1.创建文件:touch
命令 路径
touch …
[[email protected] ~]# touch file{a…z} #集合
[[email protected] ~]# ll
总用量 4
-rw-------. 1 root root 1270 2月 29 18:05 anaconda-ks.cfg
-rw-r–r--. 1 root root 0 3月 5 09:43 filea
-rw-r–r--. 1 root root 0 3月 5 09:43 fileb
-rw-r–r--. 1 root root 0 3月 5 09:43 filec
-rw-r–r--. 1 root root 0 3月 5 09:43 filed
-rw-r–r--. 1 root root 0 3月 5 09:43 filee
-rw-r–r--. 1 root root 0 3月 5 09:43 filef
-rw-r–r--. 1 root root 0 3月 5 09:43 fileg
-rw-r–r--. 1 root root 0 3月 5 09:43 fileh
-rw-r–r--. 1 root root 0 3月 5 09:43 filei
-rw-r–r--. 1 root root 0 3月 5 09:43 filej
-rw-r–r--. 1 root root 0 3月 5 09:43 filek
-rw-r–r--. 1 root root 0 3月 5 09:43 filel
-rw-r–r--. 1 root root 0 3月 5 09:43 filem
-rw-r–r--. 1 root root 0 3月 5 09:43 filen
-rw-r–r--. 1 root root 0 3月 5 09:43 fileo
-rw-r–r--. 1 root root 0 3月 5 09:43 filep
-rw-r–r--. 1 root root 0 3月 5 09:43 fileq
-rw-r–r--. 1 root root 0 3月 5 09:43 filer
-rw-r–r--. 1 root root 0 3月 5 09:43 files
-rw-r–r--. 1 root root 0 3月 5 09:43 filet
-rw-r–r--. 1 root root 0 3月 5 09:43 fileu
-rw-r–r--. 1 root root 0 3月 5 09:43 filev
-rw-r–r--. 1 root root 0 3月 5 09:43 filew
-rw-r–r--. 1 root root 0 3月 5 09:43 filex
-rw-r–r--. 1 root root 0 3月 5 09:43 filey
-rw-r–r--. 1 root root 0 3月 5 09:43 filez
[[email protected] ~]#
touch file1 file2 file3 file4
touch file5 /tmp/file6
touch file{a…z}
touch file{A…Z}
touch file{01…10}
history
————————————————————————
创建目录:mkdir (目录通常显示为蓝色)
命: mkdir
选项:-p -v
参数:路径 在哪里创建
例1:
[[email protected] ~]# mkdir data -p
例2:
[[email protected] ~]# mkdir /home/od/dir1 /home/od/dir2 -p
vdir1 dir2
例3:
[[email protected] ~]# mkdir /home/od/{dir3,dir4}
[[email protected] ~]# ll /home/od/
total 0
drwxr-xr-x. 2 root root 6 Mar 5 10:08 dir1
drwxr-xr-x. 2 root root 6 Mar 5 10:08 dir2
drwxr-xr-x. 2 root root 6 Mar 5 10:10 dir3
drwxr-xr-x. 2 root root 6 Mar 5 10:10 dir4
例4:
[[email protected] ~]# mkdir -pv /home/{od/{diu,but},boy}
/home/od
/home/od/diu
/home/od/but
/home/boy
mkdir -pv /home/{od/{diu,but},boy}
tree 将目录以树状结构显示
yum install tree -y
acho #所见即所得
[[email protected] ~]# echo $LANG
en_US.UTF-8
[[email protected] ~]# LANG=en
[[email protected] ~]# touch /das/das/da/d/as
touch: cannot touch ‘/das/das/da/d/as’: No such file or directory
[[email protected] ~]# # 报错显示英文
——————————————————————————
3,拷贝文件
命令:cp
拷贝文件:cp [OPTION]… SOURCE… DIRECTORY
命令:cp
选项: -v:详细显示命令执行的操作 -r: 递归处理目录与子目录 -p: 保留源文件或目录的属性
参数:路径
例1:将当前目录下的file文件拷贝至/tmp/目录下
[[email protected] ~]# cp file /tmp/
例2:将当前目录下的file文件拷贝至/tmp/目录下,并改名为test.txt
[[email protected] ~]# cp file /tmp/test.txt
例3:重复拷贝一个文件,至/tmp/目录,会提示是否覆盖
[[email protected] ~]# cp file /tmp/test.txt
cp: overwrite ‘/tmp/test.txt’? #如果直接回车,则无反应
[[email protected] ~]# cp file /tmp/test.txt
cp: overwrite ‘/tmp/test.txt’? y #如果输入 y 则确定覆盖
[[email protected] ~]# echo “123”
123
[[email protected] ~]# echo “123” > file
[[email protected] ~]# cat file
123
[[email protected] ~]# cp file /tmp/test.txt
cp: overwrite ‘/tmp/test.txt’? y
[[email protected] ~]# cat /tmp/test.txt
123
[[email protected] ~]#
例4:直接使用cp无法拷贝目录,需要添加-r参数,才可以
[[email protected] ~]# cp -r /root/data/ /tmp/
例5:将多个文件拷贝到/tmp/data目录下(cp的最后一个目录就是目标,中间的都是要拷贝的源文件)
[[email protected] ~]# cp file01 file02 file3 /tmp/data/
[[email protected] ~]# ls /tmp/data/
file01 file02 file3
例6: -v显示拷贝的过程,通常我们都不用他
[[email protected] ~]# cp file04 /tmp/data/ -v
‘file04’ -> ‘/tmp/data/file04’
例7:-p 源文件之前是什么属性。就是什么属性。不改变。
#变更一下文件的权限(不用理解什么意思)
[[email protected] ~]# chown adm file04
-rw-r–r--. 1 adm root 0 Mar 5 09:44 file04
[[email protected] ~]# cp -p file04 /tmp/fil04_test
[[email protected] ~]# ll /tmp/fil04_test
-rw-r–r--. 1 adm root 0 Mar 5 09:44 /tmp/fil04_test
——————————————————————————
移动文件| 对文件进行改名:mv [OPTION]… SOURCE… DIRECTORY
例子1:
[[email protected] ~]# mv file /tmp/ #移动file文件至/tmp目录
[[email protected] ~]# mv file /tmp/file_mmm #移动file文件至/tmp目录下并修改文件名称
例子2:
[[email protected] ~]# mkdir /tmp/test #准备一个接收文件的目录
[[email protected] ~]# mv filea fileb filec /tmp/test #移动多个文件至一个目录下
[[email protected] ~]# mv file{01…10} /tmp/test #移动多个文件至一个目录下
例子3:给文件进行修改名称
[[email protected] ~]# mv file1 oldxu
例子4:mv可以直接移动目录,无需任何参数
[[email protected] ~]# mv data/ /tmp/test/
——————————————————————————————————
删除文件或目录:rm [OPTION]… FILE…
命令:rm
选项: -r: 递归 -f: 强制删除 -v: 详细过程
参数:路径
例子1:删除文件时候,会提醒是否删除。 (原因是默认rm存在alias别名,rm -i所以会提醒是否删除文件)
[[email protected] ~]# rm file.txt
例子2:删除文件时,不要提示,直接就删除。
[[email protected] ~]# rm -f file2 file3 file4 file5
例子3:删除目录,可以使用-r递归删除,但是会提示
[[email protected] ~]# mkdir qq
[[email protected] ~]# touch qq/1
[[email protected] ~]# touch qq/2
[[email protected] ~]# touch qq/3
[[email protected] ~]# rm -r qq/ #会不断提示,很费劲
rm: descend into directory ‘qq/’? y
rm: remove regular empty file ‘qq/1’? y
rm: remove regular empty file ‘qq/2’? y
rm: remove regular empty file ‘qq/3’?
例子4:-rf组合使用,可以删除任何东西,很危险,谨慎操作。
[[email protected] ~]# rm test/ -rf
例子5:
[[email protected] ~]# touch file{1…10}
[[email protected] ~]# rm -f file* # *表示通配符,表示所有的意思
例子6:
[[email protected] ~]# touch file{1…10}.txt # file1.txt file2.txt … file10.pdf
[[email protected] ~]# touch file{1…10}.pdf # file1.pdf file2.pdf … file10.pdf
[[email protected] ~]# rm -f file* #能删除名字是file开始的,后面是啥都不重要,会全部被删除
[[email protected] ~]# rm -f .pdf #删除所有.pdf结尾的文件
[[email protected] ~]# rm -f ./ #删除当前目录下的所有文件
注意:引入一个特殊的符号, “*” 表示匹配所有
————————————————————————————————
实验: 1.创建了一推的文件,文件要进行分门别类存储起来。
1) 创建一推文件 { /data/filea-filez }
2) 创建一个目录 { /data/dir }
3) 将文件剪贴到对应目录
4) 删除文件 { /data/dir/* }
1.创建一个/data目录,然后在/data目录下创建对应的文件。
[[email protected] ~]# mkdir -p /data #创建目录
[[email protected] ~]# touch /data/file{a…z} #在目录下创建文件
[[email protected] ~]# ls /data/ #检查一下
filea filed fileg filej filem filep files filev filey
fileb filee fileh filek filen fileq filet filew filez
filec filef filei filel fileo filer fileu filex
2.创建一个/data/dir目录。
[[email protected] ~]# mkdir /data/dir -p
[[email protected] ~]# ls /data/
dir filec filef filei filel fileo filer fileu filex
filea filed fileg filej filem filep files filev filey
fileb filee fileh filek filen fileq filet filew filez
3.移动data目录下的文件至/data/dir目录中
[[email protected] ~]# mv /data/file{a…z} /data/dir/ #将文件都移动到/data/dir目录中
[[email protected] ~]# ls /data/ #检查/data/目录
dir
[[email protected] ~]# ls /data/dir/ #检查/data/dir目录,确认文件是否移动成功
filea filed fileg filej filem filep files filev filey
fileb filee fileh filek filen fileq filet filew filez
filec filef filei filel fileo filer fileu filex
4.删除/data/dir/所有文件
[[email protected] ~]# rm -f /data/dir/* #删除/data/dir下的所有文件
[[email protected] ~]# ls /data/ #检查/data/目录
dir
[[email protected] ~]# ls /data/dir/ #检查/data/dir/目录
touch
mkdir
tree
cp
mv
rm