Linux file commands (all)

1 New

mkdir 文件夹名称: Create a new folder
mkdir -p /目录/文件夹名称: Automatically create a superior if there is no superior
touch /路径/文件名: Create a file under the specified path

2 views

2.1 Directory view

ls 目录名: Display the files in the specified directory
ls -l 目录名: Display the files in the specified path in list form
ll 目录名: Display the files in the specified path in list form
cd 路径: Enter the specified path
pwd: Display the current path
du -h 路径/文件名: Display the file size in units

2.2 File viewing

stat 路径/文件名: View file details
file 路径/文件名: View file type
cat 文件名 : Display all file contents at one time
cat -n 文件名: Display all file contents at one time, with line numbers
more 文件名: Display file contents in split screen, only one page is displayed at a time

空格键: Display the next screen
Enter键: Scroll one line at a time
b: Scroll back one screen
f: Scroll forward one screen
q: Exit

less 文件名: View file contents

空格键: Display the next screen
Enter键: Scroll one line at a time
b: Scroll back one screen
f: Scroll forward one screen
q: Exit
上下箭头: Scroll up and down line by line
PageDown/PageUp: Scroll up and down page by page

grep [选项] [文件] : Perform a keyword search in text and display matching results

-n: Show matching lines and line numbers
-v: Show all lines that do not contain matching text
-i: Ignore case
-c: Show only the number of lines found

tail [选项] [文件]: View the last N lines of the file or continuously refresh the content
tail -n 10 文件名: View the last 10 lines of the file content
tail -f 文件名: View the latest content of the file in real time
head -n 10 文件名: View the first 10 lines of the file
diff --brief 文件1 文件2: Compare whether two files are the same
diff -c 文件1 文件2: Compare the differences between two files

3 Delete/Move/Copy

rm -rf 路径/文件名: Forced deletion of folders/files
rm -f 路径/文件名 : Forced deletion of files, folders cannot be deleted
mv 源文件的路径 目标文件路径: Move source file to destination file
mv 源文件路径 目标路径/名字 : Move source file to destination file and rename
mv -i 文件名 目标文件目录: When moving, prompt before overwriting the file
cp 源文件 目标文件: Copy source file to destination directory , folders cannot be copied
cp -r 源文件 目标文件: If the source file is a folder, all subdirectories under the directory will be copied.

4 File assignment permissions

chmod {u|g|o|a}{+|-|=}{r|w|x} filename

u (user)Represents the user himself.
g (group)Indicates users in the same group.
o (oher)Represents other users.
a (all)Represents all users.
+Used to grant permissions to specified users.
-Used to cancel the permission of a specified user.
=Grant the permitted permissions to the file.
r (read) 【4】Read permission means that the contents of the file or directory can be copied.
w (write) 【2】Write permission means that the contents of the file or directory can be modified.
x (execute)【1】Execution permission means that the file can be executed or the directory can be entered.

chmod -R u+x /test: Add executable permissions to all files in the folder
chmod 777 文件夹: Add all permissions to the folder

Guess you like

Origin blog.csdn.net/qq_41943900/article/details/129138163