万字肝货 | 超全总结,Linux常用磁盘命令、文件命令!(五)

简介: 万字肝货 | 超全总结,Linux常用磁盘命令、文件命令!(五)

② 将同一个文件,移动到不同目录下,如果没有指定新文件名,效果相当于移动。

此操作,仅相当于把sum.txt移动到aa目录下。

[root@image_boundary Desktop]# mv bb/sum.txt aa/

③ 将同一个文件,移动到不同目录下,可以不用修改文件名。

如果指定了新文件名,效果相当于移动+重命名。

[root@image_boundary Desktop]# mv bb/sum.txt aa/sum.txt
"把bb目录下的sum.txt文件,移动到aa目录下,并重命名为sum1.txt。"
[root@image_boundary Desktop]# mv bb/sum.txt aa/sum1.txt


8)head/tail:展示开头或者结尾的若干行,默认10行

-n :指定行数;

head :查看文件中所有内容;

tail :查看文件中所有内容;

head -n:查看前n行数据;

tail -n:查看后n行数据;

“在计划任务那里会用下面这个参数。”

“在hadoop集群里面,查看log日志文件的时候,会用到。”

tail -f:查看新追加内容;

操作如下:


[root@image_boundary Desktop]# ll
total 8
drwxr-xr-x. 2 root root 4096 Oct 15 22:35 aa
drwxr-xr-x. 2 root root 4096 Oct 15 22:30 bb
[root@image_boundary Desktop]# head -3 aa/sum.txt
aaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbb
ccccccccccccccccc
[root@image_boundary Desktop]# tail -3 aa/sum.txt
mmmmmmmmmmmmmmmmm
nnnnnnnnnnnnnnnnn
ooooooooooooooooo


9)cat/tac:查看文件内容

-n:显示文件行号。(这是cat常用的)

cat :查看文件中所有内容,正着查看。

tac :查看文件中所有内容,倒着查看。

操作如下:


[root@image_boundary Desktop]# cat -n aa/sum.txt
     1  1
     2  2
     3  3
     4  4


cat配合EOF命令,有一个比较厉害的操作:

image.png


10)more:分屏显示,每次显示一屏

q键:退出more命令。

Space键:显示文本的下一屏内容。

Enter键:只显示文本的下一行内容。

h键:显示帮助屏,该屏上有相关的帮助信息。

b键:显示上一屏内容。

11)less:分屏上下翻页浏览文件内容

q键:退出less命令。

G:跳到文件末尾

gg:跳到文件首行

按e键:向上滚动一行

按y键:向下滚动一行

操作如下:


less -N aa/sum.txt  此参数会显示文件内容的行数


结果如下:

image.png


12)echo:输出字符串或者变量

-e:处理特殊的符号。eg:写了-e,就会把\n当成换行符,否则不会。
echo $PWD :输出变量的绝对路径   
">表示覆盖源文件中的内容"     
echo   aa  > a.txt     
">>表示追加到源文件末尾"
echo   aa >> a.txt


操作如下:


[root@image_boundary Desktop]# echo "aa\nbb"
aa\nbb
[root@image_boundary Desktop]# clear
"-e参数,表示让系统能够识别特殊字符"
[root@image_boundary Desktop]# echo -e "aa\nbb"
aa
bb
[root@image_boundary Desktop]# echo -e "aa\tbb"
aa  bb
==================================================
"echo $PWD表示输出当前文件夹的绝对路经,很有用。"
[root@image_boundary Desktop]# echo $PWD
/root/Desktop
[root@image_boundary Desktop]# cd aa
[root@image_boundary aa]# echo $PWD
/root/Desktop/aa
[root@image_boundary aa]# cd ../bb
[root@image_boundary bb]# echo $PWD
/root/Desktop/bb
=================================================
[root@image_boundary Desktop]# echo -e '666\n888' > ./aa/aa.txt
[root@image_boundary Desktop]# echo -e '中国人' >> ./aa/aa.txt


13)ln:创建硬链接和软链接

硬链接类似于【复制】;

软连接类似于【创建快捷方式】(常用);

为f1 创建硬链接 f2 : ln f1 f2

为f1 创建软链接(也叫符号链接) f3 : ln -s f1 f3

操作如下:


