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

巴扎黑
巴扎黑Original
2017-07-18 09:37:571761browse

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!

Statement:
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