Home Operation and Maintenance Linux Operation and Maintenance Summary of commonly used commands in Linux (detailed)

Summary of commonly used commands in Linux (detailed)

Oct 19, 2018 pm 04:41 PM
linux

The content of this article is a summary (detailed) of commonly used commands in Linux. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

ls -alrtAFR

-a Display all files and directories (ls defaults to file names or directory names starting with "." as hidden files and will not be listed)
-l In addition to the file name, the file type, permissions, owner, file size and other information are also listed in detail
-r Display the files in reverse order (originally in English alphabetical order)
-t List the files in order of creation time
-A Same as -a, but do not list "." (current directory) and ".." (parent directory)
-F in the listed Add a symbol after the file name; for example, add "*" for executable files, and add "/" for directories
-R. If there are files in the directory, the following files will also be listed in sequence

touch -acfm-r--help[file or directory...]

is used to modify the time attributes of the file or directory, including access time and change time. If the file does not exist, the system will create a new file.

mkdir [-p] dirName

-p Make sure the directory name exists. If it does not exist, create one.
mkdir -p BBB/Test Create a subdirectory named Test in the BBB directory under the working directory. If the BBB directory does not exist originally, create one. (Note: If -p is not added in this example, and the original BBB directory does not exist, an error will occur.)

rm [options] name...

-i Ask for confirmation one by one before deleting .
-f Even if the original file attribute is set to read-only, it will be deleted directly without confirming one by one.
-r Delete the files in the directory and below one by one.

mv [options] source dest

-i: If there is already a file with the same name in the specified directory, first ask whether to overwrite the old file;
-f: To overwrite an existing file in the mv operation No instructions are given when there are some target files;
mv file name file name changes the source file name to the target file name
mv file name directory name moves the file to the target directory
mv directory name directory name the target directory has been If exists, move the source directory to the target directory; if the target directory does not exist, rename it
mv Directory name file name error

cp [options] source dest

-a: This option is usually in Used when copying a directory, it preserves links, file attributes, and copies all contents under the directory. Its effect is equivalent to the dpR parameter combination.
-d: Keep the link when copying. The links mentioned here are equivalent to shortcuts in Windows systems.
-f: Overwrite an existing target file without giving a prompt.
-i: Contrary to the -f option, a prompt is given before overwriting the target file, asking the user to confirm whether to overwrite. The target file will be overwritten when answering "y".
-p: In addition to copying the contents of the file, the modification time and access permissions are also copied to the new file.
-r: If the given source file is a directory file, all subdirectories and files in the directory will be copied.
-l: Do not copy files, just generate link files.

cat -AbeEnstTuv [--version] fileName

-n or --number: Number all output lines starting from 1.
-b or --number-nonblank: Similar to -n, except that blank lines are not numbered.
-s or --squeeze-blank: When encountering two or more consecutive blank lines, replace them with one blank line.

scp [optional parameter] file_source file_target

-r: Recursively copy the entire directory.
-P port: Note the capital P, port is the port number used to specify the data transmission

1. Copy from local to remote

scp local_file remote_username@remote_ip:remote_folder
Copy after login

or

scp local_file remote_username@remote_ip:remote_file
Copy after login

or

scp local_file remote_ip:remote_folder
Copy after login

or

scp local_file remote_ip:remote_file
Copy after login

The 1st and 2nd ones specify the user name. After the command is executed, you need to enter the password again. The 1st one Only the remote directory is specified, and the file name remains unchanged. The second one specifies the file name;
The third and fourth ones do not specify a user name. You need to enter the user name and password after the command is executed. The third one only specifies the remote directory. Directory, the file name remains unchanged, the 4th one specifies the file name;

Application example:

scp /home/space/music/1.mp3 root@www.runoob.com:/home/root/others/music
scp /home/space/music/1.mp3 root@www.runoob.com:/home/root/others/music/001.mp3
scp /home/space/music/1.mp3 www.runoob.com:/home/root/others/music
scp /home/space/music/1.mp3 www.runoob.com:/home/root/others/music/001.mp3
Copy after login

Copy directory command format:

scp -r local_folder remote_username@remote_ip:remote_folder
Copy after login

or

scp -r local_folder remote_ip:remote_folder
Copy after login

The first one specifies the user name, and you need to enter the password after the command is executed;
The second one does not specify the user name, and you need to enter the user name and password after the command is executed;
Application Example:

scp -r /home/space/music/ root@www.runoob.com:/home/root/others/
scp -r /home/space/music/ www.runoob.com:/home/root/others/
Copy after login

The above command copies the local music directory to the remote others directory.

2. Copy from remote to local

To copy from remote to local, just change the order of the last two parameters of the command to copy from local to remote, as shown in the following example

Application example:

scp root@www.runoob.com:/home/root/others/music /home/space/music/1.mp3
scp -r www.runoob.com:/home/root/others/ /home/space/music/
Copy after login

