[Linux system installation and use of common commands]

[Linux] System installation and use of common commands

1. Understanding Linux system

Linux manages memory without partitioning.

1. System introduction

1. Kernel version

  • Open source distribution version: cloud server deployment system, Ubuntu and CentOS are the most popular ones on the market ;
    Insert image description here
  • Non-open source version, iOS, Android

2. Systematic genealogy

Insert image description here

3. Systems supported by the Linux kernel

Insert image description here

4. Server market share of Linux systems

(2016)
Insert image description here

  • More than 90% of the world's 500 fastest supercomputers run Linux distributions or variants, including the top 10 fastest supercomputers, all operating systems based on the Linux kernel.
  • Linux is also widely used in embedded systems, mobile phones, tablets, routers, TVs, game consoles, etc., including iOS and Android systems, which are based on the Linux kernel.

5. Advantages of Linux

  • 1. Open source is free, can be modified by yourself, and has good compatibility with other open source software.
  • 2. Multi-user access is friendly, and permission management is convenient and fast.
  • 3. Excellent memory management, can run continuously for a long time, and the system occupies low memory
  • 4. Complete tool function library, easy to deploy and install

2. Install Linux on a virtual machine under Windows

  • Using the virtual machine that comes with win10 is convenient, fast and takes up little space

1. Turn on developer mode

Insert image description here

2. Enable subsystem functions

  • Turn on Turn Windows features on or off, check Windows Subsystem for Linux, and confirm. Restart later.
    Insert image description here

3. Download and install Ubuntu

  • Open the Microsoft Store, search for Ubuntu, get the installation, LTS long-term support version
    Insert image description here
  • After the download and installation is complete, open:
    Insert image description here

3. Common Linux commands

0, basic commands

sudo , elevated privileges

clear , clear the screen

pwd , displays the current directory path

> , overwrite the output of the command on the left to the file or command on the right. If the file on the right does not exist, create one

>> , append the output of the command on the left to the file or command on the right. If the file on the right does not exist, create one

chmod, modify attribute permissions, 6777: full permissions (octal), 110: super permissions/reorganization (6), 111: user's read and write execution (7), eg:

1. ls command—traverse

ls is the abbreviation of list . Its function is to list the files and folders in the specified location. If not specified, the files or folders in the current folder will be defaulted.
Commonly used parameters are:

-a , list all files or folders

  • You can view all files including hidden files or folders (files or folders starting with . are generally considered hidden by default)
    Insert image description here

-l , list details

  • By default, ls only displays the name. After adding this parameter, it will display the file permissions, user, group, size, modification date, etc.
    Insert image description here

-h , increase readability

  • The default file is displayed in bytes. Adding this parameter will be accompanied by size suffixes such as K, M, G, T, etc. K: Kilobytes, M: Megabytes, T: 1024G
    Insert image description here

-R , recursive access

  • If there are other folders in the current directory, the files and folders in these folders will also be displayed.

-Q , the file name is wrapped in double quotes

  • This parameter is used to prevent some files or folders from ending with a space character. You can use double quotes to see the actual length of the file name.
    Insert image description here

2. echo command—display string

  • display string,
    Insert image description here

Display escape characters, eg: echo ", or '`

Insert image description here
Insert image description here

Display variables, echo $PATH: display environment variables

Insert image description here

Display line break/no line break, echo -e "\n": line break, echo -e "\c": no line break

Insert image description here

Display the string as it is, echo "$PATH"

Display command results, echodate

Insert image description here
Insert image description here

3. cd command—target path

cd target path (change directory)

~ : Represents the user directory of the current user

  • Under ordinary users: usually the /home/username folder; under root users: the corresponding /root folder.

. : A dot represents the current directory.

. . : Two dots represent the upper-level directory.

  • cd . ./. .

4. head command—file header

-cn , displays the specified n characters of the header.

Insert image description here

-nx , displays the specified first x rows of data in the header.

-v , display file name

Insert image description here

-q, do not display file names, default.

Traverse files in the specified format. eg: ls*.txt

Insert image description here

Traverse files that do not specify a character. eg: ls jso?.txt

Insert image description here

5. tail command—end of file

-c displays the contents of the specified bytes at the end

-n, displays the content of the specified number of lines at the end of a file.

-v display file name

-q, do not display file names, default.

-f, you can continuously update the tail content of a file.

6. ps command—display processes started under the current user

-Al displays details and process names of all processes

-aux displays details of all processes and their startup commands

  • All processes are children of the init process
    Insert image description here

