This is the 13th day of my participation in Gwen Challenge

First, the principle of command

  1. Commands are classified into internal commands and external commands.
    • The command line is also a program that executes as a command anything before the first space of a character entered by the user
    • If the internal command is executed directly, the external command needs to find the corresponding file based on the environment variable, and then execute the file

  1. type: Indicates the command type
    • Internal command | external commands
  2. help: Internal help command
    • See what this command does
    help cd
    Copy the code
  3. man: Help manual
    • It is also used to view commands, but in more detail
    • Each command has its own category, and the same command can have multiple categories
    Man 1: user commands (/bin, /usr/bin, /usr/bin)local/bin) 2: system call 3: library user 4: special file (device file) 5: file format (syntax of configuration file) 6: game 7: Miscellaneous 8: management commands (/sbin, /usr/sbin, /usr/local/sbin)
    Copy the code
  4. file: Displays the file type
    • ELF: a binary file
[root@node01 ~]# type ifconfig
ifconfig is /sbin/ifconfig
[root@node01 ~]# file /sbin/ifconfig
/sbin/ifconfig: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
Copy the code
  1. echo: Prints to standard output
    • Print what you wrote later below
[root@node01 ~]# echo abcd
abcd
Copy the code
  1. The environment variable
    • You can display the paths of all environment variables with the following command
    [root@node01 ~]# echo $PATH
    /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
    Copy the code
  2. Whereis: Views the location of the command
  3. Current System language
[root@node01 ~]# echo $LANG
en_US.UTF-8
Copy the code
  1. ps
    • -ef: Displays all running processes in the system
  2. variable
    • You can also define variables in Linux
    1. A single variable
    [root@node01 ~]# a=1
    [root@node01 ~]# echo $a
    1
    Copy the code
    1. An array of
      • Linux is sensitive to Spaces, not commas
    [root@node01 ~]# b=(1 k 2 4)
    [root@node01 ~]# echo $b
    1
    [root@node01 ~]# echo ${b[1]}
    k
    Copy the code
  3. hash: a cache area
    • Some command paths are cached here instead of having to find them on disk
    • -r: Clear the cache

File system commands

  1. directory
/boot: files related to system startup, such as the kernel, initrd, and GRUB (bootloader) /dev: Device file /etc/configuration file /home: indicates the home directory of the user. The default home directory of each user is /home/username /root: indicates the home directory of the administrator. /lib: library file /media: mount point directory, mobile device/MNT: mount point directory, additional temporary file system /opt: optional directory, installation directory of third-party programs /proc: pseudo-file system, kernel mapping file /sys: pseudo-file system, hardware device-related attribute mapping file/TMP: Temporary file: /var/tmp/var: changeable file /bin: executable file. User command /sbin: management commandCopy the code
  1. Properties for file and directory display

    1. The file type

    • Appears in the first letter
    - : common file (F) D: directory file B: block device file C: character device file L: symbolic link file P: command pipe file s: socket fileCopy the code
    1. File permissions
      • First: permissions for the file owner (u), in this case root
      • Second: permissions for owning group (g)
      • Third: permissions for other people (O)

    • Nine in a group of three
    • Each group: RWX (read, write, execute)
    1. Number of hard links

    • Hard links are Windows create shortcuts (shortcuts created several times)
    1. The owner of the file

    • Who does the file belong to
    1. Group of the file

    • Which group the file belongs to
    1. File size, in bytes

    • The file size
    1. Timestamp: indicates the time when it was last modified

    • The time when it was last modified
  2. Df: displays the disk usage

    • -h: Displays the size unit
    • When the system will be partition, see the size of each partition and directory
  3. Du: displays the file usage

    • -s: indicates the total size of all files
    • -h: Displays the size unit
    • -a: Even the size of hidden files is displayed
  4. Ls: displays the directory

    • -r: reverses the file display order
    • -t: displays the file order according to the file modification time
    • -lha
    • You can use the ls command to list the contents of multiple folders simultaneously
    // Displays the ls /etc/temp file under etc and temp at the same timeCopy the code
  5. – CD: switches the working directory

  6. -mkdir: creates a directory

    • -p: a directory can be created in a non-existent directory
    • Create multiple directories at once
    Mkdir a/{1,2,3}dirCopy the code
  7. Rm: delete

  8. Cp: copy

  9. Mv: mobile

  10. Ln: link

    • Default hard link
      • Quite socp -p, copies a file and synchronizes the creation time of the copied file
      • If the source file is deleted, the hard-linked file is not deleted
      • This creates a variable pointing to the memory address space, and the variable is deleted without any problem
    • -s: soft link
      • Windows equivalent to create shortcuts
      • The link is deleted when the source file is deleted
      ln -s test test.soft
      Copy the code
  11. Stat: displays metadata information

  12. touch

    1. Change all three times in the file to the present time
      • Application:
    2. Create a file
    touchh abc.txt
    Copy the code

