find files
find
soft link
ln
Packing and Compression
tar
Software Installation
apt-get
1. Find files
The find command is powerful and is usually used to search for qualified files in a specific directory
serial number |
Order |
effect |
01 |
find[path] -name "*.py" |
Find files with the extension .py in the specified path , including subdirectories |
If the path is omitted, it means to search under the current folder
The wildcards learned before are also available when using the find command
exercise goal
Search for files in the desktop path whose filename contains 1
find -name "*1*"
Search for all files with .txt extension in the desktop directory
find -name "*.txt"
Search for files starting with the number 1 in the desktop directory
find -name "1*"
2. Soft link
serial number |
Order |
effect |
01 |
ln -s linked source file link file |
Create soft links to files , similar to shortcuts under Windows |
Notice:
A hard link file is created without the -s option
The two files occupy the same size of hard disk space, and hard links to files are hardly established during work
The source file should use an absolute path instead of a relative path, so that it can still be used normally after moving the linked file
exercise goal
Move 01.py in the desktop directory to demo/b/c
Create a soft link FirstPython of 01.py in the desktop directory
Use relative path and absolute path respectively to establish soft link of FirstPython
Move FirstPython to the demo directory, and compare the difference between using relative paths and absolute paths
Introduction to Hard Links
When using ln to create a link, if there is no -s option, a hard link will be created instead of a soft link
Hard Link Walkthrough
Create a hard link 01_hard of ~/desktop/demo/b/c/01.py in the ~/desktop/demo directory
Use ls-l to view the number of hard links of files (hard links - how many ways to access files or directories)
Delete ~/desktop/demo/b/c/01.py and use tree to confirm the three link files in the demo directory
Schematic diagram of soft and hard links of files
In Linux , the file name and the data of the file are stored separately
hint:
In Linux , only the hard link number of the file == 0 will be deleted
Use ls -l to view the number of hard links in a file
In daily work, hard links to files are hardly established , just know
3. Package compression
Packing and compression is a way of backing up files in daily work
In different operating systems, the commonly used packaging and compression methods are different
Windows commonly used rar
Mac commonly used zip
Linux commonly used tar.gz
3.1 Packing/unpacking
tar is the most commonly used backup tool in Linux . This command can pack a series of files into a large file , and can also restore a series of files from a packaged large file.
tar is only responsible for packaging, not for compression
The command format of tar is as follows:
# 打包文件
tar -cvf 打包文件.tar 被打包文件/路径...
# 解包文件
tar -xvf 打包文件.tar
Description of tar options
options |
meaning |
c |
Generate archive file, create package file |
x |
unpack the archive |
v |
List the detailed process of archiving and unarchiving, and display the progress |
f |
Specify the name of the archive file, f must be followed by a .tar file , so it must be placed at the end of the option |
Packing and Unpacking Walkthrough
Delete everything under the desktop
Create three blank files 01.py, 02.py, 03.py under the desktop
Pack these three files into a py.tar package
Create a new tar directory and move py.tar to the tar directory
unpack py.tar
3.2 Compression/Decompression
3.2.1 gzip
The combination of tar and gzip commands can realize file packaging and compression
tar只负责打包文件,但不压缩
用gzip压缩tar打包后的文件,其扩展名一般用xxx.tar.gz
在Linux中,最常见的压缩文件格式就是xxx.tar.gz
在tar命令中有一个选项-z可以调用gzip,从而可以方便实现压缩和解压缩功能
命令格式如下:
# 压缩文件
tar -zcvf 打包文件.tar.gz 被压缩的文件/路径...
# 解压缩文件
tar -zxvf 打包文件.tar.gz
# 解压缩到指定路径
tar -zxvf 打包文件.tar.gz -C 目标路径
选项 |
含义 |
-C |
解压缩到指定目录,注意:要解压缩的目录必须存在 |
3.2.2 bzip2(two)
tar与bzip2命令结合可以使用实现文件打包和压缩(用法和gzip一样)
tar只负责打包文件,但不压缩
用bzip2压缩tar打包后的文件,其扩展名一般用xxx.tar.bz2
在tar命令中有一个选项-j可以调用bzip2,从而可以方便的实现压缩和解压缩功能
命令格式如下
# 压缩文件
tar -jcvf 打包文件.tar.bz2 被压缩的文件/路径...
# 解压缩文件
tar -jxvf 打包文件.tar.bz2
4.软件安装
4.1通过apt安装/卸载软件
apt是Advanced Packaging Tool 是Linux下的一款安装包管理工具
可以在终端方便的安装/卸载/更新安装包
# 安装软件
$ sudo apt install 软件包
# 卸载软件
$ sudo apt remove 软件名
# 更新已安装的包
$ sudo apt upgrade
安装演练
# 一个小火车提示
$ sudo apt install sl
# 一个比较漂亮的查看当前进程排名的软件,退出程序用q
$ sudo apt install htop
4.2配置软件源
如果希望在ubuntu中安装软件,更加快速,可以通过设置镜像源,选择一个访问网速更快的服务器来提供软件下载/安装服务
提示:更换服务器后,需要一个相对比较长时间的更新过程,需要耐心等待。更新完成后,再安装软件都会从新设置的服务器下载软件了
所谓镜像源,就是所有服务器的内容是相同的(镜像),但是根据所在位置的不同,国内服务器通常速度会更快一些
点击按钮,显示应用程序
点击 红色方框 内容处
如果有比较倾向的服务器,找到对应的选中即可,如果不知道哪个服务器效果比较好,点击 选择最佳服务器 按钮
寻找最佳服务器的过程,时间较长,耐心等待
测试完成后,点击 选择服务器按钮
然后按照提示输入对应用户的密码,点击授权
点击关闭,在弹窗中,点击 重新载入,将所有软件源的信息进行更新缓存,耗时较长,耐心等待