Linux learning basic commands

Linux learning basic commands

table of Contents

Linux learning basic commands

Internal and external commands

The usage format of the general command line

Auxiliary operation

How to get command help

Internal command help

Use the man command to read the man page

Press "\" key to find content

View the current working directory-pwd

path

Relative path expression

List the contents of the directory-ls

Set alias-alias

du - Count the size of the disk space occupied by the specified directory or file

Create a new directory mkdir

Create an empty document touch

Create a link file -ln

Copy files or directories-cp

Delete files or directories-rm

Move files or directories—mv

Find the command/file storage directory—which

find Find files and directories

Use the find command to achieve multiple search conditions

exec usage of find

Priority of command execution

View the contents of the file cat command

View file content more command


Internal and external commands

 

The usage format of the general command line

Command word: It is the key part of the whole command and only determines a command

Options: short format option"-"to guide long format option"–"symbol to guide

parameter

Linux commands are case sensitive

Auxiliary operation

How to get command help

Internal command help


View the help information of Shell internal commands. The "–help" option of the command is
suitable for most Linux external commands

Use the man command to read the man page


Use the ENTER arrow keys to scroll a line of text
Use the Page Up and Page Down (space) keys to turn pages
Press the Q or q key to exit the reading environment

Press "\" key to find content

View the current working directory-pwd

cd target location

cd ~

cd cut to the current user's home directory

cd-switch to the directory where the cd command was executed before

path

Absolute path: full path

Relative path: starting from the current path to the target path

Relative path expression

List the contents of the directory-ls

Set alias-alias

du - Count the size of the disk space occupied by the specified directory or file

du-ah counts all files in the disk'

du-sh

du-a count all files

du-h counted in kb'

Total space occupied by du-s statistics

Create a new directory mkdir

mkdir -p creates multiple directories at once

Create an empty document touch

Time stamp of update file

Often used to create multiple new empty files
touch a-the /root/a home directory

touch /a-/a root directory

Create a link file -ln

Create a link file for a file-based directory, similar to the shortcut of the Windows system.
Link file type.
Soft link (also called symbolic link) creates an access shortcut and deletes the source file. Link failure.
Hard link: When creating a link, a file will be created and deleted Source files have no effect on hard links

Copy files or directories-cp

Rebuild a copy of the file or directory (source) that needs to be copied and save it as a new file or directory

cp …source file or directory…target file or directory
Commonly used option
-f: when overwriting target file or directory with the same name, without warning, copy directly

-i: remind the user to sort when overwriting the target file or directory with the same name

-p: Keep the permissions of the source file when copying, the attributes such as the owner and time stamp are unchanged

-r: This option must be used when copying directories, which means that all files and subdirectories are recursively copied

Delete files or directories-rm

Delete the specified file or directory
Common options
-f silent

-i prompt

-r include subdirectories

Move files or directories—mv

Move the specified file or directory to the location

If the target location is the same as the source location, it is equivalent to performing a rename operation

Find the command/file storage directory—which

The environment variable PATH in the search scope is determined

which command/program name

or

which -a command/program name

which ls

which cd

find Find files and directories

Recursively, according to the target name, type, size and other different attributes for fine search

find [Search range] [Search condition expression]

Search by name: -name searches based on the target name, allowing the use of "*" and "?" wildcards

Search by file size: -size Search by file size generally use "+" and "-" settings as search conditions

Search by file owner: -user Search according to whether the file belongs to the target user

Search by file type: -type Search according to file type, including ordinary file (f) directory (d), block device file (b), character device file (c), etc.

Use the find command to achieve multiple search conditions

Use logical operator
"-a" between expressions to indicate and (and)
"-o" to indicate or (or) example
find /boot -size +1024k -a -name "vmlinuz*""
find lboot -size +1024k -o -name "vmlinuz*""

exec usage of find

The -exec parameter is followed by the Linux command, which is ended with a semicolon ";". Since the semicolon has different meanings in various systems, the backslash escape character "\" is added in front of the semicolon. .
{} represents the file name found by the previous find.
The find command matches all the ordinary files in the current directory, and uses the ls -l command in the -exec option to list them
find ./ -type f -exec ls-l {};

Priority of command execution

First priority: the command to specify the path. Absolute path /root/pwd.sh or relative path. /pwd.sh
/usr/bin/cpcd /usr/bin./cp
Second priority: the command specified by the alias alias pwd=/root/pwd.sh
third priority Level: Internal command
Fourth priority: Hash command
There will be a hash table in the linux system. When you first boot this hash table is empty. Whenever you execute a command, the hash table will record the path of this command. , It is equivalent to the cache. The first time the command is executed, the she11 interpreter will find the path of the command from the PATH path by default. When you use the command for the second time, the shell interpreter will first check the hash table, and will go to the PATH path without this command. . The hash table can increase the call rate of commands.
Fifth priority: Search through the search order defined by PATH.
If none of the above order is found, it will report "Command not found..." error.

View the contents of the file cat command

cat see
the common options of simple files cat
-n: number all output lines
-b: not number blank lines
-s: replace all consecutive blank lines with one blank line

View file content more command

Full screen mode to display the contents of the file in pages
more[options]file name...

Interactive operation method

Press Enter to scroll down one line

Press the space bar to scroll down one page
ctrl+b to return to the previous screen
ctrl+f to scroll down one screen
press the q key to exit When
combined with pipe operations (for example: ls -R/etc | more), the page cannot be turned up

Guess you like

Origin blog.csdn.net/Alen686/article/details/113667438