File operation command

  1. cat: Displays the file on the command line
    • If the file is too large some of the content will not be visible
  2. more: Displays files in pages
    • Display file contents one screen at a time
    • Space: Displays the next page
    • However, the command does not scroll up, and exits when it reaches the last page
  3. less: Displays files in pages
    • You can flip up, you can flip down
    • Space: Scroll down
    • B: Turn the page up
    • Q: quit
    • Obviously, less loads files into memory in order to scroll up and down, and if the files are too large to fit into memory, there will be text problems
  4. head: Displays the first ten lines of the file
    • The first ten lines of the file are displayed by default
    • -number: displays the first number line of the file
      • -2: displays the first two lines of a file
  5. tail: Displays the last ten lines of the file
    • The last ten lines of the file are displayed by default
    • As above, you can customize the display of several lines
    • -f: Displays the content just appended to the file
    // At this point, the command line will pause // If abc.log is dynamically added in another window, the content will be displayed in the suspended window // LLDB. For example, when running Hadoop, you can use this command to display any errors. Tail -f abc.logCopy the code
  6. |: pipe command
    • Pass the previous command to a command as standard output
    The first three lines of the / / show b.t xt cat b.t xt | head - 3 / / display files line 5 head - 5 b.t xt | tail - 1Copy the code
  7. xargs:build and execute command lines from standard input
    • Take the standard output of the previous command as an argument to the latter
    // The current directory is the root home directory // The contents of the root directory will not be printed if xargs is not added. // Xargs passes/as a parameter to the ls command. [root@node01 ~]# echo "/" | xargs ls -ltotal 90 dr-xr-xr-x. 2 root root 4096 Jul 5 18:16 bin dr-xr-xr-x. 5 root root 1024 Jul 5 18:17 boot drwxr-xr-x. 18 root root 3700 Jul 11 18:40 dev drwxr-xr-x. 61 root root 4096 Jul 11 18:40 etc drwxr-xr-x. 2 root root 4096 Sep 23 2011 home dr-xr-xr-x. 8 root root 4096 Jul 5 18:16 lib dr-xr-xr-x. 9 root root 12288 Jul 5 18:17 lib64 drwx------. 2 root root 16384 Jul 5 18:15 lost+found drwxr-xr-x. 2 root root 4096 Sep 23 2011 media drwxr-xr-x. 2 root root 4096 Sep 23 2011 mnt  drwxr-xr-x. 2 root root 4096 Sep 23 2011 opt dr-xr-xr-x. 85 root root 0 Jul 11 18:40 proc dr-xr-x---. 7 root root 4096 Jul 12 05:39 root dr-xr-xr-x. 2 root root 12288 Jul 5 18:17 sbin drwxr-xr-x. 7 root root 0 Jul 11 18:40 selinux drwxr-xr-x. 2 root root 4096 Sep 23 2011 srv drwxr-xr-x. 13 root root 0 Jul 11 18:40 sys drwxrwxrwt. 3 root root 4096 Jul 12 05:43 tmp drwxr-xr-x. 13 root root 4096 Jul 5 18:16 usr drwxr-xr-x. 17 root root 4096 Jul 5 18:16 varCopy the code