[root@image_boundary Desktop]# ll
total 4
drwxr-xr-x. 2 root root 4096 Oct 15 23:28 aa
"创建一个文件test.txt"
[root@image_boundary Desktop]# cd aa
[root@image_boundary aa]# touch test.txt
"创建一个硬链接,相当于是复制了该文件"
[root@image_boundary aa]# ln test.txt test
"创建一个软连接,相当于给该文件创建了一个快捷方式"
[root@image_boundary aa]# ln -s test.txt s_test
[root@image_boundary aa]# echo "I am a student" >> test.txt
[root@image_boundary aa]# cat s_test
I am a student
[root@image_boundary aa]# cat  test
I am a student
"删除源文件test.txt后"
[root@image_boundary aa]# rm -rf test.txt
"软连接文件(快捷方式)会消失"
[root@image_boundary aa]# cat s_test
cat: s_test: No such file or directory
"但是这个硬链接(复制)不会消失"
[root@image_boundary aa]# cat test
I am a student



14)alias:查看某些命令的别名

“定义别名的意义在于,可以用别名,代替某些组合命令,减少敲代码;”

查看别名:alias

定义别名:alias la= ‘ll -a’

取消别名:unalias la

操作如下:


[root@image_boundary Desktop]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'



10、其他常用命令

clear 或 ctrl+l :清屏
history :显示历史代码命令
su :切换用户。$普通用户;#管理员root用户
hostname :显示主机名
sudo :以root用户权限执行一次命令(目前不太明白这个)
exit :退出当前登录状态。当前是普通用户切换到root用户;当前是root用户就切换到普通用户。
who :显示目前有哪些用户登入系统
| :管道符,表示把前面命令内容的输出,当做后面命令的输入。


11、案例讲解


操作如下:


"首先,创建这3个文件夹;"
[root@image_boundary Desktop]# mkdir myFile   
[root@image_boundary Desktop]# mkdir myPic
[root@image_boundary Desktop]# mkdir backup
[root@image_boundary Desktop]# ll
total 16
drwxr-xr-x. 2 root root 4096 Oct 15 23:36 aa
drwxr-xr-x. 2 root root 4096 Oct 15 23:57 backup
drwxr-xr-x. 2 root root 4096 Oct 15 23:56 myFile
drwxr-xr-x. 2 root root 4096 Oct 15 23:56 myPic
"分别在myFile、backup分别创建一个a.txt;"
[root@image_boundary Desktop]# cd myFile
[root@image_boundary myFile]# touch a.txt
[root@image_boundary myFile]# cd ..
[root@image_boundary Desktop]# cd backup
[root@image_boundary backup]# mkdir a.txt
"删除backup这个文件夹及其其中的内容;"
[root@image_boundary Desktop]# rm -rf backup
"将同一个文件夹移动到同级目录下,相当于修改名字;"
[root@image_boundary Desktop]# mv ./myFile ./File
"将File目录下的a.txt文件,移动到myPic目录下;"
[root@image_boundary Desktop]# cp ./File/a.txt ./myPic/
相关文章
|
23小时前
|
人工智能 Linux
Linux查找大文件的方法
Linux查找大文件的方法
|
1天前
|
监控 Linux Windows
50个必知的Linux命令技巧,你都掌握了吗?(下)
50个必知的Linux命令技巧,你都掌握了吗?(下)
|
1天前
|
Linux Shell Windows
Linux 常用基本命令
Linux 常用基本命令
|
2天前
|
Ubuntu Linux Shell
linux免交互登陆远程主机并执行命令(密钥对和Expect)
linux免交互登陆远程主机并执行命令(密钥对和Expect)
|
2天前
|
Linux
【Linux】常用命令
【Linux】常用命令
21 0
|
2天前
|
安全 Ubuntu Linux
Linux 网络操作命令Telnet
Linux 网络操作命令Telnet
16 0
Linux 网络操作命令Telnet
|
3天前
|
固态存储 Ubuntu Linux
Linux(29) 多线程快速解压缩|删除|监视大型文件
Linux(29) 多线程快速解压缩|删除|监视大型文件
11 1
|
3天前
|
Ubuntu Linux 数据安全/隐私保护
Linux(24) 如何在Ubuntu中操作rootfs.img文件
Linux(24) 如何在Ubuntu中操作rootfs.img文件
5 0
|
3天前
|
Linux 数据安全/隐私保护
Linux常用命令实例带注释
Linux常用命令实例带注释
30 0
|
3天前
|
Linux 开发工具 数据安全/隐私保护
Linux(19)常用解压命令记录
Linux(19)常用解压命令记录
9 0