Linux usage operation[3]

Copyright Notice

  • The content of this blog is based on my personal study notes from the Dark Horse Programmer course. I hereby declare that all copyrights belong to Dark Horse Programmers or related rights holders. The purpose of this blog is only for personal learning and communication, not commercial use.
  • I try my best to ensure accuracy when organizing my study notes, but I cannot guarantee the completeness and timeliness of the content. The content of this blog may become outdated over time or require updating.
  • If you are a Dark Horse programmer or a related rights holder, if there is any copyright infringement, please contact me in time and I will delete it immediately or make necessary modifications.
  • For other readers, please abide by relevant laws, regulations and ethical principles when reading the content of this blog, refer to it with caution, and bear the resulting risks and responsibilities at your own risk. Some of the views and opinions in this blog are my own and do not represent the position of Dark Horse Programmers.

environment variables

  • Environment variables are some key information recorded by the operating system (Windows, Linux, Mac) when it is running to assist the system in running.
  • Execute the env command in the Linux system to view the environment variables recorded in the current system
  • Environment variables are a KeyValue type structure, that is, names and values, as shown below:
    Insert image description here
  • No matter what the current working directory is, the program /usr/bin/cd can be executed. This is done with the help of the value of the PATH item in the environment variable.
    Insert image description here
  • PATH records the search path for any command executed by the system. When any command is executed, the ontology of the program to be executed will be searched from the above path in order.

$ sign

  • In Linux systems, $symbols are used to get the value of "variables". The information recorded by environment variables is not only used by the operating system itself, but can also be used if we want to access it.
  • To obtain the value of an environment variable, you can obtain it through the syntax: ·$environment variable name·
  • For example: echo $PATHyou can get the value of the PATH environment variable and output it through the echo statement.
    Insert image description here

Set environment variables yourself

Linux environment variables can be set by users themselves, which are divided into:

  • Temporary setting, syntax: export variable name = variable value
  • Effective permanently
    • Effective for the current user, configured in the current user's: ~/.bashrcfile
    • Effective for all users, configured in the system:/etc/profile文件中
    • And use the syntax: source 配置文件, it will take effect immediately, or log in to FinalShell again to take effect.

Upload Download

  • Use the FinalShell tool to conveniently exchange data with virtual machines.
  • In the lower form of the FinalShell software, the Linux file system view is provided, which can be conveniently:
    • Browse the file system, find the appropriate file, right-click to download, and transfer it to your local computer
    • Browse the file system, find the appropriate directory, and expand the files on the local computer to easily upload data to Linux.

rz, sz command

  • Installation command
    yum -y install lrzsz
    
  • rz and sz are command line tools for file transfer in Linux systems, usually used with a terminal emulator such as xterm or gnome-terminal.
  1. rz command:
    • The rz command is used to upload files from the local computer to a remote computer, usually used in a terminal emulator.
    • After you launch the rz command using a terminal emulator, it waits for files to be sent from the remote computer.
    • Select Send File from the terminal emulator's menu and select the file to upload. rz will then receive and save the file to the remote computer's current directory.
  2. sz command:
    • The sz command is used to download files from a remote computer to the local computer, usually used in a terminal emulator.
    • After you launch the sz command using a terminal emulator, it will wait for you to specify the file to download. You use menus or commands in the terminal emulator to select files to download. sz will then send the selected files to the local computer's current directory.

Compression, decompression

  • There are two compression formats commonly used in Linux and Mac systems, and the suffix names are:
    • .tar, called tarball, is an archive file that simply assembles files into a .tar file. It does not reduce the file size much, it is just a simple package.
    • .gz, also commonly known as .tar.gz, gzip format compressed files, that is, using the gzip compression algorithm to compress the files into one file, which can greatly reduce the compressed volume.
  • For both formats, you can use the tar command to perform compression and decompression operations.
  • Basic syntax:
    tar [选项] [目标文件] [文件或目录...]
    
  • Options
    • -c, creates a compressed file, used in compression mode
    • -v, displays the compression and decompression process, used to view the progress
    • -x, decompression mode
    • -f, the file to be created, or the file to be decompressed, the -f option must be the last one among all options
    • -z, gzip mode, without -z it is ordinary tarball format
    • -C, select the decompression destination for decompression mode

tar command compression

  • Common combinations of tar are:
    tar -cvf test.tar 1.txt 2.txt 3.txt
    
    • Compress 1.txt 2.txt 3.txt into the test.tar file
    tar -zcvf test.tar.gz 1.txt 2.txt 3.txt
    
    • Compress 1.txt 2.txt 3.txt into the test.tar.gz file, using gzip mode

tar decompression

  • Commonly used tar decompression combinations include
  1. Unzip test.tar and extract the file to the current directory
    tar -xvf test.tar
    
  2. Unzip test.tar and extract the file to the specified directory (/home/it)
    tar -xvf test.tar -C /home/it
    
  3. Decompress test.tar.gz in Gzip mode and extract the file to the specified directory (/home/it)
    tar -zxvf test.tar.gz -C /home/it
    

zip command compresses files

  • You can use the zip command, and the compressed file is a zip compressed package.
  • Basic syntax:
    zip [-r] 参数1 参数2 ... 参数N
    

Example:

  • Compress a.txt b.txt c.txt into the test.zip file
    zip test.zip a.txt b.txt c.txt
    
  • Compress the test and itheima folders and the a.txt file into the test.zip file
    zip -r test.zip test itheima a.txt
    

unzip command to decompress files

  • Use the unzip command to easily decompress the zip archive.
  • grammar:
    unzip [-d] 参数
    
  • -d, specifies the location to decompress, the same as tar's -C option
  • Parameters, the decompressed zip package file

Guess you like

Origin blog.csdn.net/yang2330648064/article/details/133325895
Recommended