content
mkdir create directory command
rmdir delete directory command
touch create empty file command
>overwrite directive and >>append directive
historyView historical command commands
file directory class
pwd show file path directive
Basic syntax: pwd (function description: display the absolute path of the current working directory, the absolute path starts from the root directory )
Example:
The first slash indicates the root directory
ls view file command
Basic syntax: ls [options] [directory or file]
Common options
-a: Display all files and directories in the current directory, including hidden files
-l: Display information as a list
Example: View all information in a directory
cd into the file command
Basic syntax: cd parameter (function description: switch to the specified directory)
Understanding: Absolute and Relative Paths
cd ~ or cd : indicates returning to the home directory of bytes, such as user kongchao, using cd ~ will return to /home/kongchao, and root user cd ~ will return to /root
cd .. means go back to the previous directory of the current directory (the top directory is the root directory, so cd .. will only go to the root directory / at most)
Example:
Case 1: Use absolute path to switch to root directory (cd /root)
Case 2: Use a relative path to the /root directory. For example, the current location is /home/kongchao (cd ../../root, which is equivalent to returning two directories to the root directory and finally accessing root directly)
Case 3: Represents the upper-level directory of the current directory (cd ..)
Case 4: Go home directory (cd ~)
mkdir create directory command
mkdir instructs the user to create a directory
Basic syntax: mkdir [options] directory to create
Common options: -p Create multi-level directories
Example: Creating a Directory and Creating Multilevel Directories
rmdir delete directory command
The rmdir command deletes empty directories
Basic syntax: rmdir [options] Empty directory to delete (non-empty directories cannot be deleted)
rm -rf means recursive deletion (use with caution)
Such as: delete /home/Dog (no content under Dog) and delete Dog2, there is a smallDog file under Dog2 (rm -rf /home/Dog2)
touch create empty file command
touch command creates empty file
Basic syntax: touch filename
For example, create an empty folder hello.txt in the /home directory, (touch /home/hello.txt)
cp copy command
The cp command copies files to the specified directory
Basic syntax: cp [options] source dest
Common options -r: recursively copy the entire folder
Example: Copy hello.txt in text1 to text2
Recursively copy the entire folder without adding the following /hello.txt (cp -r text1/ text2) has reached the /home directory, if not, it should be written as cp -r /home/text1 text2
usage details
Force overwrite without prompting: \cp -r /home/text1 text2
[root@kongchao02 home]# ls
kongchao kongchao1 kongchao2 text1 text2
[root@kongchao02 home]# ls text1
hello1.txt hello.txt
[root@kongchao02 home]# ls text2
[root@kongchao02 home]# cp -r text1/hello.txt text2
[root@kongchao02 home]# ls text2
hello.txt
rm delete command
Description: The rm command removes a file or directory
Basic syntax: rm [options] file or directory to delete
Common options:
-r : delete the entire folder recursively
-f: Force delete without prompting
-i: remove prompt before
Example: delete text1 and text2
[root@kongchao02 home]# ls
kongchao kongchao1 kongchao2 text1 text2
[root@kongchao02 home]# ls text1
hello1.txt hello.txt
[root@kongchao02 home]# rm -rf text1/
[root@kongchao02 home]# ls
kongchao kongchao1 kongchao2 text2
[root@kongchao02 home]# rm -ri text2/
rm:是否进入目录"text2/"? y
rm:是否删除目录 "text2/hello.txt"?y
rm:是否删除目录 "text2/"?y
[root@kongchao02 home]# ls
kongchao kongchao1 kongchao2
-i prompt deletion is safer, but more cumbersome, -f forced deletion does not prompt, it is not safe to use with caution
mv move or rename instruction
mv is to move files and directories or rename
Basic syntax:
mv oldName newName (rename)
mv /temp/movefile /targetFolder (move file
Example 1 : Rename and move location
[root@kongchao02 home]# mkdir text1
[root@kongchao02 home]# mkdir text1/text2
[root@kongchao02 home]# ls
kongchao kongchao1 kongchao2 text1
[root@kongchao02 home]# mv text1 newNameText1
[root@kongchao02 home]# ls
kongchao kongchao1 kongchao2 newNameText1
[root@kongchao02 home]# ls newNameText1/
text2
[root@kongchao02 home]# mkdir text3
[root@kongchao02 home]# ls
kongchao kongchao1 kongchao2 newNameText1 text3
[root@kongchao02 home]# mv newNameText1 text3
[root@kongchao02 home]# ls
kongchao kongchao1 kongchao2 text3
[root@kongchao02 home]# ls text3
newNameText1
[root@kongchao02 home]# ls text3/newNameText1
text2
Rename under the same path, move location under different paths
Example 2: Move and give a new name
[root@kongchao02 home]# ls
kongchao kongchao1 kongchao2 text3
[root@kongchao02 home]# mv text3/newNameText1 /home/text4
[root@kongchao02 home]# ls
kongchao kongchao1 kongchao2 text3 text4
Move the entire directory: such as mv /home/text3 /temp
cat view file content command
cat to view file contents
Basic syntax: cat [options] file to view
Common options: -n : display line numbers
Example: see hello.java
[root@kongchao02 home]# vim hello.java
[root@kongchao02 home]# ls
hello.java kongchao kongchao1 kongchao2 text3 text4
[root@kongchao02 home]# cat -n hello.java
1 public class Hello{
2 public static void main (String[] args){
3 System.out.println("hello java");
4
5 }
6
7
8
9
10 }
Usage details : cat can only browse files, but cannot modify files (so cat is safe). For the convenience of browsing, the pipe command | more is usually used. The function is to hand over the query results to more for processing. exitmore
cat -n /etc/profile |more (interactive command)
If you press space to show more
more command
The more command is a text filter based on the vi editor. It displays the contents of the text file page by page in a full-screen manner. Several shortcut keys (interactive commands) are built into the more command.
Basic syntax: more file to view
The operation instructions are shown in the figure:
less view instructions
The less command is used to view the file content in split screen. Its function is similar to the more command, but it is more powerful than the more command and supports various display terminals. When the less command displays the file content, it does not display the entire file at one time, but displays the content that needs to be loaded, which is more efficient for displaying large files.
Basic syntax : less file to view
echo output command
echo output content to console
Basic syntax: echo [options] [output]
Example: Use the echo command to output environment variables and specified content
[root@kongchao02 ~]# echo $HOSTNAME
kongchao02
[root@kongchao02 ~]# echo "hello kongchao"
hello kongchao
[root@kongchao02 ~]#
head shows the head command
The head command is used to display the content at the beginning of the file. By default, the head command displays the first 10 lines of the file.
Basic syntax: head file (see the first 10 lines of the file)
head -n 15 file (view the first 15 lines of the file, which can be any number of lines)
Example: View the first 6 lines under /etc/profile
[root@kongchao02 ~]# head -n 6 /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
[root@kongchao02 ~]#
tail shows tail commands
tail is used to output the content at the end of the file. By default, tail displays the first 10 lines of the file.
Basic syntax:
tail file (view the last 10 lines of the file)
tail -n 5 files (view the 5 lines at the end of the file)
tail -f file (track all updates to the document in real time, and the file changes will be reported back)
[root@kongchao02 ~]# tail /etc/profile
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
[root@kongchao02 ~]# tail -n 5 /etc/profile
fi
done
unset i
unset -f pathmunge
[root@kongchao02 ~]#
>overwrite directive and >>append directive
> is to overwrite the original content, >> is to append to the original content
Basic syntax:
ls -l > file (the contents of the list are written to the file overwriting the original)
ls -al >> file (appends the contents of the list to the end of the file)
cat file 1 > file 2 (overwrite the contents of file 1 into file 2)
echo "content" >> file (append content to file)
Example 1: Write the list of files in the /home directory to /home/text.txt, overwrite (ls -l /home > /text.txt) if text.txt does not exist, it will be created automatically
[root@kongchao02 home]# ls -l /home
总用量 24
-rw-r--r--. 1 root root 107 3月 4 22:22 hello.java
drwx------. 15 kongchao kongchao 4096 3月 1 20:37 kongchao
drwx------. 5 kongchao1 kongchao1 4096 2月 28 22:08 kongchao1
drwx------. 3 kongchao2 kongchao2 4096 2月 28 22:11 kongchao2
drwxr-xr-x. 2 root root 4096 3月 3 21:44 text3
drwxr-xr-x. 3 root root 4096 3月 3 21:27 text4
[root@kongchao02 home]# ls -l /home > text.txt
[root@kongchao02 home]# ls /home
hello.java kongchao kongchao1 kongchao2 text3 text4 text.txt
[root@kongchao02 home]# cat /home/text.txt
总用量 24
-rw-r--r--. 1 root root 107 3月 4 22:22 hello.java
drwx------. 15 kongchao kongchao 4096 3月 1 20:37 kongchao
drwx------. 5 kongchao1 kongchao1 4096 2月 28 22:08 kongchao1
drwx------. 3 kongchao2 kongchao2 4096 2月 28 22:11 kongchao2
drwxr-xr-x. 2 root root 4096 3月 3 21:44 text3
drwxr-xr-x. 3 root root 4096 3月 3 21:27 text4
-rw-r--r--. 1 root root 0 3月 4 22:29 text.txt
[root@kongchao02 home]#
Example 2: Append I am kc to hello.java
[root@kongchao02 home]# cat /home/hello.java
public class Hello{
public static void main (String[] args){
System.out.println("hello java");
}
}
[root@kongchao02 home]# echo "I am kc" >> /home/hello.java
[root@kongchao02 home]# cat /home/hello.java
public class Hello{
public static void main (String[] args){
System.out.println("hello java");
}
}
I am kc
[root@kongchao02 home]#
Example 3: Overwrite the file
[root@kongchao02 home]# cd /home/
[root@kongchao02 home]# cat text.txt
总用量 24
-rw-r--r--. 1 root root 107 3月 4 22:22 hello.java
drwx------. 15 kongchao kongchao 4096 3月 1 20:37 kongchao
drwx------. 5 kongchao1 kongchao1 4096 2月 28 22:08 kongchao1
drwx------. 3 kongchao2 kongchao2 4096 2月 28 22:11 kongchao2
drwxr-xr-x. 2 root root 4096 3月 3 21:44 text3
drwxr-xr-x. 3 root root 4096 3月 3 21:27 text4
-rw-r--r--. 1 root root 0 3月 4 22:29 text.txt
[root@kongchao02 home]# cat hello.java > text.txt
[root@kongchao02 home]# cat text.txt
public class Hello{
public static void main (String[] args){
System.out.println("hello java");
}
}
I am kc
[root@kongchao02 home]#
current calendar display cal
[root@kongchao02 ~]# cal
三月 2022
日 一 二 三 四 五 六
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
[root@kongchao02 ~]#
ln symbolic link command
In soft link, also known as symbolic link, is similar to the shortcut in windows, which mainly stores the path to link other files
Basic syntax: ln -s [original file or directory] [soft link name] (create a soft link to the original file)
Example: Create a soft link myroot in the /home directory, linking to the /root directory
[root@kongchao02 ~]# ln -s /root /home/myroot
[root@kongchao02 ~]# ls /home
hello.txt kongchao kongchao1 kongchao2 myroot
[root@kongchao02 ~]# cd /home/myroot/
[root@kongchao02 myroot]# ls
anaconda-ks.cfg 公共 视频 文档 音乐
initial-setup-ks.cfg 模板 图片 下载 桌面
[root@kongchao02 myroot]# pwd
/home/myroot
[root@kongchao02 myroot]#
Details : When we use the pwd command to view the directory, we still see the directory where the soft link is located, not the directory it points to
remove soft link rm
rm soft link path
[root@kongchao02 myroot]# rm /home/myroot
rm:是否删除符号链接 "/home/myroot"?y
[root@kongchao02 myroot]# ls /home
hello.txt kongchao kongchao1 kongchao2
[root@kongchao02 myroot]#
historyView historical command commands
history View historical commands that have been executed, you can also execute historical commands
Basic syntax: history [number] (to see how many commands have been executed)
View all history commands: history
View 10 history commands: history 10
The command to execute the history number: !Number
Example 1: View the commands that have been commanded in history
[root@kongchao02 myroot]# history
1 gcc -v
2 ifconfig
3 reboot
4 ifconfig
5 cat /etc/passwd
6 useradd kongchao1
7 passwd kongchao1
8 su kongchao1
9 clear
10 ls
11 vim hello.v
12 vim /etc/passwd/
13 useradd kongchao2
14 passwd kongchao2
15 clear
16 cat /etc/passwd
17 clear
18 vim /etc/shadow
19 cat /etc/shadow
20 clear
21 cat /etc/group
22 clear
23 init 5
24 init 3
25 init 5
26 gcc- v
27 gcc -v
28 tree
29 ls /home/
30 ls
31 su kongchao
32 logout
33 ifconfig
34 vim clear
35 man ls
36 q
37 help cd
38 clear
39 ls /
40 cd /
41 ls
42 cd home
43 s
44 clear
45 cd /home
46 ls
47 cd kongchao
48 pwd
49 clear
50 ls -a
51 ls -al
52 ls a
53 man lc
54 manls
55 man ls
56 clear
57 ls -al
58 cd /home
59 ls
60 cd kongchao
61 cd/
62 cd /
63 clear
64 cd /home/kongchao
65 cd ~
66 pwd
67 ls -s /root /home/myroot
68 clear
69 ln -s /root /home/myroot
70 ls /home
71 cd /home/myroot/
72 ls
73 pwd
74 clear
75 ls /home/myroot/
76 clear
77 ls /home
78 rm /home/myroot/
79 clear
80 rm /home/myroot
81 ls /home
82 clear
83 history
Example 2: View the 10 instructions that have been instructed
[root@kongchao02 myroot]# history 10
75 ls /home/myroot/
76 clear
77 ls /home
78 rm /home/myroot/
79 clear
80 rm /home/myroot
81 ls /home
82 clear
83 history
84 history 10
Example 3: Instructions with corresponding labels
[root@kongchao02 myroot]# history 10
75 ls /home/myroot/
76 clear
77 ls /home
78 rm /home/myroot/
79 clear
80 rm /home/myroot
81 ls /home
82 clear
83 history
84 history 10
[root@kongchao02 myroot]# !77
ls /home
hello.txt kongchao kongchao1 kongchao2
[root@kongchao02 myroot]#