Linux basics (1) ----- Linux commonly used commands

Recently I want to run experiments on the server, and found that I have very little knowledge of Linux, and only know some very simple commands; therefore, I decided to learn the following Linux-related knowledge from the beginning, then start with the common commands of Linux!

ls command

  • The meaning of
    ls The ls command can not only view the files contained in the linux folder, but also view file permissions (including directories, folders, and file permissions), view directory information, and so on.
  • grammar
    ls -a 列出目录所有文件,包含以.开始的隐藏文件
    ls -A 列出除.及..的其它文件
    ls -r 反序排列
    ls -t 以文件修改时间排序
    ls -S 以文件大小排序
    ls -h 以易读大小显示
    ls -l 除了文件名之外,还将文件的权限、所有者、文件大小等信息详细列出来
    
  • Example
    ls -t 
    

cd command

  • (1) Meaning
    The function of the cd command is to switch the current directory to dirName

  • (2) Grammar

    cd [dirname]
    
  • (3) Example

    • Enter the root directory
    cd /
    
    • Enter the user's home directory
    cd ~
    
    • Enter the last visited directory
    cd -
    

Here need to explain the difference between cd / and cd~:
cd / is to enter the root directory
cd ~ is to enter the user's home directory: it means to add you to log in as a Djk user, then cd ~ will enter the /home/Djk directory

pwd command

  • (1) Meaning The
    pwd command is used to view the current working directory path.
  • (2) Example
    • View current directory
    pwd
    

mkdir command

  • (1) Meaning The
    mkdir command is used to create a folder.
  • (2) Grammar
    mkdir -m
    mkdir -p
    
  • (3) Example
    • Create a folder t in the current working directory
    mkdir t
    
    • Create a directory with the path test/t1/t2 in the tmp directory, if it does not exist, create it:
    mkdir -p /tmp/test/t1/t2
    

touch command

  • Use the touch command to create an empty file

    touch filename
    
  • Use the touch command to create multiple files at once

    touch filename1 filename2 filename3
    

rm command

  • (1) Meaning
    Delete one or more files or directories in a directory. If the -r option is not used, rm will not delete the directory. If you use rm to delete a file, you can usually restore the file to its original state.

  • (2) Grammar

    rm [选项] 文件…
    
  • (3) Example

    • Delete any .log files, ask for confirmation one by one before deleting
    rm -i *.log
    

rmdir command

  • (1) Meaning
    To delete one or more sub-directory items from a directory, you must also have write permission to its parent directory when deleting a directory.
    Note: You cannot delete non-empty directories
  • (2) Grammar
rmdir 目录名
  • (3) Example
    • When the parent subdirectory is deleted to make it an empty directory, delete it at the same time:
    rmdir -p parent/child/child11
    

mv command

  • (1) Meaning To
    move a file or modify a file name, according to the second parameter type (such as a directory, move the file; if it is a file, re-order the file).
    When the second parameter is a directory, the first parameter can be multiple files or directories separated by spaces, and then move multiple files specified by the first parameter to the directory specified by the second parameter.
  • (2) Example
    • Rename the file test.log to test1.txt
    mv test.py test1.py
    

cp command

  • (1) Meaning
    Copy the source file to the target file, or copy multiple source files to the target directory.
    Note: For command line copy, if the target file already exists, it will prompt whether to overwrite. In the shell script, if the -i parameter is not added, it will not prompt, but overwrite directly!

  • (2) Grammar

    -i 提示
    -r 复制目录及目录内所有项目
    -a 复制的文件与原文件时间一样
    
  • (3) Example

    • Copy a.txt to the test directory, keep the original file time, if the original file exists, it will prompt whether to overwrite
    cp -ai a.txt test
    
    • Suggest a link (shortcut) for a.txt
    cp -s a.txt link_a.txt
    

cat command

cat has three main functions:

  • 1. Display the entire file at once
cat filename
  • 2. Create a file from the keyboard
cat > filename
  • 3. Combine several files into one file
cat file1 file2 > file

references

https://www.runoob.com/w3cnote/linux-common-command-2.html

Guess you like

Origin blog.csdn.net/dongjinkun/article/details/114636453