Instructions

1. If the remote server firewall has set a specified port for the scp command, we need to use the -P parameter to set the command The port number, the command format is as follows:
scp -P 4588 remote@www.runoob.com:/usr/local/sin.sh /home/administrator #scp command uses port number 4588. When using the scp command, ensure that the user used Have permission to read the corresponding files on the remote server, otherwise the scp command will not work.

rcp

rcp -pr[target file or directory]

rcp -pr[目标文件]
-p  保留源文件或目录的属性,包括拥有者,所属群组,权限与时间。
-r  递归处理,将指定目录下的文件与子目录一并处理。

使用 rcp 指令复制远程文件到本地进行保存。
设本地主机当前账户为 rootlocal,远程主机账户为 root,要将远程主机(218.6.132.5)主目录下的文件"testfile"复制到本地目录"test"中,则输入如下命令:
rcp root@218.6.132.5:./testfile testfile
 #复制远程文件到本地
rcp root@218.6.132.5:home/rootlocal/testfile testfile
 #要求当前登录账户 cmd 登录到远程主机
rcp 218.6.132.5:./testfile testfile
Copy after login

ftp -dignv

tftp [主机名称或 IP 地址]

tar

-c 或--create 建立新的备份文件。
-t 或--list 列出备份文件的内容。
-x 或--extract 或--get 从备份文件中还原文件。
-z 或--gzip 或--ungzip 通过 gzip 指令处理备份文件。
-f<备份文件>或--file=<备份文件> 指定备份文件。
-v 或--verbose 显示指令执行过程。

压缩文件 非打包
# touch a.c
# tar -czvf test.tar.gz a.c //压缩 a.c文件为test.tar.gz
Copy after login

a.c

列出压缩文件内容

# tar -tzvf test.tar.gz
-rw-r--r-- root/root 0 2010-05-24 16:51:59 a.c
Copy after login

解压文件

# tar -xzvf test.tar.gz a.c
Copy after login

gzip

-c 或--stdout 或--to-stdout  把压缩后的文件输出到标准输出设备,不去更动原始文件。
-d 或--decompress 或----uncompress  解开压缩文件。
-f 或--force  强行压缩文件。不理会文件名称或硬连接是否存在以及该文件是否为符号连接。
-l 或--list  列出压缩文件的相关信息。
-r 或--recursive  递归处理,将指定目录下的所有文件及子目录一并处理。
-v 或--verbose  显示指令执行过程。

压缩文件

[root@w3cschool.cc a]
# ls
 //显示当前目录文件
a.c b.h d.cpp
[root@w3cschool.cc a]
# gzip *
 //压缩目录下的所有文件
[root@w3cschool.cc a]
# ls
 //显示当前目录文件
a.c.gz b.h.gz d.cpp.gz
[root@w3cschool.cc a]#
Copy after login

列出详细的信息

[root@w3cschool.cc a]
# gzip -dv *
 //解压文件,并列出详细信息
a.c.gz: 0.0% -- replaced with a.c
b.h.gz: 0.0% -- replaced with b.h
d.cpp.gz: 0.0% -- replaced with d.cpp
[root@w3cschool.cc a]#
Copy after login

显示压缩文件的信息

[root@w3cschool.cc a]
# gzip -l *
compressed uncompressed ratio uncompressed_name
24 0 0.0% a.c
24 0 0.0% b.h
26 0 0.0% d.cpp
Copy after login

zip

将 /home/html/ 这个目录下所有文件和文件夹打包为当前目录下的 html.zip:
zip -q -r html.zip /home/html
Copy after login

如果在我们在 /home/html 目录下,可以执行以下命令:

zip -q -r html.zip *
Copy after login

从压缩文件 cp.zip 中删除文件 a.c

zip -dv cp.zip a.c
Copy after login

unzip

查看压缩文件中包含的文件:
# unzip -l abc.zip
Copy after login

-v 参数用于查看压缩文件目录信息,但是不解压该文件。

# unzip -v abc.zip
Copy after login

kill

kill 12345 杀死进程

其他

环境变量 cmd:sysdm.cpl

The above is the detailed content of Summary of commonly used commands in Linux (detailed). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1657
14
PHP Tutorial
1257
29
C# Tutorial
1229
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

vscode terminal command cannot be used vscode terminal command cannot be used Apr 15, 2025 pm 10:03 PM

Causes and solutions for the VS Code terminal commands not available: The necessary tools are not installed (Windows: WSL; macOS: Xcode command line tools) Path configuration is wrong (add executable files to PATH environment variables) Permission issues (run VS Code as administrator) Firewall or proxy restrictions (check settings, unrestrictions) Terminal settings are incorrect (enable use of external terminals) VS Code installation is corrupt (reinstall or update) Terminal configuration is incompatible (try different terminal types or commands) Specific environment variables are missing (set necessary environment variables)

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

See all articles