Linux Practical Operation
- Linux (Practical Part 1)
-
- 1. Commonly used basic commands
-
- 1.1 Help commands
- 1.2 File directory class
-
- 1.2.1 pwd displays the absolute path of the current working directory
- 1.2.2 ls lists the contents of a directory
- 1.2.3 cd to switch directories
- 1.2.4 mkdir creates a new directory
- 1.2.5 rmdir deletes an empty directory
- 1.2.6 touch creates empty file
- 1.2.7 cp copy files or directories
- 1.2.8 rm deletes files or directories
- 1.2.9 mv moves or renames files and directories
- 1.2.10 cat to view file content
- 1.2.11 more file content split screen viewer
- 1.2.12 less displays file contents in split screen
- 1.2.13 echo
- 1.2.14 head displays the file header content
- 1.2.15 tail outputs the content at the end of the file
- 1.2.16 \> Output Redirection and >> Append
- 1.2.17 ln soft link
- 1.2.18 history View historical commands that have been executed
Linux (Practical Part 1)
1. Commonly used basic commands
Shell can be regarded as a command interpreter, providing us with an interactive text console interface. We can enter commands through the terminal console, which are interpreted by the shell and finally handed over to the kernel for execution.
1.1 Help commands
1.1.1 man to get help information
-
basic grammar
man [command or configuration file]Function description: Get help information
-
show description
- NAME: Name and one-line description of the command
- SYNOPSIS: How to use commands
- DESCRIPTION: In-depth discussion of command functionality
- EXAMPLES: Examples of how to use the command
- SEE ALSO: Related topics (usually man pages)
-
Practical examples
man ls View help information for the ls command
1.1.2 help Get help information for shell built-in commands
Some system commands with basic functions are directly embedded in the shell., it will be loaded together with the shell after the system is loaded and started, and will reside in the system memory. These commands are called "built-in commands"; the corresponding other commands are called "external commands".
Availabletype commandTo determine whether the command is an embedded command
[guozihan@hadoop100 ~]$ type cd
cd is shell embedded
-
basic grammar
help commandFunction description: Get help information for shell built-in commands
-
Practical examples
help cd View help information for the cd command
1.1.3 Commonly used shortcut keys
ctrl + c Stop process
ctrl+l Clearing the screen is equivalent to clear; completely clearing the screen is: reset
Good at using the tab keyTips (more importantly, it can prevent typos)
Up and down keysFind executed commands
1.2 File directory class
1.2.1 pwd displays the absolute path of the current working directory
pwd:print working directory print working directory
-
basic grammar
pwd (Function description: Display the absolute path of the current working directory)
-
Practical examples
Display the absolute path of the current working directory
[guozihan@hadoop100 ~]$ pwd
/home/guozihan
1.2.2 ls lists the contents of a directory
ls:list lists directory contents
-
basic grammar
ls [options] [directory or file]
-
Option description
- -a: List all files, together with hidden files (files starting with .) (commonly used)
- -l: Long data string list, including file attributes and permissions, etc.; (commonly used) is equivalent to "ll"
-
show description
The information listed on each line is:File type and permission link number File owner File group File size Use bytes to represent the time of creation or last modification Name
-
Practical examples
View all content information of the current directory
1.2.3 cd to switch directories
cd:Change Directory switch path
-
basic grammar
cd [parameter]
-
Parameter Description
cd absolute pathswitch path
cd relative pathswitch path
cd ~ or cdReturn to your home directory
cd - Return to the last directory
cd … Return to the directory one level above the current directory
cd -P Jump to actual physical path, not shortcut path
1.2.4 mkdir creates a new directory
mkdir:Make directory Create directory
-
basic grammar
mkdir [options] Directory to create
-
Option description
-p Create multi-level directories
-
Practical examples
Create a directory
[root@hadoop101 ~]# mkdir xiyou
[root@hadoop101 ~]# mkdir xiyou/mingji
Create a multi-level directory
[root@hadoop101 ~]# mkdir -p xiyou/dssz/meihouwang
1.2.5 rmdir deletes an empty directory
rmdir:Remove directory remove directory
-
basic grammar
rmdir The empty directory to be deleted
-
Case practice
Delete an empty folder
[root@hadoop101 ~]# rmdir xiyou/dssz/meihouwang
If you want to delete a multi-level directory, delete it layer by layer from the inside out!
1.2.6 touch creates empty file
-
basic grammar
touch file name
-
Practical examples
[guozihan@hadoop100 desktop]$ touch a.txt
1.2.7 cp copy files or directories
-
basic grammar
cp [option] source destFunction description: Copy source files to dest
-
Option description
-r Copy entire folder recursively
-
Parameter Description
- source source file
- dest object file
-
Practical examples
Copy files
[root@hadoop100 desktop]# cp a.txt /home/
Copy entire folder recursively
[guozihan@hadoop100 desktop]$ mkdir a/b/c.txt
[guozihan@hadoop100 桡面]$ cp -ra /home/guozihan
1.2.8 rm deletes files or directories
-
basic grammar
rm [options] deleteFileFunction description: Recursively delete all contents in the directory
-
Option description
- -r: Recursively delete all contents in the directory
- -f: Force the deletion without prompting for confirmation
- -v: Display the detailed execution process of the command
-
Case practice
Delete the contents of a directory
[guozihan@hadoop100 desktop]$ rm test
Recursively delete all contents in a directory
[guozihan@hadoop100 desktop]$ rm -rf a
1.2.9 mv moves or renames files and directories
-
basic grammar
mv oldNameFile newNameFile Function description: Rename
mv /temp/movefile /targetFolder Function description: Move files
-
Case practice
double naming
[guozihan@hadoop100 desktop]$ touch test.txt
[guozihan@hadoop100 desktop]$ mv test.txt a.txt
Move files
[guozihan@hadoop100 desktop]$ mv a.txt /home/guozihan
1.2.10 cat to view file content
View the file contents, starting from the first line
-
basic grammar
cat [options] file to view
-
Option description
-n Display line numbers for all lines, including blank lines
-
Practical examples
View file contents and display line numbers
[guozihan@hadoop100 桌面]$ cat -n a.txt
1 test
2 test
3 test
4 test
5 test
6 test
7 test
8 test
9 test
1.2.11 more file content split screen viewer
The more command is a VI editor-basedtext filter, which displays the contents of a text file page by page in full screen mode. There are several shortcut keys built into the more command. Please refer to the operating instructions for details.
-
basic grammar
more files to view
-
Instructions
- space keyRepresents turning down one page
- Enter Represents scrolling down "one line"
- q The representative leaves more immediately and no longer displays the contents of the file.
- Ctrl+F Scroll down one screen
- Ctrl+B Return to previous screen
- = Output the line number of the current line
- :f Output file name and line number of current line
-
Case practice
Use more to view files
[guozihan@hadoop100 desktop]$ more a.txt
1.2.12 less displays file contents in split screen
The less command is used to view file contents in split screen. Its function is similar to the more command, but it is more powerful and supports various display terminals.When the less command displays the content of a file, it does not load the entire file at once, but loads the content according to the display needs, which is more efficient for displaying large files.
-
basic grammar
less file to view
-
Instructions
- space keyScroll down a page
- [pagedown] Scroll down a page
- [shut up]Scroll up a page
- /stringThe function of searching "string" downwards; n: search downwards; N: search upwards
- ?StringFunction to search "string" upward; n: search upward; N: search downward
- qleave less
-
Case practice
Use less to view files
[guozihan@hadoop100 desktop]$ less a.txt
1.2.13 echo
echo outputs content to the console
-
basic grammar
echo [options] [output content]
Options:
-e: Supports character conversion controlled by backslash
-
Special characters
- \\ output\self
- \n newline character
- \t Tab character, also known as Tab key
-
Case practice
[guozihan@hadoop100 desktop]$ echo “hello\tworld”
hello\tworld[guozihan@hadoop100 desktop]$ echo -e “hello\tworld”
hello world
1.2.14 head displays the file header content
head is used to display the beginning of the file,By default, the head command displays the first 10 lines of the file.
-
Basic usage
head fileFunction description: View the first 10 lines of the file
head -n 5 filesFunction description: View the first 5 lines of the file, 5 can be any number of lines
-
Option description
-n<number of lines>Specify the number of lines to display header content
-
Practical examples
View the first 2 lines of the file
[guozihan@hadoop100 desktop]$ head -n2 a.txt
test
test
1.2.15 tail outputs the content at the end of the file
tail is used to output the content at the end of the file,By default, the tail command displays the last 10 lines of the file.
-
Basic usage
tail fileFunction description: View the content of the last 10 lines of the file
tail -n 5 filesFunction description: View the 5 lines at the end of the file, 5 can be any number of lines
tail -f fileFunction description: Track all updates to this document in real time
-
Option description
- -n<number of lines>Output n lines at the end of the file
- -f Display the latest added content of the file and monitor file changes
-
Practical examples
View the content of the last line of the file
[guozihan@hadoop100 desktop]$ tail -n 1 a.txt
testTrack all updates to this file in real time
[guozihan@hadoop100 desktop]$ tail -f a.txt
1.2.16 > Output Redirection and >> Append
-
basic grammar
ls -l > fileFunction description: Write the contents of the list to a file (overwrite)
ls -al >> fileFunction description: Append the contents of the list to the end of the file
cat file 1 > file 2Function description: Overwrite the contents of file 1 to file 2
echo "content" >> fileFunction description: Append content to the end of the file
-
Case practice
Write ls view information to file
[guozihan@hadoop100 desktop]$ ls -l>a.txt
Append ls view information to file
[guozihan@hadoop100 desktop]$ ls -l>>a.txt
Use echo to append the hello word to the file
[guozihan@hadoop100 desktop]$ echo hello>>a.txt
1.2.17 ln soft link
Soft links are also called symbolic links, similar to shortcuts in Windows.Has its own data block, mainly stores the paths linking to other files
-
basic grammar
ln -s [original file or directory] [soft link name]Function description: Create a soft link to the original file
-
Practical examples
Create a soft link
[root@hadoop101 ~]# ln -s xiyou/dssz/houge.txt ./houzi
Delete the soft link (be careful not to write the last /)
[root@hadoop101 ~]# rm -rf houzi
Enter the actual physical path of the soft connection
[root@hadoop101 ~]# ln -s xiyou/dssz/ ./dssz
[root@hadoop101 ~]# cd -P dssz/
1.2.18 history View historical commands that have been executed
-
basic grammar
history Function description: View historical commands that have been executed
-
Case practice
View historical commands that have been executed
[guozihan@hadoop100 desktop]$ history