万字肝货 | 超全总结,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/
相关文章
|
6天前
|
Linux
Linux系统之whereis命令的基本使用
Linux系统之whereis命令的基本使用
50 23
Linux系统之whereis命令的基本使用
|
3天前
|
存储 网络协议 Linux
【Linux】进程IO|系统调用|open|write|文件描述符fd|封装|理解一切皆文件
本文详细介绍了Linux中的进程IO与系统调用,包括 `open`、`write`、`read`和 `close`函数及其用法,解释了文件描述符(fd)的概念,并深入探讨了Linux中的“一切皆文件”思想。这种设计极大地简化了系统编程,使得处理不同类型的IO设备变得更加一致和简单。通过本文的学习,您应该能够更好地理解和应用Linux中的进程IO操作,提高系统编程的效率和能力。
50 34
|
20天前
|
网络协议 Unix Linux
深入解析:Linux网络配置工具ifconfig与ip命令的全面对比
虽然 `ifconfig`作为一个经典的网络配置工具,简单易用,但其功能已经不能满足现代网络配置的需求。相比之下,`ip`命令不仅功能全面,而且提供了一致且简洁的语法,适用于各种网络配置场景。因此,在实际使用中,推荐逐步过渡到 `ip`命令,以更好地适应现代网络管理需求。
33 11
|
23天前
|
Ubuntu Linux 网络安全
Linux磁盘挂接教程
Linux磁盘挂接教程
55 14
|
2月前
|
Ubuntu Linux Go
golang编译成Linux可运行文件
本文介绍了如何在 Linux 上编译和运行 Golang 程序,涵盖了本地编译和交叉编译的步骤。通过这些步骤,您可以轻松地将 Golang 程序编译成适合 Linux 平台的可执行文件,并在目标服务器上运行。掌握这些技巧,可以提高开发和部署 Golang 应用的效率。
273 14
|
2月前
|
Ubuntu Linux
Linux 各发行版安装 ping 命令指南
如何在不同 Linux 发行版(Ubuntu/Debian、CentOS/RHEL/Fedora、Arch Linux、openSUSE、Alpine Linux)上安装 `ping` 命令,详细列出各发行版的安装步骤和验证方法,帮助系统管理员和网络工程师快速排查网络问题。
203 20
|
2月前
|
存储 NoSQL Linux
linux积累-core文件是干啥的
核心文件是Linux系统在程序崩溃时生成的重要调试文件,通过分析核心文件,开发者可以找到程序崩溃的原因并进行调试和修复。本文详细介绍了核心文件的生成、配置、查看和分析方法
155 6
|
2月前
|
Linux
linux查看目录下的文件夹命令,find查找某个目录,但是不包括这个目录本身?
通过本文的介绍,您应该对如何在 Linux 系统中查看目录下的文件夹以及使用 `find` 命令查找特定目录内容并排除该目录本身有了清晰的理解。掌握这些命令和技巧,可以大大提高日常文件管理和查找操作的效率。 在实际应用中,灵活使用这些命令和参数,可以帮助您快速定位和管理文件和目录,满足各种复杂的文件系统操作需求。
140 8
|
2月前
|
存储 NoSQL Linux
linux之core文件如何查看和调试
通过设置和生成 core 文件,可以在程序崩溃时获取详细的调试信息。结合 GDB 等调试工具,可以深入分析 core 文件,找到程序崩溃的具体原因,并进行相应的修复。掌握这些调试技巧,对于提高程序的稳定性和可靠性具有重要意义。
400 6
|
9月前
|
Linux
linux(二十八)磁盘管理类命令df、du和free查看磁盘和目录空间占用
linux(二十八)磁盘管理类命令df、du和free查看磁盘和目录空间占用
187 0