Linux Learning Summary (10)-File copy and view, environment variables

Source: Internet
Author: User

A file copy and move

1. Command cp--------Copy meaning
Format CP option source file destination file
A: For files we direct CP file target file
Suppose we/home/lv in the normal user home directory
New two normal file touch 1.txt 2.txt
echo "SFSFSFSDF" >> 1.txt write some data in
CP 1.txt 2.txt This will prompt you whether to overwrite, meaning, whether to use
The contents of 1.txt replace the contents of 2.txt. It's starting here.
An-I alias option for security options that interact with the user.
Which CP will see alias cp= ' Cp-i '
CP 1.txt/media copy 1.txt to media directory, if media does not have the same name file, copy directly, if there is a prompt to overwrite
B:-R is used to copy a directory while replicating subdirectories and files, which is a recursive copy. Whether the overriding principle is the same. Cannot copy directory without the-r parameter

  1. MV----------the meaning of move
    Format MV option source file destination file
    MV is simpler, built-in alias-I is also a security option, other parameters are not used
    MV In addition to moving files, commonly used is the renaming function, is to move the file in the same directory, such as I have a Python program temporarily saved in the 2.txt file, then I want to run
    Can be MV 2.txt 2.py then Python 2.py can be viewed in two files

    Five-piece query set, cat more less head tail
    1. We use the most cat, can be directly with the file name to see the content
    There are two more options to keep an eye on,-N to display line numbers,-A to show everything out, including special characters, cat we often cooperate with append >>, filter grep use, for example, can:
    CAT/ETC/PASSWD |grep ' Home ' >> 2.txt we can get regular user information

  2. Cat's Flip command TAC can display content in flashbacks
  3. More when asking price content many pages, cat only display the last screen, then more can appear, CTRL b page forward, Ctrl F or the space bar back page, to the end of automatic exit. Early Exit Q
  4. Less, better than more than the place is, you can always flip to see, want to quit and then retreat.
    Less also has the query function, presses/, then enters the query character, presses the n key to be able to search backwards in turn, if you press? , enter a character, just look forward
    5.head Query the first 10 lines, tail query the last 10 rows, two commands can take the-n parameter, display the first few lines, or the last few lines can be written as Head-n4/etc/profile can also be written as Head-4/etc/profile
  5. The
  6. tail-f option dynamically displays the last 10 lines of a file, which is useful for analyzing logs later. Head does not have this option, you can open two terminals, verify.
    Summary, general small-scale query with cat, to fine-check the first few lines after a few lines with Head,tail
    file is very large with less, dynamic display with tail, with the pipeline more convenient such as
    Cat-n/etc/profiel |head-18 Show first 18 rows with line number three environment variable path

    If you have to ask what the environment variable is, my knowledge reserves is not enough to answer this question positively, then I will bring the Baidu Encyclopedia, convenient for you to see
    https://baike.baidu.com/item/%E7%8E% Af%e5%a2%83%e5%8f%98%e9%87%8f/1730949?fr=aladdin
    Of course, I would like to cite an example, I understand that if you install Python under WinDOS, then you should be impressed, When we start the Python interpreter under CMD, we must add the Python.exe file path to the WINDOS environment variable

    Otherwise you can't call Python, I'm not going to let you go back to Python, I just want to understand from this operation, We put the absolute path of an application in the system-specified location, which is the environment that the system assigns to us, and then establishes the connection.
    We go back to the Linux environment, further understanding, why we can directly enter the LS CD find and so many commands, how the computer found these commands, from where to find, is from the environment variables to find.
    Echo $PATH View environment variables
    typically have five paths two sbin three bin
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    We do a little experiment to understand the environment variable
    which LS view down LS position,/usr/bin/ls
    cp/usr/bin/ls/tmp
    mv/tmp/ls LS1
    path= $PATH:/tmp/
    Execution LS1 discovery is equivalent to LS, if you do not add an environment variable, you are not prompted to find LS1 unless you have an absolute path/tmp/ls1 can execute
    If you want the environment variable to take effect permanently, you can edit the/etc/profile file to add path= $PATH:/tmp/

Linux Learning Summary (10)-File copy and view, environment variables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.