linux的基础命令

1.linux命令[ 复制粘贴 | 剪切 | 删除 | 查看 | 编辑vim | 压缩tar |

FQ:如果服务器里面加了一块硬盘也只有一个根是吗
windows多根的
在这里插入图片描述
linux 一切皆文件。
文件
目录

在这里插入图片描述1 文件管理之:创建,复制,移动,删除
1.创建了一堆文件,文件要进行分门别类存储起来
1)创建一堆文件 {/data/filea-filez}
2) 创建一个目录 {/tata/dir}
3) 将文件剪贴到对应目录
4)删除文件
1.创建文件:touch
命令 路径

touch …
[root@juw5207 ~]# touch file{a…z} #集合
[root@juw5207 ~]# 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
[root@juw5207 ~]#

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:
[root@oldboy ~]# mkdir data -p

例2:
[root@oldboy ~]# mkdir /home/od/dir1 /home/od/dir2 -p
vdir1 dir2

例3:
[root@oldboy ~]# mkdir /home/od/{dir3,dir4}
[root@oldboy ~]# 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:
[root@oldboy ~]# 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 #所见即所得

[root@juw5207 ~]# echo $LANG
en_US.UTF-8
[root@juw5207 ~]# LANG=en
[root@juw5207 ~]# touch /das/das/da/d/as
touch: cannot touch ‘/das/das/da/d/as’: No such file or directory
[root@juw5207 ~]# # 报错显示英文

——————————————————————————
3,拷贝文件
命令:cp
拷贝文件:cp [OPTION]… SOURCE… DIRECTORY
命令:cp
选项: -v:详细显示命令执行的操作 -r: 递归处理目录与子目录 -p: 保留源文件或目录的属性
参数:路径

例1:将当前目录下的file文件拷贝至/tmp/目录下
[root@oldboy ~]# cp file /tmp/

例2:将当前目录下的file文件拷贝至/tmp/目录下,并改名为test.txt
[root@oldboy ~]# cp file /tmp/test.txt

例3:重复拷贝一个文件,至/tmp/目录,会提示是否覆盖
[root@oldboy ~]# cp file /tmp/test.txt
cp: overwrite ‘/tmp/test.txt’? #如果直接回车,则无反应
[root@oldboy ~]# cp file /tmp/test.txt
cp: overwrite ‘/tmp/test.txt’? y #如果输入 y 则确定覆盖

[root@juw5207 ~]# echo “123”
123
[root@juw5207 ~]# echo “123” > file
[root@juw5207 ~]# cat file
123
[root@juw5207 ~]# cp file /tmp/test.txt
cp: overwrite ‘/tmp/test.txt’? y
[root@juw5207 ~]# cat /tmp/test.txt
123
[root@juw5207 ~]#

例4:直接使用cp无法拷贝目录,需要添加-r参数,才可以
[root@oldboy ~]# cp -r /root/data/ /tmp/

例5:将多个文件拷贝到/tmp/data目录下(cp的最后一个目录就是目标,中间的都是要拷贝的源文件)
[root@oldboy ~]# cp file01 file02 file3 /tmp/data/
[root@oldboy ~]# ls /tmp/data/
file01 file02 file3

例6: -v显示拷贝的过程,通常我们都不用他
[root@oldboy ~]# cp file04 /tmp/data/ -v
‘file04’ -> ‘/tmp/data/file04’

例7:-p 源文件之前是什么属性。就是什么属性。不改变。

#变更一下文件的权限(不用理解什么意思)
[root@oldboy ~]# chown adm file04
-rw-r–r--. 1 adm root 0 Mar 5 09:44 file04

[root@oldboy ~]# cp -p file04 /tmp/fil04_test
[root@oldboy ~]# ll /tmp/fil04_test
-rw-r–r--. 1 adm root 0 Mar 5 09:44 /tmp/fil04_test

——————————————————————————
移动文件| 对文件进行改名:mv [OPTION]… SOURCE… DIRECTORY

