Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common commands in linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "which commands are commonly used in linux". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "which commands are commonly used in linux".

A complete Collection of commonly used linux commands

Common structure of Linux command: Command [- option] [argument]

Command: that is, the command to be run itself, to put it bluntly, is a software (program)

Option: is an option (optional) that controls the running state and behavior of the command (multiple options, such as df-hT)

Argument: is a parameter (optional) and is a command to manipulate objects such as files, paths, data, directories, etc.

Press the [tab] key in the first part of the instruction for [command completion], select for all commands twice, and press the [tab] key twice in the non-first part for [file completion]

The linux command is case sensitive

Switch on and off

Sync: write the data in memory to disk (sync is required before shutdown and restart)

Shutdown-r now or reboot: restart immediately

Shutdown-h now: turn it off immediately

Shutdown-h 20:00: shut down the system at the scheduled time (shutdown at 8pm, if it is beyond 8pm now, 8pm tomorrow)

Shutdown-h + 10: shut down the system at a scheduled time (shut down after 10 minutes)

Shutdown-c: cancel shutting down the system at the scheduled time

System information

Who am i: view the terminals currently in use

Who or w: view all terminals

Uname-m: displays the processor architecture of the machine (such as x86x64)

Cat / proc/version: view linux version information

Uname-r: displays the kernel version in use

Lsb_release-a: check the system distribution (such as CentOS7) (install yum install-y redhat-lsb-core without this command)

Rpm-qa | grep kernel-devel: check the kernel-devel version (the kernel is compiled when installing the software, so you need to keep the kernel version consistent)

Yum install-y "kernel-devel-uname-r = = $(uname-r)": install kernel-devel that matches the Linux kernel version

Hostnamectl set-hostname hostname: modify the hostname (including static, transient and flexible hostnames. If there is domain name resolution, remember to update / etc/hosts manually)

Date: displays the system date (date +% Y/%m/%d: display effect such as 2018-01-01)

Date 070314592018.00: set the time (format: month, day, hour, year. Seconds)

Clock-w: save time changes to BIOS

Cal 2018: display the calendar for 2018

Clear: clear the command line

Ifconfig: display or set the network card (check ip, etc.) (similar to ipconfig in windows)

Ping-c 3 www.baidu.com: test the connection between Baidu and this machine (- c 3 means 3 tests)

Cat / proc/cpuinfo: display information for CPU

Cat / proc/cpuinfo | grep "physical id" | sort | uniq | wc-l: view the number of physical CPU

Cat / proc/cpuinfo | grep "cpu cores" | uniq: check the number of cores in each physical CPU

Cat / proc/cpuinfo | grep "processor" | wc-l: check the number of logical CPU, i.e. the number of threads.

System performance

Top: dynamic real-time display of cpu, memory, process, etc. Usage (similar to task manager under windows)

Top-d 2-p 7427:-d is the number of seconds to update the screen. The default is 5 seconds, and-p is the pid information of the specified process.

Vmstat 2 10: collect server status every 2 seconds and collect 10 times (check memory, io read and write status, cpu)

Free-h: view system memory and virtual memory usage

Df-h: displays disk space usage

Iostat: can check io read and write, cpu usage

Sar-u 3 5: check cpu usage (once every 3 seconds for 5 times)

Sar-d 2 3: evaluate disk performance

Ps aux | grep firefox: get the process number of Firefox (PID) (you can check the cpu occupied by the process, the percentage of memory occupied by the process, and the path of the instruction triggered by the process)

Kill-9 process number: forcibly kill a process

Systemctl: view running services

Files and directories

Cd: abbreviation for Change Directory, used to switch working directories. Syntax: cd [relative or absolute path or special symbol]

Cd: enter the user's home directory ~ (root user is / root, other user is / home/ user name)

Cd.. Return to the directory at the previous level (pay attention to spaces)

Cd -: returns the directory where it was last time

Cd /: returns the root directory (absolute path)

