Home Operation and Maintenance Linux Operation and Maintenance A summary of commonly used Linux commands in Ubuntu

A summary of commonly used Linux commands in Ubuntu

Jul 18, 2017 am 09:37 AM
linux ubuntu Summarize

I have been in the laboratory for nearly a month, and I have hardly touched windows. I have been developing under Ubuntu, and I would like to summarize the commonly used Linux commands recently.

(0) su and sudo: Get root permissions

su 切换到root用户sudo command 切换到root用户,执行command,然后切换回当前用户su liaohuqiang 切换回普通用户
Copy after login

(1) apt: Used to install software packages

apt list 根据名称列出软件包
apt show 显示软件包细节sudo apt install 安装软件包sudo apt remove 卸载软件包sudo apt-get check 检查依赖sudo apt update 更新可用软件包列表sudo apt upgrade 通过安装/升级软件来更新系统
Copy after login

(2) pip: Used to install python modules (not the default command in linux, You need to install sudo apt install pip yourself)

pip install 安装包
pip uninstall 卸载包
pip list 列出已安装的包
pip show 展示已安装包的信息
pip check 检查依赖
pip --version 显示pip版本和位置
pip help 查看帮助
pip help install 查看install指令的相关option介绍
Copy after login

(3) ssh and scp: Communication between hosts

ssh username@ip 登录到远程主机scp local_file username@ip:remote_directory 复制本地文件到远程主机scp -r local_directory username@ip:remote_directory 复制本地文件夹到远程主机
Copy after login

(4) Compression and decompression: zip, unzip, tar

zip -r target.zip . 把当前目录以及目录下的子文件夹全部压缩zip target.zip 压缩当前目录,如果有文件夹则不会压缩进去(因为没有加-r)unzip source.zip -d 'folder' 解压到folder目录下unzip source.zip 解压到当前目录下tar -zcvf target.tar.gz sorceFoler c代表打包,z代表用gzip来压缩/解压,v详细报告处理信息,f必选并且后带文件名tar -zxvf source.tar.gz -C 'folder' 解压到folder目录下,,其中z代表gzip属性的,x代表解压,v代表解压时输出相关信息,f必须有并且放最后并且后带文件名。tar -xvf source.tar.gz 试了一下,少了个z也可以,效果同上
Copy after login

(5) Check the storage usage of the disk: du; check the storage usage of the file system: df.

du -s或--summarize 仅显示总计,只列出最后加总的值。du -h 以K,M,G为单位,提高信息的可读性。df -h 以K,M,G为单位,提高信息的可读性。df -T x显示文件系统类型
Copy after login

(6) Search command

6.1 which searches for a system in the path specified by the PATH variable The position of the command and returns the first search result.
6.2 whereis can only be used to search for program names, and only searches binary files (parameter -b), man description files (parameter -m) and source code files (parameter -s). If parameters are omitted, all information is returned.
6.3 locate Use the database to view the file location. Linux will record all files in the system in a database file, but the database is not updated in real time.
6.4 find actually searches the hard disk to query the file name.

 . -name whereis python
which python
Copy after login

(7) File permissions

 [ugoa][+-=+代表增加权限,-代表取消权限,= u+=, =, x=  用户名[:组名] 文件名或目录 改变指定目录或文件的所属用户
Copy after login

(8) File and text operations

grep str /tmp/test 在文件/tmp/test中查找strgrep ^str /tmp/test 在文件/tmp/test中查找以str开始的行ls -ld */ 显示当前目录的所有目录文件ls -l | grep '^d'  显示当前目录的所有目录文件wc -l 统计文件行数wc -w 统计单词数量ls -l | wc -l 统计当前目前的文件数量,注意要减去“总用量”那一行cp -a dir1 dir2 复制目录mv dir1 dir2 移动/重命名目录mkdir -p /tmp/dir1/dir2 创建一个目录树rm -f file1 删除文件rm -rf dir1 删除目录
Copy after login

(9) Process

ps -e 显示所有进程ps -f 全格式显示进程ps -u 'liaohuqiang' | grep 'tmux' 显示指定用户执行的进程,并匹配出包含'tmux'的那一行进程kill -2 pid 类似ctrl+C,在程序结束之前能够保存相关数据,再退出kill -9 pid 直接强制结束进程

top 动态显示进程信息
top -i 不显示任何闲置或无用的进程
k 杀死某进程
n 改变显示的进程数量
u 显示指定用户
P 按CPU使用情况排序
q 退出
Copy after login

(10) Network

netstat 显示网络情况
netstat -a 列出所有端口
netstat -l 只显示监听端口
netstat -t 列出所有tcp端口
netstat -p 显示使用该端口的pid和程序名称
netstat -n 直接使用ip地址,不通过域名服务器

找出程序运行的端口:netstat -anp | grep ssh找出运行在指定端口的进程:netstat -anp | grep ':80'ifconfig 查看网卡信息
Copy after login

(11) Others

date 显示时间whoami 显示当前用户名who 目前登录系统的用户信息
curl 'url' -O --progress 下载文件,-O代表保存文件(如果没有则输出到屏幕), --progress表示会显示进度条 
(curl不是linux的默认自行,需自行安装apt install curl)echo $SHELL 查看系统使用的是哪种shellecho $PATH 查看环境变量
Copy after login

Help
--help simple help
help command more detailed help
man command the most detailed help
ls command
ls - a Display all files and folders, including hidden files or folders
ls -l displays more complete file information, including permissions, users, user groups, etc.
ls --color displays files and folders marked with different colors.
tab key
The tab command is used when you can’t remember all the commands. Enter one part and press it again to complete it. If there are multiple commands with the same previous part, then
Press the tab key twice
alias
alias ubuntu="ls" is used to give an alias to a command. When you enter ubuntu it is equivalent to entering the ls command.

The above is the detailed content of A summary of commonly used Linux commands in Ubuntu. 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)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

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.

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.

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.

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.

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)

See all articles