Today, I bring you a very comprehensive article summarizing Linux commands. It is also a very frequently used operation command in our daily work. There are a lot of commands. It is recommended that friends collect it first and then read it.
cd /home 进入 '/ home' 目录' cd .. 返回上一级目录 cd ../.. 返回上两级目录 cd 进入个人的主目录 cd ~user1 进入个人的主目录 cd - 返回上次所在的目录 pwd 显示工作路径 ls 查看目录中的文件 ls -F 查看目录中的文件 ls -l 显示文件和目录的详细资料 ls -a 显示隐藏文件 ls *[0-9]* 显示包含数字的文件名和目录名 tree 显示文件和目录由根目录开始的树形结构(1) lstree 显示文件和目录由根目录开始的树形结构(2) mkdir dir1 创建一个叫做 'dir1' 的目录' mkdir dir1 dir2 同时创建两个目录 mkdir -p /tmp/dir1/dir2 创建一个目录树 rm -f file1 删除一个叫做 'file1' 的文件' rmdir dir1 删除一个叫做 'dir1' 的目录' rm -rf dir1 删除一个叫做 'dir1' 的目录并同时删除其内容 rm -rf dir1 dir2 同时删除两个目录及它们的内容 mv dir1 new_dir 重命名/移动 一个目录 cp file1 file2 复制一个文件 cp dir/* . 复制一个目录下的所有文件到当前工作目录 cp -a /tmp/dir1 . 复制一个目录到当前工作目录 cp -a dir1 dir2 复制一个目录 ln -s file1 lnk1 创建一个指向文件或目录的软链接 ln file1 lnk1 创建一个指向文件或目录的物理链接 touch -t 0712250000 file1 修改一个文件或目录的时间戳 - (YYMMDDhhmm) file file1 outputs the mime type of the file as text iconv -l 列出已知的编码 iconv -f fromEncoding -t toEncoding inputFile > outputFile creates a new from the given input file by assuming it is encoded in fromEncoding and converting it to toEncoding. find . -maxdepth 1 -name *.jpg -print -exec convert "{}" -resize 80x60 "thumbs/{}" \; batch resize files in the current directory and send them to a thumbnails directory (requires convert from Imagemagick)
ifconfig eth0 显示一个以太网卡的配置 ifup eth0 启用一个 'eth0' 网络设备 ifdown eth0 禁用一个 'eth0' 网络设备 ifconfig eth0 192.168.1.1 netmask 255.255.255.0 控制IP地址 ifconfig eth0 promisc 设置 'eth0' 成混杂模式以嗅探数据包 (sniffing) dhclient eth0 以dhcp模式启用 'eth0' route -n show routing table route add -net 0/0 gw IP_Gateway configura default gateway route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 configure static route to reach network '192.168.0.0/16' route del 0/0 gw IP_gateway remove static route echo "1" > /proc/sys/net/ipv4/ip_forward activate ip routing hostname show hostname of system host www.example.com lookup hostname to resolve name to ip address and viceversa(1) nslookup www.example.com lookup hostname to resolve name to ip address and viceversa(2) ip link show show link status of all interfaces mii-tool eth0 show link status of 'eth0' ethtool eth0 show statistics of network card 'eth0' netstat -tup show all active network connections and their PID netstat -tupl show all network services listening on the system and their PID tcpdump tcp port 80 show all HTTP traffic iwlist scan show wireless networks iwconfig eth1 show configuration of a wireless network card hostname show hostname host www.example.com lookup hostname to resolve name to ip address and viceversa nslookup www.example.com lookup hostname to resolve name to ip address and viceversa whois www.example.com lookup on Whois database
Copy after login
23. 列出目录内容
ls -a:显示所有文件(包括隐藏文件); ls -l:显示详细信息; ls -R:递归显示子目录结构; ls -ld:显示目录和链接信息; ctrl+r:历史记录中所搜命令(输入命令中的任意一个字符); Linux中以.开头的文件是隐藏文件; pwd:显示当前目录
Copy after login
24. 查看文件的类型
file:查看文件的类型
Copy after login
25. 复制文件目录
1、cp:复制文件和目录 cp 源文件(文件夹)目标文件(文件夹)
常用参数:-r:递归复制整个目录树;-v:显示详细信息;
复制文件夹时要在 cp 命令后面加一个-r 参数:
如:cp -r 源文件夹 目标文件夹
2.touch file name: When the file does not exist, create the corresponding file; when the file exists, modify the creation time of the file. In addition, when searching for public accounts, Linux should learn how to reply "monkey" in the background and get a surprise gift package.
Function: Generate an empty file or modify the access/modification time record value of the file.
touch *: Modify the current file time to the current system time
touch –d 20040210 test: Change the date of the test file Change to 20040210
touch abc : If the abc file exists, it will be modified to the current time of the system; if it does not exist, an empty file with the current time will be generated
3,mv file target directory: Move or rename the file or directory (if the file name is specified, the file can be renamed). You can move files and directories to another directory, or change the names of files and directories.
##The format is: mv [parameter]
## mva.txt ../: Move the a.txt file to the upper directory
mv a.txt b.txt: Rename a.txt to b.txt
mvdir2 ../: Move the dir2 directory up one level
4,rm: Delete files;
Commonly used parameters: -i: interactive -r: recursive Delete all contents in the include directory
5,mkdir Folder name: Create folder;
6,rm -r folder name: Delete the folder (both empty and non-empty folders can be deleted)
rmdir folder Name: Delete folder (only empty folders can be deleted)
7,mkdir -p dir1/dir2: Create the dir1 directory in the current directory , and create the dir2 directory under the dir1 directory, that is, create two directories (dir1/ and dir1/dir2) in succession
8,rmdir –p dir1/dir2: Delete the dir2 directory under dir1. If the dir1 directory is empty, delete it too
9,rm *: Delete all files in the current directory
10,-f parameter: Forced deletion File rm –f *.txt: Force the deletion of all txt files with the extension
11,-i Parameter: Ask when deleting files
rm –i *: Delete all files in the current directory and the following prompt will appear:
rm:backup:is a directory Skip
rm: remove 'myfiles.txt' ? Y
You will be asked when deleting the file. You can press Y or N to allow it. Or refuse to delete the file
12,-r parameter: recursive deletion (deleting subdirectories together, this is a very common parameter)
rm -r test: Delete the test directory (including all files and subdirectories under the test directory)
rm -r *: Delete all files (including all files in the current directory, all subdirectories and files under subdirectories). Generally, r and f are used together when deleting a directory to avoid trouble
rm -rf test: Forced deletion without asking
13,grep: Function: Search for matching characters in the file And output
Format: grep[parameter]
greplinux test.txt: Search for the string linux in the test.txt file and output
14,ln command
Function: Establish a link between a file and a directory
Format: ln [parameter]< Target file or directory>
Links are divided into "soft links" and "hard links"
1.Soft links:
ln–s /usr/share/do doc: Create a link file doc and point to the directory /usr/share/do
2. Hard link :
ln /usr/share/test hard: Create a hard link file hard. At this time, for the storage area corresponding to the test file, there is another file pointing to it
26. Commonly used system commands
26.1. Display command
date: View or set the current system time: format Customized display time: %Y--%m--%d;
date -s: Set the current system time
hwclock( clock): Display hardware clock time (requires administrator rights);
cal: View calendar
Format cal [Parameter] Month Year
cal: Display the calendar of the current month cal4 2004: Display the calendar of April 2004
cal- y 2003: Display the calendar of 2003
uptime: Check the system running time
26.2. Output viewing command
echo: Display the input content and append the file echo "liuyazhuang" >> liuyazhuang.txt
cat: displays the file content, and can also merge several files into one file.
Format: Format: cat[parameter]
cat test.txt: Display test.txt file content
cat test.txt | more: Display the contents of the test.txt file page by page
cat test.txt >> test1. txt: Append the content of test.txt to the test1.txt file
cat test.txt test2.txt >readme.txt: Merge the test.txt and test2.txt files into readme.txt file
head: Display the first few lines of the file (default 10 lines) -n: Specify the number of lines to display Format: head -n file name
tail: Display the file The last few lines (default 10 lines) -n: Specify the number of displayed lines -f: Track display file updates (generally used to view logs, the command will not exit, but will continue to display the newly added content)
Format: Format: tail[parameter]
##tail-10 /etc/passwd: Display the reciprocal of the /etc/passwd/ file 10 lines of content
tail 10 /etc/passwd: Display the contents of the /etc/passwd/ file from line 10 to the end
more: Used to turn pages to display file content (can only turn pages down)
The more command is generally used when the content to be displayed exceeds the length of one screen. In order to avoid the screen flashing when it is displayed, the user can use the more command to pause the screen when a full page is displayed. At this time, the user can press the space bar to continue displaying the next screen, or press the Q key to stop displaying.
ls -al |more: Display the file list in the etc directory in long format. It will pause after displaying one screen. You can press the space bar to continue to display the next screen, or press Q Key jump away
less: Turn pages to display the file content (turn pages up and down). Press the up key to page, and press q to exit. The usage of the '
less command is similar to the more command. , can also be used to browse documents that exceed one page. The difference is that in addition to pressing the space bar to display the file downwards, the less command can also use the up and down keys to scroll the file. When you want to end browsing, just press the Q key at the less command prompt ":".
ls -al | less: List all contents in the /etc directory in long format. The user can press the up and down keys to browse or press the Q key to escape
26.3. View hardware information
Ispci: View PCI device -v: View Detailed information
Isusb: View USB device -v: View detailed information
Ismod: View loaded module (driver)
26.4. Shutdown and restart
shutdown Shutdown and restart the computer
shutdown[关机、重启]时间 -h 关闭计算机 -r:重启计算机
如:立即关机:shutdown -h now
10 分钟后关机:shutdown -h +10
23:30 分关机:shutdown -h 23:30
立即重启:shutdown -r now
poweroff:立即关闭计算机
reboot:立即重启计算机
26.5、归档、压缩
zip:压缩文件 zip liuyazhuang.zip myfile 格式为:“zip 压缩后的 zip 文件文件名”
牛逼啊!接私活必备的 N 个开源项目!赶快收藏
Copy after login
Copy after login
unzip:解压文件 unzip liuyazhuang.zip
gzip: compressed file gzip file name
tar: archive file
tar -cvf out.tar liuyazhuang pack one Archive (package the file "liuyazhuang" into an archive)
tar -xvf liuyazhuang.tar Release an archive (release the liuyazhuang.tar archive)
tar -cvzf backup.tar.gz/etc
#-z parameter gzip compresses the archived archive file to reduce the size.
-c: Create a new tar file
-v: Display information about the running process
-f: Specify the file name
-z: Call the gzip compression command for compression
-t: View the contents of the compressed file
-x: Unzip the tar file
tar -cvf test. tar *: Pack all files into test.tar, the extension .tar needs to be added by yourself
tar -zcvf test.tar.gz *: Pack all files into test.tar , and then use the gzip command to compress
##tar -tf test.tar: Check which files are included in the test.tar file
tar -xvf test.tar Unzip test.tar
tar -zxvf foo.tar.gz Unzip
gzip Each gunzip command
gziptest.txt: When compressing a file, no parameters are required
gizp–l test.txt.gz: Display compression rate
26.6. Search
locate: Quickly find files and folders: locate keyword
This command requires a database to be established in advance , the database is updated once a day by default, and the updatedb command can be used to manually create and update the database. Welcome to follow us, the official account will last forever.
find Find location search parameters
For example:
find . -nameliuyazhuangFind files with "liuyazhuang" in their names in the current directory
find / -name *.conf Find files with the suffix .conf in the root directory (the entire hard disk)
find / -perm 777 Find all files with permission 777
find / -type d Return all directories under the root directory
find . -name "a*"-exec ls -l {} ;
find Function: Used to find files or directories.
Format: find [
][matching condition]
find / -name httpd.conf Search the system root directory File named httpd.conf
26.7, ctrl c: terminate the current command
##26.8, who or w command
Function: Check which users are logged in in the current system
Format: who/w[parameter]
26.9, dmesg command
Function: Display system diagnostic information, operating system version number, physical memory size and other information
26.10, df command
Function: Used to check the occupancy of each partition of the file system
26.11, du command
Function: View the amount of hard disk space used by subdirectories at all levels in a directory
##Format: du [parameter]
;
26.12, free command
Function: Used to check the size and occupancy of system memory and virtual memory (swap space)
27. VIM
VIM is a powerful command line text editor. The vim editor can be started through the vim command in Linux.
Generally use vim in the form of the target file path
If the target file exists, vim will open the target file, if the target file does not exist , then vim creates and opens the file
:q: Exit vim editor
VIM mode
vim has three modes:
(1) Command mode (regular mode)
After vim is started, it enters the command mode by default. In any mode, you can return to the command mode through the esc key (you can press it several times). In the command mode, you can type different commands to complete operations such as selection, copy, paste, and undo. .
Common commands for naming patterns are as follows:
i: Insert text before the cursor;
o: In the current line Insert a new line below;
dd: delete the entire line;
yy: put the contents of the current line into the buffer (copy the current line )
n yy: Put the contents of n lines into the buffer (copy n lines)
p: Put the text in the buffer After placing the cursor (paste)
u: Undo the previous operation
r: Replace the current character
/ Search keyword
(2) Insert mode
#Press the "i" key in command mode to enter insert mode, and you can enter in insert mode Edit text content and use the esc key to return to command mode.
(3) ex mode
Press the " : " key in command mode to enter ex mode, the cursor It will move to the bottom, where you can save changes or exit vim.
Common commands in ext mode are as follows:
:w: Save the current Modify
:q: Exit
:q!: Force exit, save the modification
:x: Save and exit, equivalent to:wq
:set number Display line number
:! System command executes a system command and displays the result
:sh: Switch to the command line and use ctrl d to switch back to vim
28. Software package management command (RPM)
28.1. Installation of software packages
Use the installation mode of the RPM command to put all the components in the software package into the correct path in the system. The command to install the software package is: rpm –ivh wu-ftpd-2.6. 2-8.i386.rpm
i: Use the installation mode of rpm v: Verify file information h: Display the installation progress with
#28.2. Deletion of software packages
The deletion mode will delete all the contents of the specified software package, but does not include the changed configuration files. The command to delete the RPM software package is as follows :rpm –e wu-ftpd
Note: The software name "wu-ftpd" or "wu-ftpd-2.6.2-8 must be used here instead of the originally installed software package name.wu-ftpd-2.6.2-8. i386.rpm
28.3. Software package upgrade
The upgrade mode will install the updated version specified by the user and delete the version already installed in the system The same software package, the upgrade package command is as follows: rpm –Uvh wu-ftpd-2.6.2-8.i386.rpm –Uvh: upgrade parameters
28.4, software package update
In update mode, the rpm command will check whether the software package specified in the command line is newer than the original software package in the system. If this is true, the rpm command will automatically update the specified software package; conversely, if there is no older version of the specified software package in the system, the rpm command will not install the software package. In upgrade mode, the rpm command will install the specified software regardless of whether there is an older version in the system. Package.
To obtain relevant information about RPM software packages, you can use query mode. Use the -q parameter to query the contents of an installed software package
rpm –q wu-ftpd
Query the location where the software package is installed: rpm –ql package-name
rpm –ql xv (l parameter: display file list)
Okay, that’s it for today. I think it’s good. If you find it useful, you can bookmark it first!
The above is the detailed content of Summary of the 600 most powerful Linux commands. For more information, please follow other related articles on the PHP Chinese 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