


A summary of commonly used Linux commands in Ubuntu
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 切换回普通用户
(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 通过安装/升级软件来更新系统
(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介绍
(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 复制本地文件夹到远程主机
(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也可以,效果同上
(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显示文件系统类型
(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
(7) File permissions
[ugoa][+-=+代表增加权限,-代表取消权限,= u+=, =, x= 用户名[:组名] 文件名或目录 改变指定目录或文件的所属用户
(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 删除目录
(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 退出
(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 查看网卡信息
(11) Others
date 显示时间whoami 显示当前用户名who 目前登录系统的用户信息 curl 'url' -O --progress 下载文件,-O代表保存文件(如果没有则输出到屏幕), --progress表示会显示进度条 (curl不是linux的默认自行,需自行安装apt install curl)echo $SHELL 查看系统使用的是哪种shellecho $PATH 查看环境变量
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.

The steps to start Apache are as follows: Install Apache (command: sudo apt-get install apache2 or download it from the official website) Start Apache (Linux: sudo systemctl start apache2; Windows: Right-click the "Apache2.4" service and select "Start") Check whether it has been started (Linux: sudo systemctl status apache2; Windows: Check the status of the "Apache2.4" service in the service manager) Enable boot automatically (optional, Linux: sudo systemctl

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

This article describes how to effectively monitor the SSL performance of Nginx servers on Debian systems. We will use NginxExporter to export Nginx status data to Prometheus and then visually display it through Grafana. Step 1: Configuring Nginx First, we need to enable the stub_status module in the Nginx configuration file to obtain the status information of Nginx. Add the following snippet in your Nginx configuration file (usually located in /etc/nginx/nginx.conf or its include file): location/nginx_status{stub_status

The steps to start an Oracle listener are as follows: Check the listener status (using the lsnrctl status command) For Windows, start the "TNS Listener" service in Oracle Services Manager For Linux and Unix, use the lsnrctl start command to start the listener run the lsnrctl status command to verify that the listener is started

This article introduces two methods of configuring a recycling bin in a Debian system: a graphical interface and a command line. Method 1: Use the Nautilus graphical interface to open the file manager: Find and start the Nautilus file manager (usually called "File") in the desktop or application menu. Find the Recycle Bin: Look for the Recycle Bin folder in the left navigation bar. If it is not found, try clicking "Other Location" or "Computer" to search. Configure Recycle Bin properties: Right-click "Recycle Bin" and select "Properties". In the Properties window, you can adjust the following settings: Maximum Size: Limit the disk space available in the Recycle Bin. Retention time: Set the preservation before the file is automatically deleted in the recycling bin

To restart the Apache server, follow these steps: Linux/macOS: Run sudo systemctl restart apache2. Windows: Run net stop Apache2.4 and then net start Apache2.4. Run netstat -a | findstr 80 to check the server status.

In Debian systems, readdir system calls are used to read directory contents. If its performance is not good, try the following optimization strategy: Simplify the number of directory files: Split large directories into multiple small directories as much as possible, reducing the number of items processed per readdir call. Enable directory content caching: build a cache mechanism, update the cache regularly or when directory content changes, and reduce frequent calls to readdir. Memory caches (such as Memcached or Redis) or local caches (such as files or databases) can be considered. Adopt efficient data structure: If you implement directory traversal by yourself, select more efficient data structures (such as hash tables instead of linear search) to store and access directory information