Cd. / directory 1 / directory 2: enter a subdirectory under the current directory (relative path)

Pwd: show work path (abbreviation for Print Working Directory)

Ls: abbreviation for List, used to list files in a directory, syntax: ls [option] [directory or file name]

Ls-a: lists all the files under the file, including "." Hidden file at the beginning

Ls-lh * .log: lists the details of the file (at the end of the .log, * is a wildcard that represents any number of characters)

File file or directory: displays the type of file (directory, text, zip, shell script, etc.)

Mkdir dir1: create a directory (dir1) (mkdir is an abbreviation for make directory)

Mkdir-p. / dir1/dir2: recursively create a directory (- p: set up at the same time when the parent directory does not exist)

Touch a.txt: create file a.txt

Rm: you can delete one or more files or directories in a directory, or delete a directory and all its subordinate files and their subdirectories; syntax: rm (option) (parameter) (Note: if the parameter contains a directory, you must add the-r option)

Rm files: deleting fil

Rm-r directory or file: delete the directory (and all files under the directory) (not empty)

Rm-rf directory or file: forced deletion, such as: rm-rf * to delete all files in the current directory

Find-inum 1842601-exec rm-rf {};: delete garbled files or directories (you will be prompted that the file or folder cannot be found but have already been deleted) (uploading Chinese files will be garbled, but the rm command cannot delete them) (first use the ls-I command to find inode, that is, the numeric string before the file or directory, such as 1842601;)

Mv: an abbreviation for move, which can be used to cut and move files, directories, or rename files

Syntax: mv source file destination file (renamed) or directory (mobile)