例子1:
[root@oldboy ~]# mv file /tmp/ #移动file文件至/tmp目录
[root@oldboy ~]# mv file /tmp/file_mmm #移动file文件至/tmp目录下并修改文件名称

例子2:
[root@oldboy ~]# mkdir /tmp/test #准备一个接收文件的目录
[root@oldboy ~]# mv filea fileb filec /tmp/test #移动多个文件至一个目录下
[root@oldboy ~]# mv file{01…10} /tmp/test #移动多个文件至一个目录下

例子3:给文件进行修改名称
[root@oldboy ~]# mv file1 oldxu

例子4:mv可以直接移动目录,无需任何参数
[root@oldboy ~]# mv data/ /tmp/test/

——————————————————————————————————
删除文件或目录:rm [OPTION]… FILE…
命令:rm
选项: -r: 递归 -f: 强制删除 -v: 详细过程
参数:路径

例子1:删除文件时候,会提醒是否删除。 (原因是默认rm存在alias别名,rm -i所以会提醒是否删除文件)
[root@oldboy ~]# rm file.txt

例子2:删除文件时,不要提示,直接就删除。
[root@oldboy ~]# rm -f file2 file3 file4 file5

例子3:删除目录,可以使用-r递归删除,但是会提示
[root@oldboy ~]# mkdir qq
[root@oldboy ~]# touch qq/1
[root@oldboy ~]# touch qq/2
[root@oldboy ~]# touch qq/3

[root@oldboy ~]# 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组合使用,可以删除任何东西,很危险,谨慎操作。
[root@oldboy ~]# rm test/ -rf

例子5:
[root@oldboy ~]# touch file{1…10}
[root@oldboy ~]# rm -f file* # *表示通配符,表示所有的意思

例子6:
[root@oldboy ~]# touch file{1…10}.txt # file1.txt file2.txt … file10.pdf
[root@oldboy ~]# touch file{1…10}.pdf # file1.pdf file2.pdf … file10.pdf

[root@oldboy ~]# rm -f file* #能删除名字是file开始的,后面是啥都不重要,会全部被删除
[root@oldboy ~]# rm -f .pdf #删除所有.pdf结尾的文件
[root@oldboy ~]# rm -f ./
#删除当前目录下的所有文件

注意:引入一个特殊的符号, “*” 表示匹配所有

————————————————————————————————

实验: 1.创建了一推的文件,文件要进行分门别类存储起来。
1) 创建一推文件 { /data/filea-filez }
2) 创建一个目录 { /data/dir }
3) 将文件剪贴到对应目录
4) 删除文件 { /data/dir/* }

1.创建一个/data目录,然后在/data目录下创建对应的文件。
[root@juw5207 ~]# mkdir /data/ -p #创建目录
[root@juw5207 ~]# touch /data/file{a…z} #在目录下创建文件
[root@juw5207 ~]# ls /data/ #检查一下
filea filec filee fileg filei filek filem fileo fileq files fileu filew filey
fileb filed filef fileh filej filel filen filep filer filet filev filex filez

2.创建一个/data/dir目录。
[root@juw5207 ~]# mkdir /data/dir -p
[root@juw5207 ~]# ls /data/
dir fileb filed filef fileh filej filel filen filep filer filet filev filex filez
filea filec filee fileg filei filek filem fileo fileq files fileu filew filey

3.移动data目录下的文件至/data/dir目录中
[root@juw5207 ~]# mv /data/file{a…z} /data/dir/ #将文件都移动到/data/dir目录
[root@juw5207 ~]# ls /data/dir/ #检查/data/dir目录,确认文件是否移动成功
filea filec filee fileg filei filek filem fileo fileq files fileu filew filey
fileb filed filef fileh filej filel filen filep filer filet filev filex filez

4.删除/data/dir/所有文件
[root@juw5207 ~]# rm -f /data/dir/* #删除/data/dir下的所有文件
[root@juw5207 ~]# ls /data/ #检查/data/目录
dir
[root@juw5207 ~]# ls /data/dir/ #检查/data/dir/目录
[root@juw5207 ~]#

touch
mkdir
tree
cp
mv
rm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值