Linux Daily Maintenance commands

Source: Internet
Author: User
Tags bz2 create directory ftp login network function readable save file time and date scp command

For programmers, mastering some basic Linux commands is essential, even if not available today, and should be used in the near future. Because Linux has a lot of commands, each command can basically be introduced in an article, so this article only summarizes some common use of commands commonly used, if there are obvious omissions or errors, please help point out, thank you! The following content is based on the test environment: Red Hat first, the server hardware configuration1, view hard disk and partition condition # fdisk-l 2, view partition space usage can see each partition size, used, available, percent used, mount 1) The default unit is k# DF 2) More readable display, such as Unit m, G etc # df-h 3, View memory information 1) using the free command, the default unit is K, which can be displayed by combining the parameters-B, K, M, respectively, by the free# free-b# free-k# free-m 2) To view the/proc/meminfo file, Can get more detailed memory information than the free command # Cat/proc/meminfo 4, CPU information 1) query CPU basic information # more/proc/cpuinfo# More/proc/cpuinfo | grep "Model Name" | Sort | Uniqmodel Name:intel (R) Xeon (r) CPU E7330 @ 2.40GHz 2) query how many CPUs (same physical ID for the same CPU) # More/proc/cpuinf o | grep "Physical ID" | Sort | Uniqphysical id:0physical id:1 3) Query the number of individual CPU cores # More/proc/cpuinfo | grep "CPU Cores" | Sort | UNIQCPU cores:6 4) Query the number of individual CPU threads (logical processors) # More/proc/cpuinfo | grep siblings | Sort | Uniqsiblings:12 second, System Information1. View System Information 1) View the kernel name # uname equivalent # UNAME-S2) view complete system information including kernel name, hostname, kernel version, processor architecture etc # uname-a 2, view redhat release information # more/etc/ Redhat-release 3, view hostname # hostname# uname-nhostname corresponding profile is/etc/sysconfig/network, if the configuration file hostname is empty, (none), localhost or localhost.localdomain, it attempts to find the mapped hostname from the/etc/hosts based on the actual IP, or use the original hostname if there is a host name. third, network configuration1. Check the status of the network service, start, stop or restart the Network service # service network status|start|stop|restart 2, display, Set Network device 1) View enabled network interface Information # IFCONFIG&NBSP;2) View all network interface Configuration # ifconfig-a 3) view Eth0 network interface configuration # ifconfig eth0  4) Enable Eth0 network interface # ifconfig eth0 up# ifup eth0 5) close Eth0 network interface # ifconfig eth0 down# ifdown eth0 6) Real-time (temporary) modify eth0 IP address #& Nbsp;ifconfig eth0 IP address  7) real-time (temporary) modify eth0 IP address, subnet mask # ifconfig eth0 IP address netmask Subnet mask   Manually modify some network interface parameters in real time, can use Ifconfig to achieve, if is to directly with the configuration file, that is, in the/etc/sysconfig/network-scripts inside the IFCFG-ETHX and other files set parameters to start, it must be through the Ifdown or ifup to achieve. Ifconfig is a command. Ifup, Ifdown, is a script that searches directly into the/etc/sysconfig/network-scripts directory for a corresponding configuration file, such as Ifup eth0, which will find the contents of the Ifcfg-eth0 file and set it up. However, since these two programs are primarily search settings files (ifcfg-ethx) to start and shut down, make sure that the ifcfg-ethx is actually in the correct directory before use, or it will fail to start. In addition, if you set the ifconfig eth0 or modify the network interface, you will no longer be able to shut down in the Ifdown eth0 way. Because Ifdown will analyze and compare the current network parameters and ifcfg-eth0 whether the match, if not, will give up this operation. Therefore, after you have modified with ifconfig, you should ifconfig eth0 down to be able to close the interface.  3, view NIC Profile network Interface profile directory:/etc/sysconfig/network-scripts, where Ifcfg-eth0 is the default first network interface, if there are multiple network interfaces in the machine, the name is based on suchPush Ifcfg-eth1, ifcfg-eth2...# more /etc/sysconfig/network-scripts/ifcfg-eth0   Iv. system service Configuration1. View the running status of all system Services # service--status-all 2, view service status, start, stop or restart Service # Services name Status|start|stop|restart 3, query, Update run level information for System Services 1) View the list of system services and the runlevel of each service # Chkconfig--list 2) Add Service # chkconfig--add Service Name 3) Delete Service # chkconfig--del Service Name 4) turn on, turn off, or reset the Opening of a RunLevel # chkconfig--level 2345 name <on|off|reset> v. Display network, process status1. Display network status 1) view sockets# netstat-l 2) View the TCP Transport protocol connection condition # NETSTAT-T 3) View UDP Transport Protocol Connectivity # Netstat-u 4) View all socket# in the current connection NETSTAT-A 5) Show Network connection status, display IP address instead of using domain name # netstat-n 6) View TCP port in listening # NETSTAT-TNLP 7) View UDP port in Listen # NETSTAT-UNLP 8) page display results # netstat -anp|more 9) To see if the port is being used # NETSTAT-NLP | grep port number 2, real-time monitoring CPU, memory, process and other usage # top input uppercase P: Sort by CPU usage descending input uppercase M: Sort by Memory utilization descending 3, Process management 1) View all processes # ps-ef# Ps-aux 2) Show all processes in the process tree format # PS- EJH 3) through grep filtering process such as find Tomcat process can generally write # Ps-ef|grep Tomcat 4) Close process close Process # Kill process number Force close Process # kill-9 process number Six, disk operation1, cd command switch directory 1) switch to the specified directory # cd/var/log 2) switch to the current user's main/home directory # CD ~ 3) switch to the previous level directory # CD. 4) Return to the recently accessed directory, this is often used to get, do not need to enter the directory yourself # cd-2, pwd command to display the current working directory # pwd 3, ls command list directory contents 1) List the current directory of files and subdirectories # ls 2) List files and subdirectories of the specified directory # ls dir 3) List the files and subdirectories of the current directory, including hidden files # ls-a 4) List details of the current directory's files and subdirectories # Ls-l 5) lists the details of the files and subdirectories of the current directory, and displays them in a more readable format # LS-LH 6) sorted by modified time in descending order # LS-LT 7 Sort in ascending order by modified time # LS-LRT vii. file and directory management1, Directory management 1) Create directory # mkdir dir 2) Delete Directory # rm-r dir Delete directory do not prompt # RM-RF dir Delete directory all files and directories # RM-RF dir/* 3) Rename, move directory if Newdir does not exist, then Olddir renamed to Newdir; if newdir exists, move Olddir to Newdir directory # mv olddir newdir 4) Copy directory if NewDir2 does not exist, A copy of the Newdir is copied as NewDir2; if NewDir2 already exists, Newdir copy will be copied to NewDir2 directory # cp-r newdir newdir2 2, File management 1) Create an empty file # Touch file.txt# > File.txt 2) Delete File # rm file.txt Delete file do not prompt # rm-f file.txt 3) Rename file # mv File.txt file5.txt 4) move File # &NBSP;MV file.txt Newdir move multiple files or directories to a specified directory, move a.txt, B.txt, C.txt, Olddir to newdir directory # MV A.txt b.txt c.txt olddir/newdir/  5) Copy files # cp old.txt new.txt copy files and directories in Newdir directory to targetDir directory # cp-r newdir/* targetdir/ 3, Find command finds a file or directory  1) look for the current directory, all files prefixed with file or subdirectory # Find-name file\* 2) Find the file and output the results to the Filelist.txt file # find- Name file\*-fprint filelist.txt 3) lists files in the directory that have changed within the last two days # Find/home-mtime 2 4) Looking for files or directories in the Dir directory that are prefixed with file. Search for up to 1 levels of subdirectories # Find dir/-name file\*-maxdepth 2 4, File command to identify the type of files or directories  1) view the types of files and directories under/home/jsam directory #&nbsP;FILE/HOME/JSAM/*&NBSP;2) View the type of the specified file or directory # file filename 5, du command displays the size of the files or directories. &NBSP;1) Displays the disk space occupied by all subdirectories in the current directory, # du 2), and displays the disk space occupied by all subdirectories in the current directory. Display size # du-b# du-k# du-m# du-h 3 in bytes, K, M, and more readable ways) displays the disk space occupied by all subdirectories in the current directory. Display up to 2 levels of subdirectories # du--max-depth=2 4) Displays the disk space occupied by all subdirectories in the current directory. When the directory size is displayed, it does not include the size of its subdirectories, that is, the size of the directory excludes the size of the subdirectories. # du-s 5) Displays the disk space occupied by the current directory # du-s# du-sh 6) Displays the current directory, all subdirectories and files occupy the respective disk space # Du-a 7) List the largest 10 files in the current directory # Du-s * | Sort-n | Tail Note: Do not use Du-sh, although-H makes readability better, but the organization may not unify  6, sort commands to order the contents of the text file.  1) sort the contents of the file by default display # sort file.txt   2) Reverse display of file contents by default # Sort-r file.txt 3) view process, sort by default by the second column # Ps-aux | Sort-k 2 4) View process, sort by memory usage Ascending # Ps-aux | The Sort-nk 4 7, grep command is used to find strings that meet the criteria in a file, or to filter the standard input stream.  1) in the current directory, look for files with the "Java" string in the file with the extension log, # grep Java *.log 2) for all files in the current directory and subdirectories, find the file # grep-r Java * that contains the "Java" string &NBSP;3) to see if the port is being used # NETSTAT-NLP | grep port number  4) through the grep filtering process such as find Tomcat process can generally be written in this way # Ps-ef | grep tomcat 5) View the language type in the environment variable, ignoring case # Set | Grep-i lang 8, tail command output file The last part of the content  1) displays the last contents of the file (default is the last 10 lines) # tail file.txt 2) show the last 20 lines of the file # Tail-n 20 FILE.TXT&NBSP;3) Real-time monitoring log file # tail-f logs/catalina.out 9, Cat command 1) View file contents This command displays the entire file content at once # cat file.txt  2) give the line number (-B,--number-nonblank) # cat-b file.txt 3) to all lines (-N,--number) # cat-n file.txt  4) There is a continuous number of blank lines, leaving only a blank line (-S,--squeeze-blank) # cat-s file.txt 5) merge files A, b for C # cat a B >> c 6) empty Files # Cat/dev/null > G.txt 7) Create a file entry from the keyboard input and enter it, and then CTRL + C to save the file contents # Cat > file.txt 10, more Command page to display the contents of the file, one screen at a time, This command does not support backward/up-scrolling. #&nBsp;more catalina.out  after executing the more command, support a series of commands and actions: 1) ctrl+f Display next full screen 2) I space if I is specified, the following I line is displayed; otherwise, the next full screen is displayed. 3) I enter if I is specified, the following line of I is displayed; otherwise, the next line is displayed. 4) v Start/usr/bin/vi on the current line edit modify 5)/pattern search for pattern from the beginning of the cursor to the end of the file, click the N key to find the next  11, less command the command resembles the more command, but supports backward/up-flipping. # less Catalina.out When the Find command is executed, only the current string that matches the find condition is displayed (# less-g catalina.out) When the Find command is executed, all strings matching the find criteria are not displayed in the white line # LESS-G Catalina.out when performing a find command, ignore the case # Less-i catalina.out display the file contents and mark the line number of each line # Less-n catalina.out Import the data into the less command through a pipeline to read its contents, and then save it as a file # Set | Less-o outputfile.txt Show percent # less-m catalina.out display percentage, current row, and total number of rows # less-m catalina.out  after executing the less command, Supports a series of commands and actions: 1) ctrl+f Display next full screen 2) I space if I is specified, the following line I is displayed; otherwise, the next full screen is displayed. 3) I enter if I is specified, the following line of I is displayed; otherwise, the next line is displayed. Support for upper and lower keys display Upper, next line 4) v to start/usr/bin/vi on the current line edit modify 5)/pattern from the beginning of the cursor to the end of the file search pattern, lowercase n Find the next 6)? pattern searches the file header for pattern from the beginning of the cursor, Lowercase n finds the next, uppercase N in the opposite direction to find the next  12, vi command a powerful linux file editing command.  1) Enter VI command to open or create a new file and place the cursor at the beginning of the first line # VI filename.txt  Open the file and place the cursor at the end of the line # VI + filename.txt  2) Move Cursor class command h: Cursor moves to the top line of the screen  m: The cursor moves to the middle line of the screen  l: The cursor moves to the last line of the screen  0: (note the number 0) the cursor moves to the current beginning  $: The cursor moves to the end of the current line&NBSP;3) Screen Tumbling class command ctrl+f: Flip a screen to the end of the file  ctrl+b: turn to the top of the file   4) Insert text Class command I: Before the cursor  i: At the beginning of the current  a: after the cursor   A: At the end of the current line  o: A new line below the current line  o: A new line above the current line   5) Delete the command d0: Delete to the beginning of the line  d$: Delete to the end   NDD: Delete current line and its n-1 line DD: Delete current line  6) search and replace command/pattern: Search from the beginning of the cursor to the end of the file Pattern ?pattern: Search from the beginning of the cursor to the top of the file pattern  N: Repeat the last search command in the same direction  n: Repeats the last search command in the opposite direction &NBSP;:S/P1/P2: Replaces the first P1 in the current row with P2: s/p1/p2/g: Replaces all P1 in the current row with P2 instead of  :n1,n2s/ P1/p2/g: All P1 in line N1 to N2 are replaced P2 with  :g/p1/s//p2/g: All P1 in the file P2 replace  7) option set  number: Displays the line number of the current line: Set Nu (set Number): Displays the line numbers for all lines. or edit the file ~/.vimrc, add set Nu, so that the VI command to open the file, will automatically display the line number: Set Nonu (set Nonumber): Hide all lines of the line number  8) Save, Exit and other commands: W: Save the current file   X: Save current file and exit  :q: Exit vi :q!: Do not save file and exit vi :e!: Reload content    Viii. User Management1. User Management Add user # Useradd user name delete User # Userdel username Modify Current user's password # passwd modify the password of the specified user, only the root user can specify the user name # passwd user Name 2, user Group Management Add user Group # Groupadd User group name Delete user Group # Groupdel user Group name 3, view user Information View user's UID, GID and user group belonging to # id# ID User name View user Information # finger username # more/etc/passwd | grep username 4, switch user Switch User but do not switch user's environment variable su username switch user and switch user's environment variable Su-user name 5, view login user Information View currently logged in User name # WhoAmI View all users currently logged on to the system # Who view details of all users of the currently logged on System # W Nine, compression decompression1, the tar command file packaging, decompression command, can be combined with a variety of algorithms packaged after compression 1) All files and directories under the current directory are packaged as my.tar# tar-cf My.tar.  2) package directory/home/jsam and display the command execution process (-V) # &NBSP;TAR-CVF jsam.tar/home/jsam 3) package directory log and check that the backup file is correct (-W) # TAR-CVWF Log.tar log 4) package the directory log and compress it with the gzip command # TAR-CZVF log.tar.gz log 5) Unzip the tar package # TAR-XVF foo.tar 6) Unzip the gzip Compression Pack # TAR-XZF foo.tar.gz 7) Create bzip2 Zip package # TAR-CJ F foo.tar.bz2 bar/ 8) unzip the BZIP2 compressed package and store the extracted content in the bar directory, the bar directory must already exist # TAR-XJF Foo.tar.bz2-c bar/  9) Extract index.html files from gzip package # TAR-XZF foo.tar.gz index.html 2, zip command zip package compression Command 1) Compress all files and subdirectories in the current directory # zip-r First.zip *  3, Unzip command zip package decompression command. Can extract Java War Project package 1) Extract files directly into the current directory # unzip first.zip 2) extract the index.html file from the ZIP package # unzip first.zip index.html  3) unzip the zip package into dir directory # unzip first.zip -d dir 4, bzip2 command bzip2 package compression, decompression command 1) zip file # bzip2 file.20130126# bzip2- z file.20130126 Result: file.20130126 compressed to file.20130126.bz2, and delete the source file, before and after the file modification time is not changed  2) unzip the file # bzip2 -d  FILE.20130126.BZ2 Result: file.20130126.bz2 is reduced to file.20130126, and the source file is deleted and the file is modified before and after it is decompressed.Between the same    10. Permission Settings1. chmod command to change permissions for a file or directory. Description: U: The file or directory owner g: File or directory of the group O: other users R: Read permission, the number code is "4" w: Write permission, the number code is "2" x: Execute permissions, the number code is "1"-: no permission, the number code is "0" read, Write and execute the number code can be added to form a combination of permissions, such as 6, 5, 3, 7 for reading and writing, read execution, write execution, read and write execution permissions 1) Add Write permission to the group to which the file belongs # chmod g+w filename.txt 2) Increase all user execution rights to files # chmod +x Filename.txt 3) Cancel all user execute permissions on file # chmod a-x filename.txt 4) Set file owner read and Write permissions, group read and write permissions, other people reading permissions # chmod 664 filename.txt 5) Set the file owner read and write execution permissions, the group read Execute permission, the other people do not have any permissions # chmod u=rwx,g=rx,o=-filename.txt 2, chown command to change the file or directory owner or owning group. 1) Change file owner is User1, owning group is group1# chown user1.group1 filename.txt 2) Change owner and owning group of all files and subdirectories under dir directory # chown-r User1.group1 dir 3) Change the file owner # chown Zhanjia A.C The owner of the file A.C changed to Zhanjia 3, chgrp command to change the file or directory belongs to the group. 1) Change the owning group of the file to jsam# chgrp Jsam tomcat6.0.35.tar.gz 2) Changing the owning group of all files and subdirectories under dir directory # chgrp-r Jsam dir/ 11. File Transfer1, FTP command 1) FTP Login Server # FTP host address  2) download file download single file ftp> get file.txt download multiple files Ftp> mget *.txtftp> mget File1.txt file2.txt 3) Upload a file on a flyer file ftp> put file.txt upload multiple files ftp> mput *.txtftp> mput File1.txt file2.txt 4) Mget, Mput, Mdelete and other batch operations prompt switch settings ftp> prompt on|off 5) Delete remote files delete remote files ftp> Delete file.txt remove multiple remote files ftp> mdelete file1.txt file2.txt 6) remote directory Management is established remotely directory ftp> mkdir dir Delete remote directory ftp>  rmdir dir renames a remote file or directory ftp> rename src dest 7) executes the specified command on the local side (client Linux). This command is useful, you can view the local side of the situation without exiting the FTP syntax:!< command >ftp>!lsftp>!dir 8) Other commands help < command >,? < command;: Help command, do not specify < command > list all available action commands ASCII, ASC: Sets the mode of transmitting data to ASCII mode, for transferring text files binary, Bin: The mode of transmitting data is set to binary mode, For transfer Program Files LS, CD, PWD: General usage is the same as the Linux command user < username;: Login to FTP server with specified user account and password bye: Exit ftp 2, SCP command remote file Security Copy command. The data transfer uses SSH and uses the same authentication method as SSH, providing the same security guarantee. Syntax: SCP [Options] [[[Email protected]]host1:]file1 [...] [[[Email protected]]host2:]file2 General usage: SCP [optional] source file/directory destination file/directory  1)Download file download remote file to current directory SCP [email protected]:/opt/server/apache-tomcat-6.0.35.tar.gz. Download the remote file as a local file/root/ TOMCAT6.0.35.TAR.GZSCP [email protected]:/opt/server/apache-tomcat-6.0.35.tar.gz/root/tomcat6.0.35.tar.gz &NBSP;2) upload the file to the remote directory SCP tomcat6.0.35.tar.gz [email protected]:/opt/ 3) download directory to download the remote directory to the current directory scp-r [email  protected]:/opt/server. If/root/client does not exist, download/opt/server as/root/client, and if present, download/opt/server to/root/ Client subdirectory Scp-r [email protected]:/opt/server/root/client 4) can synchronize files and directories of both servers by specifying the source, destination IP, SCP [email  protected]:/root/tomcat6.0.35.tar.gz [email protected]:/opt/software/ 3, wget command to download files from the Internet. Download www.iteye.com Home # wget www.iteye.com download File # wget http://www.fayea.com/apache-mirror/tomcat/tomcat-6/v6.0.36/ Bin/apache-tomcat-6.0.36.zip Breakpoint Continuation # wget-c http://www.fayea.com/apache-mirror/tomcat/tomcat-6/v6.0.36/bin/ Apache-tomcat-6.0.36.zip background download, generate log file wget-log# wget-b http://www.fayea.com/apache-mirror/tomcat/tomcat-6/v6.0.36 /bin/apache-tomcat-6.0.36.zip   12, other commands 1. The WC command calculates the number of words. You can calculate the number of bytes, words, characters, or lines of a file. 1) Calculate the number of file lines # wc-l messages.txt 2) Calculate the number of bytes in a file # wc-c messages.txt 3) Number of files by pipeline # LS | wc-l 2, rpm command RPM Package Management Command  1) install RPM package # RPM-IVH gcc.rpm 2) Upgrade RPM Package # RPM-UVH gcc.rpm 3) Uninstall RPM Package # RPM-E gcc& nbsp;4) query installed RPM Package # rpm-qa 3, find History command 1) The historical command shows the executed command # history  executes the command # 158 #!158 2) by CTRL + R performs a reverse lookup of the command combination key ctrl+r, enter the query string, and then repeat the combination of key ctrl+r for reverse lookup. CTRL + C: Cancel find ESC: End lookup, get the found command enter: Directly perform the lookup to the command  4, md5sum command calculation file MD5 message digest # md5sum filename.txt 5, Set command query or SET environment variable  1) query current environment variable # set 6, mount command mount file system  1) attach/dev/hdb1 to/mnt/hdb1# mount/dev/hdb1/mnt/hdb1 &NBSP;2) mount the/DEV/HDB1 to/MNT/HDB1 and specify to load the Vfat file system # mount-t vfat/dev/hdb1/mnt/hdb1 7, umount command unmount file system   1) Uninstall the file system # umount /dev/hdb1 8, Nohup command to run the command, combined with & can implement the user to exit the terminal or logoff, the program has been running in the background. # nohup./start.sh & 9, Date command displays or sets the system time and date. &NBSP;1) Displays the date and time of the current system # Date# date "+%y-%m-%d%h:%m:%s"  2) set the system time and date # date-s "2013-2-10 12:59:00" # date-s " 2013/2/10 "# date-s" 2014-3-12 "# date-s" 12:59:00 " 10 ssh telnet login # SSH user name @ip address  11, ping command detection host, usually used to detect the host network function is normal, the network between the two hosts is not a pass &NBSP;1) continuously detects IP until the user actively ends # ping 192.168.0.100 2) emits 5 ping packets for detection # ping-c 5 192.168.0.100 12, telnet command telnet command  1) login Host # telnet 192.168.0.100 2) Check if TCP port 8080 is listening on # telnet 192.168.0.100 8080    In the writing process of this article, we find that the more content we write, the more I write. Because the Linux commands are very powerful, it seems that each command is very important, but the pursuit of chatty is not the original intention of this article, so we recommend you according to the actual environment and their own habits, form a can carry with the view of the small manual.

Linux Daily Maintenance commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.