Mv a b: move or rename a file or directory (move the directory or overwrite the file if it exists, rename it if it doesn't exist)

Mv / opt/git/g / opt/a: move g to the opt directory and rename it to a (a directory does not exist, if so, move g to a directory)

Mv-t. / test a.txt b.txt: move multiple files to a directory

Cp: copy a file or directory; the cp command can copy single or multiple files to an existing directory

Commonly used: cp-ai file or directory target directory

Cp-ai / opt/abc / opt/git/: copy the abc directory (or files) to the git directory (option a means that the attributes of the files are also copied, and all files under the directory are copied; I means ask before overwriting)

Abbreviation for ln:link, used to establish hard (soft) links, often used to build soft links (similar shortcuts) to PATH during software installation

Syntax: ln [- s] source file target file

Ln-s / opt/a.txt / opt/git/: create a soft link to the file (shortcut does not rename or a.txt)

Ln-s / opt/a.txt / opt/git/b: (the shortcut is renamed to b) (the following can be renamed)

Ln-s / opt/mulu / opt/git/: create soft links to directories

Ln / opt/a.txt / opt/git/: create hard links to files

File permissions

Chmod [- R] 777 files or directories: setting permissions (chmod a+rwx a=chmod ugo + rwx a=chmod 777a)

Note: r (read) corresponds to 4 Magi w (write) corresponds to 2 Magi x (execute) execution corresponds to 1.

-R: recursively change the group of files, that is, when you change the group of a directory file, if you add the parameter of-R, then the group of all files in that directory will be changed.

Chmod [{ugoa} {+-=} {rwx}] [file or directory]: for example, chmod UmurwGrady glossary test.txt test.txt removes write permission for user (owner), group (group to which it belongs) plus execution permission, and other (others) permission equals read-only.

Chown [- R] admin:root / opt/: change the owner and group of files and directories (- R recursively handles all files and folders, admin is the owner, root is the owner)

File lookup

Locate a.txt: look for files whose filenames contain the word a.txt globally (faster than find)

Locate: the principle is that updatedb stores the information in the file system into the database databases (but it is usually executed only once a day, so locate cannot find the newly created file, so you need to manually execute updatedb before locate), and locate reads the data from the database.

Find: searches for files in the directory structure and performs the specified operation

Syntax: find pathname-options [- print-exec.]

Pathname: the directory path found for the find command. For example, with. To represent the current directory and / to represent the system root directory (find looks for all files and directories in the target directory and its subdirectories)

The-exec: find command executes the shell command given by this parameter on the matching file. The corresponding command is in the form 'command' {};, notice the space between {} and\;

-print: the find command outputs matching files to standard output

Find / home-mtime-2: check the files that have been changed in the last 2 to 24 hours under / home

Find. -size + 100m: find files greater than 100m in the current directory and subdirectories

Find. -type f: F indicates that the file type is a normal file (b/d/c/p/l/f is block device, directory, character device, pipe, symbolic link, ordinary file)

Find. -mtime + 2-exec rm {};: find out the file whose change time is 2: 24 hours ago and delete it * *

Find.

Find. -name'* .log'| grep hello: find files with a file name suffix of .log in the current directory and subdirectories and the file name contains the word hello (grep is used to process strings)

Grep-I 'HELLO'. -r-n: look for files containing hello in the current directory and subdirectories and display the file path (- I indicates ignoring case)

Which java: look for qualified files in the directory set by the environment variable $PATH, and display the path (query the path where the running file is located)

Whereis java: view all the file paths of the installed software (whereis can only be used to find binaries, source code files, and man man pages, general file location needs to use the locate command)

View the contents of the file

Cat [- n] file name: displays the contents of the file, along with the line number

Less file name: displays the contents of the file page by page (search page flipping with man command)

Head [- n] filename: displays the contents of the file header n lines, n specifies how many lines to display

Sed-n'2 ab: show the second line to the last line

Sed-n'/ searched keywords / p 'a.txt: displays the lines that include keywords

Less a.txt | keywords searched by grep: displays the line in which the keywords are located

Cat-n a.txt | keywords searched by grep: display includes the line in which the keyword is located (displayed together with line numbers)

Cat filename | grep abc-A10: view the filename containing the last 10 lines (A10) and the first 10 lines (B10) of the abc line

Less a.txt | grep git: displays the line of the keyword, and the pipe character "|" can only handle the correct output information from the previous instruction, but has no direct ability to deal with the error message. Then pass it to the next command as standard input

Cat / etc/passwd | awk-F':'{print $1}': displays the first column

Text processing

Ls-l > file: output redirection > (change the default execution mode of the original system command): the result of the ls-l command is output to the file file. If it exists, it is overridden.

Cat file1 > > file: output redirected cat command output is appended to the file file (> indicates overwriting the original file content, > > indicates the appended content)

Ls fileno 2 > file: 2 > indicates that the standard error output is redirected (the file does not exist and the error message is saved to the file file)

Cowsay > authorized_keys

Chmod 700. ssh

Chmod 600 ~ / .ssh/authorized_keys

# generate the private key of putty (the private key format used by Putty is a little different from that generated by OpenSSH, and you need to convert putty before you can use it)

Download the private key id_rsa locally and change the suffix to .ppk, such as id_rsa_ip_commonuser.ppk

Use the "Load" of the puttygen tool to read the id_rsa file, and click "Save private key" to keep the private key

Putty can log in to the server by associating the private key file.

Disk management

Fdisk-l: view disk information (check the capacity of each hard disk and the partition of each hard disk) (each hard disk or partition under the hard disk must be mounted to a directory before it can be used)

Fdisk / dev/sdb: create a partition for the hard disk sdb

Mkfs.ext4 / dev/vdb1: modify the file system type of formatted hard disk partition vdb1 to ext4

Df-TH: displays disk space usage, file system type, and mount point (displayed only when the hard disk is mounted)

Df-h / var/log: (displays the partition where the log is located (mount point), the disk where the directory is located, and the available disk capacity)

Du-sm / var/log/ | sort-rn*: sort (MB) the size of files and directories in a directory according to the amount of disk space occupied

Mount / dev/sda1 / mnt: the hard disk sda1 is mounted to the / mnt directory (mount device file name mount point)

Mount-t cifs-o username=luolanguo,password=win user account password, vers=3.0 / / 10.2.1.178 windows G / mnt/usb: remote linux share mount windows U disk, G is U disk shared name, need to set U disk sharing

Mount-o loop / opt/soft/CentOS-7-x86_64-DVD-1708.iso / media/CentOS: Mount the iso file

Umount / dev/sda1: unmount (umount device file name or mount point)

Compress, decompress, and package backup

Simple tar is only for packaging (multiple files are packaged into a large file), plus parameters-j (bzip2 format .bz2) and-z (gzip format .gz) can be backed up, compressed (- c) and decompressed (- x). Backup generally adds more parameters than compression-p (retains the permissions and attributes of the original file), and-C can specify to extract to a specific directory; bzip2 and gzip can only compress a single file

File file name: check the file type (you can see how it is compressed)

Tar-zxvf a.tar.gz-C. / test: extract the tar.gz to the test directory under the current directory

Tar-zcvf / opt/c.tar.gz. / a /: compress tar.gz (compress the a directory in the current directory and all files in the directory into c.tar.gz in the / opt/ directory, so that tar-zxvf c.tar.gz is extracted with directory a)

Tar-jxvf a.tar.bz2: extract the tar.bz2 (to the current directory)

Tar-jcvf c.tar.bz2. / a /: compress tar.bz2 (compress the a directory and all files in the current directory to the current directory as c.tar.gz2)

Unzip a.zip: extract zip (to current directory)

Unzip-o mdmtest.war-d / opt/mdm: it is recommended to use unzip to extract the war package (- o overwrites the original file,-d specifies the directory to store the file after decompression)

Zip-r c.zip. / a /: compress zip (compress the a directory and all files in the current directory to the current directory as c.zip

Bzip2-k file1: compress a 'file1' file (- k means keep the source file) (bzip2 format, better than gzip)

Bzip2-d-k file1.bz2: extract a file called 'file1.bz2'

Gzip file1: compress a file called 'file1' (in gzip format) (source files cannot be retained)

Gzip-9 file1: maximum compression

Gzip-d file1.gz: extract a file called 'file1'

Software installation

Try to install with yum source (apt-get). If not, install rpm and deb packages. If you can not compile manually, do not compile manually.

Dpkg can only install deb packages that have been downloaded to the local machine. Apt-get can download and install deb packages online, update the system, and automatically deal with package-to-package dependencies, which dpkg tools do not have.

Rpm can only install rpm packages that have been downloaded to the local machine. Yum can download and install rpm packages online, update the system, and automatically deal with package-to-package dependencies, which rpm tools do not have.

Yum and rpm installation files are distributed in different directories of bin, lib and share of / usr. You do not need to configure PATH, but you can use commands to uninstall updates.

Compile the software manually. The default location is under different subdirectories under / usr/local. You don't need to configure PATH to use commands directly (you need to add PATH to specify the installation path manually), which makes it very troublesome to update and delete the software. There is no uninstall command to compile and install the software. To uninstall is to delete all the files of the software.

Binary (Binaries) packet

Yum installation

Download and install rpm packages online for CentOS, Fedora, RedHat and similar systems

Yum install epel-releas: install third-party YumSource EPEL (short for Enterprise Linux add-on package)

Yum repolist enabled: displays the available source repositories (configured under / etc/yum.repos.d/ directory)

Yum install yum-fastestmirror: automatically select the fastest yum source

Yum list installed | grep java: list installed software (view installed JDK)

Yum remove java-1.8.0-openjdk.x86_64: uninstall the software (uninstall JDK)

* yum list java * *: list the installed and installable software (check the JDK package in the yum library)

Yum install [- y] java-1.8.0-openjdk: installation software JDK (- y automatic installation) (recommended for this type of installation)

Yum install docker-ce-18.03.1.ce: installs the specified version of the software (if the docker-ce.x86_64 18.03.1.ce-1.el7.centos is known, the rpm package is named docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm)

* * yum check-update [kernel] * *: list all updatable software (check for updated kernel)

Yum update tomcat: update software (all available)

Rpm-ql software name: query the yum installation path (the software name can be rpm-qa | grep java)

Yum info kernel: view information about software (kernel)

Yum clean all: (clear the cache to make the latest yum configuration effective)

Common tools for yum installation

Yum install-y unzip zip: install the compress and decompress commands (zip, unzip)

Download and install rpm package manually

There is no temporary use in yum. It is suitable for CentOS, Fedora, RedHat and similar systems.

Wget-P / opt https:// URL: download to / opt directory

Rpm-ivh wps-office- version .x86 _ 64.rpm: install the rpm package (download the package first) (install the dependency package first)

Rpm-e wps-office: uninstall the software (be careful not to have the software name or version number)

Rpm-qa | grep wps: view the installed rpm package (can be used to query whether the rpm package is installed)

Rpm-ql software name: view the rpm package installation path (the software name can be rpm-qa | grep java)

Apt installation

Install debit package, similar to yum installation, suitable for Debian, Ubuntu and similar systems

Apt-get install aptitude: install aptitude tools, rely on automatic installation, and automatically downgrade or upgrade depending on version

Aptitude install software: install software (recommended)

Apt-cache search software: search softwar

Apt-get install software: installing softwar

Apt-get purge software: uninstall the software (including configuration files, only delete the software purge and replace it with remove)

Apt-get upgrade: update all installed packages

Apt-get update: software packages in the upgrade list

Apt-get clean: cleans up the cache from downloaded packages

Deb package installation

Suitable for Debian, Ubuntu and similar systems

Dpkg-I package.deb: install a deb package

Dpkg-r package_name: removes a deb package from the system

Dpkg-l | grep chrome: query all installed deb packages in the system

Dpkg-L software name: check the files installed by the software

Decompression is ready for use

Most non-open source commercial software adopts this approach.

Binary (Binaries) packages such as apache-jmeter-3.3.tgz, download and copy to / opt, and then add the bin directory of the software to PATH (vim / etc/profile export PATH=$PATH:/opt/apache-jmeter-3.3/bin)

Software's own module / package manager

For example, python: the source of the system cannot contain all the modules of the software; the update of the module of the software in the source of the system lags far behind the latest version; install python manually and install the module with Python's own pip (similar to yum)

* * pip install redis * *: install the python software package redis

* * pip unstall redis * *: uninstall

* * pip show-- files redis * *: pip to view installed packages

Pip list-- outdated: check for updates

Source code (Source) package

Compilation and installation

Source code packages (usually have install files) such as hello-2.2.tar.bz2, download and copy to / opt

Tar-jxvf hello-2.2.tar.bz2: decompression

. / configure-- prefix=/opt/ software directory name: ready for compilation, plus prefix manually specify the installation path

Make: compiling

Make install: installation

Make clean: delete temporary files generated during installation

Vim / etc/profile export PATH=$PATH:/opt/ directory / bin: path is required to specify the installation path manually

Hello: executive software: look at the INSTALL and README files (whether the source package, how to install, execute all look at these two)

Rm-rf software directory name: uninstall the software

Service and process

Netstat-ntlp: view all occupied ports of the server

Netstat-lnp | grep port number / process number / process name: check whether the service is started according to whether the port is open, and check the port occupied by the service with the ps command

Common parameters:

-p: get the process name and process number

-n: disable domain name resolution, find out IP and be fast

-l: only the connections in monitoring are listed

-t: only TCP protocol connections are listed.

Example: ps aux | grep tomcat netstat-lnp | grep process number: check the port occupied by tomcat service; ps aux | grep process number / process startup command / service name: process view command ps (process status can be checked; process occupies cpu and memory; cooperate with netstat to find out the process number according to a service port to kill the process, check the service startup command and service path)

The above is all the contents of the article "what are the common commands in linux?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report