Description of process value items:

  • USER, the user to whom the process belongs
  • UID, the user ID to which the process belongs. When it is 0, it represents the root user with the highest authority.
  • PID, process ID
  • PPID, parent process ID
  • PRI, the lower the priority value, the higher the priority, and it can even be a negative number.
  • %CPU, CPU usage
  • %MEM, memory usage
  • VSZ, virtual memory footprint (part of which may be in the swap file)
  • RSS, actual memory usage (size occupied by RAM)
  • TTY, the corresponding console device
  • TIME, the time when the process is executed
  • START, the time when the process starts execution
  • COMMAND, the command used to start the process, process name (can take parameters)
  • CMD, the command used to start the process, process name (without parameters)
  • S/STAT, status: S sleep, R running, D blocked, Z zombie process, T suspended

7. cp command—copy

(copy copy command)
Command usage: cp [parameter] source file/folder target file/folder,
[] means optional, available or not

-a copy with attributes

  • This option is typically used when copying a directory, retaining links, file attributes, and copying all content under the directory. The effect is equal to the dpr parameter combination.

-d preserve links when copying

-p copy with permissions

  • In addition to copying the file contents, the modification time and access permissions are also copied to the new file.

-r folder copy

  • If the given source file is a directory file, the subdirectories and files in the directory will be copied.

-f forces coverage

  • Overwrite an existing target file without giving a prompt

-i override prompt

  • Give a prompt before overwriting the target file, asking the user to confirm whether to overwrite.

-l create link

  • No files are copied, only linked files are generated.
  • It only works on some systems and has no effect on Ubuntu.

8. rm command—delete

removedelete

-i Delete confirmation

-f force deletion

-r directory delete

4. Common Linux commands (from the Internet):

pwd command

Use the pwd command to find the path to your current working directory (folder). This command will return an absolute (full) path, which is basically the path to all directories starting with /. An example of an absolute path is /home/username.

cd command

To browse Linux files and directories, use the cd command. Depending on the current working directory you are in, it requires the full path or name of the directory. Suppose you are in /home/username/Documents and want to go to the Photos subdirectory of Documents. To do this, just type the following command: cd Photos. Another case is if you want to switch to a completely new directory, such as /home/username/Movies. In this case you have to enter cd followed by the absolute path to the directory: cd /home/username/Movies. There are some shortcuts to help you navigate quickly: cd ... (with two dots) moves one directory up cd goes directly to the home folder cd- (with hyphen) moves to the previous directory As a side note, the shell for Linux It is case sensitive. Therefore, you must enter the name of the directory exactly.

ls command

The LS command is used to view the contents of a directory. By default, this command will display the contents of the current working directory. If you want to view the contents of another directory, type ls followed by the path to the directory. For example, enter ls /home/username/documents to view the contents of the file. You can use the following variations of the ls command: ls -R will also list all files in subdirectories ls -a will show hidden files ls -al will list files and directories with details like permissions, size, all Those who wait.

cat command

cat (short for connect) is one of the most commonly used commands in Linux. It is used to list the contents of a file on standard output (sdout). To run this command, type cat followed by the file name and its extension. For example: cat file.txt. Here are other ways to use the cat command: cat> filename Create a new file cat filename1 filename2> filename3 Concatenate two files (1 and 2) and store their output in a new file (3) Convert the files to uppercase or Use lowercase, cat filename | tr az AZ >output.txt

cp command

Use the cp command to copy files from the current directory to another directory. For example, the command cp scenery.jpg/home /username/ Pictures will create a copy of Scene.jpg (from the current directory) in your Pictures directory.

mv command

The main use of the mv command is to move files, although it can also be used to rename files. The parameters in mv are similar to the cp command. You need to enter mv, filename and target directory. For example: mv file.txt/home /username/ Documents.

mkdir command—create directories/folders

Use the mkdir command to create a new directory - if you type mkdir Music, it will create a directory called Music. There are some additional mkdir commands: To generate a new directory within another directory, use this Linux basic command mkdir Music / Newfile Create a directory between two existing directories using the p (parent) option. For example, mkdir -p Music/2022/Newfile will create a new "2022" file.

rmdir command

If you need to delete a directory, use the rmdir command. However, rmdir only allows you to delete empty directories.

rm command

This RM command deletes a directory and its contents. If you just want to delete a directory (as an alternative to rmdir), use rm -r. Note: Be extremely careful when using this command and double check the directory you are in. This will delete everything and there is no undo.

touch command

This touch command allows you to create new blank files via the Linux command line. For example, enter touch /home/username/Documents/Web.html to create an HTML file named Web in the Documents directory.

locate command

You can use this command to locate files just like the search command in Windows. Additionally, using the -i parameter with the command will make it case-insensitive, so you can search for a file even if you don't remember its exact name. To search for files containing two or more words, use the asterisk (*). For example, the locate -i school * note command will search for any file containing the words "school" and "note", regardless of whether it is uppercase or lowercase.

find command

