万字肝货 | 超全总结,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/
相关文章
|
2月前
|
监控 Linux 网络安全
Linux命令大全:从入门到精通
日常使用的linux命令整理
601 13
|
2月前
|
存储 数据管理 Linux
区分Linux中.tar文件与.tar.gz文件的不同。
总之,".tar"文件提供了一种方便的文件整理方式,其归档但不压缩的特点适用于快速打包和解压,而".tar.gz"文件通过额外的压缩步骤,尽管处理时间更长,但可以减小文件尺寸,更适合于需要节约存储空间或进行文件传输的场景。用户在选择时应根据具体需求,考虑两种格式各自的优劣。
293 13
|
3月前
|
Linux 网络安全 数据安全/隐私保护
使用Linux系统的mount命令挂载远程服务器的文件夹。
如此一来,你就完成了一次从你的Linux发车站到远程服务器文件夹的有趣旅行。在这个技术之旅中,你既探索了新地方,也学到了如何桥接不同系统之间的距离。
385 21
|
3月前
|
JSON 自然语言处理 Linux
linux命令—tree
tree是一款强大的Linux命令行工具,用于以树状结构递归展示目录和文件,直观呈现层级关系。支持多种功能,如过滤、排序、权限显示及格式化输出等。安装方法因系统而异常用场景包括:基础用法(显示当前或指定目录结构)、核心参数应用(如层级控制-L、隐藏文件显示-a、完整路径输出-f)以及进阶操作(如磁盘空间分析--du、结合grep过滤内容、生成JSON格式列表-J等)。此外,还可生成网站目录结构图并导出为HTML文件。注意事项:使用Tab键补全路径避免错误;超大目录建议限制遍历层数;脚本中推荐禁用统计信息以优化性能。更多详情可查阅手册mantree。
linux命令—tree
|
1月前
|
监控 Linux Shell
linux命令
常用 Linux 命令汇总
|
3月前
|
监控 Linux
Linux系统中使用df命令详解磁盘使用情况。
`df`命令是Linux系统管理员和用户监控和管理磁盘空间使用的重要工具。掌握它的基本使用方法和选项可以帮助在必要时分析和解决空间相关问题。简洁但功能丰富,`df`命令确保了用户可以快速有效地识别和管理文件系统的空间使用情况。
204 13
|
3月前
|
Linux
Linux命令拓展:为cp和mv添加进度显示
好了,就这样,让你的Linux复制体验充满乐趣吧!记住,每一个冷冰冰的命令背后,都有方法让它变得热情起来。
216 8
|
2月前
|
Linux C++
每天一个linux命令(8):cp 命令
cp 命令是 Linux 中用于复制文件或目录的命令。它的名字来源于英文单词 copy。这个命令非常常用,特别是在需要备份文件或创建文件副本时。
64 0
|
3月前
|
安全 Linux 定位技术
Linux环境下必备的基础命令概览
以上就是Linux系统中的基本命令和工具,掌握它们就能帮你在Linux世界里游刃有余。这其实就像是学习驾驭一辆新车,熟悉了仪表盘,调整好了座椅,之后的旅程就只需要享受风驰电掣的乐趣了。
82 4
|
Linux 索引
linux命令—ls
`ls` 是 Linux 系统中用于列出目录内容的基础命令,功能强大且使用频率极高。它可以帮助用户查看文件、分析磁盘空间及检查权限等。常用选项如 `-l` 显示详细信息,`-a` 包含隐藏文件,`-h` 以易读格式展示大小,`-t` 按修改时间排序等。通过组合选项,可实现复杂需求,如递归遍历目录(`-R`)、显示 inode 号(`-i`)或结合正则过滤特定文件。注意权限限制、特殊字符处理及大规模目录操作可能带来的性能问题。掌握 `ls` 是高效使用 Linux 的关键一步。