In similar locate commands, use Find to also search files and directories. The difference is that you can use the find command to find files in a given directory. For example, the find /home/-name notes.txt command searches the home directory and its subdirectories for a file named notes.txt. Other variations when using find are: To find files used in the current directory, use find . -name notes.txt To find a directory, use /-type d -name notes.txt13. The grep command is undoubtedly useful for daily use Another basic Linux command that helps is grep. It allows you to search all text in a given file. To illustrate this point, grep blue notepad.txt will search the Notepad file for the word blue. Lines containing the searched word will be displayed in full.

sudo command

This command is short for "SuperUser Do" and enables you to perform tasks that require administrative or superuser privileges. However, it is recommended not to use this command for daily use as errors can easily occur if you do something wrong.

df command

Use the df command to get a report on your system's disk space usage in percent and KB. If you want to view the report in megabytes, enter df -m.

command

If you want to check how much space a file or directory is taking up, the answer is the du (disk usage) command. However, the disk usage summary will show disk block numbers instead of the usual size format. If you want to view it in bytes, kilobytes and megabytes, add the -h parameter to the command line.

head command

The header command is used to view the first line of any text file. By default it will display the first ten lines, but you can change this number to your liking. For example, if you only want to display the first five lines, type head -n 5 filename.ext.

tail command

This command has similar functionality to the head command, but the tail command displays the last ten lines of the text file instead of the first line. For example, tail -n filename.ext.

diff command

The diff command is the abbreviation of difference. The diff command compares the contents of two files line by line. After parsing the file, it will output the non-matching lines. Programmers often use this command when they need to make program changes instead of rewriting the entire source code. The simplest form of this command is diff file1.ext file2.ext

tar command

The tar command is the most commonly used command to archive multiple files into a compressed archive. Similar to the zip format, a common Linux file format, compression is optional. The command has a long list of functions and is very complex, such as adding new files to existing archives, listing archive contents, extracting contents from archives, and more. Check out some real-world examples to learn more about additional features.

chmod command

chmod is another Linux command used to change the read, write and execute permissions of files and directories. Since this command is quite complex, you can read the complete tutorial to execute it correctly.

chown command

In Linux, all files are owned by a specific user. The CHOWN command enables you to change or transfer ownership of a file to a specified username. For example, chown linuxuser2 file.ext will make linuxuser2 the owner of file.ext.

Jobs command

The jobs command will display all current jobs and their status. A job is basically a process started by the shell.

kill command

If your program becomes unresponsive, you can kill it manually using the kill command. It will send a specific signal to an application that is behaving abnormally and instruct the application to terminate itself. You can use a total of 64 signals, but people usually only use two signals: SIGTERM (15) — Requests the program to stop running and give it some time to save all its progress. This signal will be used if no signal is specified when the kill command is entered. SIGKILL(9) - Forces the program to stop immediately. Unsaved progress will be lost. In addition to knowing the signal, you also need to know the process identification number (PID) of the program you want to kill. If you don't know the PID, just run the command ps ux. After you know what signal you want to use and the PID of your program, enter the following syntax: kill [signal option] PID.

ping command

Use the ping command to check the connection status with the server. For example, just type ping google.com and the command will check if you can connect to Google and measure the response time.

wget command

The Linux command line is very useful - you can even download files from the Internet with the help of wget command. To do this, just type wget followed by the download link.

uname command

The UNAME command, short for Unix name, will print details about your Linux system, such as computer name, operating system, kernel, etc.

top command

As the terminal equivalent of Task Manager in Windows, the top command displays a list of running processes and the amount of CPU used by each process. Monitoring system resource usage is very useful, especially knowing which process needs to be terminated because it is consuming too many resources.

history command

When you use Linux for a while, you'll quickly notice that you can run hundreds of commands every day. Therefore, the run history command is particularly useful if you want to see previously entered commands.

man command

Confused about what certain Linux commands do? Don't worry, you can easily learn how to use them from the Linux shell using the man command. For example, entering man tail displays manual instructions for the tail command.

echo command

This command is used to move some data into a file. For example, if you want to add the text "Hello, my name is John" to a file named name.txt, you would type echo Hello, my name is John >> name.txt

zip, unzip commands

Use the zip command to compress the files into a zip archive, and then use the unzip command to extract the compressed files from the zip archive.

hostname command

If you want to know the name of the host/network, just type hostname. Adding -I at the end will display the IP address of your network.

useradd, userdel commands

Since Linux is a multi-user system, this means that multiple people can interact with the same system at the same time. useradd is used to create a new user, while passwd adds a password to that user's account. To add a new user named John, add user John and then add his password type passwd 123456789. Deleting a user is very similar to adding a new user. To delete a user account type, use userdel UserName.

Guess you like

Origin blog.csdn.net/MOON_YZM/article/details/130751497