Common Liunx commands and common liunx commands

Source: Internet
Author: User
Tags create directory gz file

Common Liunx commands and common liunx commands

1. Tomcat-related commands

Restart tomcat in linux and view tomcat running logs in real time

In Linux, restart Tomcat and run the command!

First, go to the bin directory under Tomcat

Cd/usr/local/tomcat/bin

Use Tomcat to close the command

./Shutdown. sh

Check whether Tomcat is disabled

Ps-ef | grep java

Or ps aux | grep tomcat

If the following similar information is displayed, Tomcat is not closed.

Root 7010 1 0 Apr19 00:30:13/usr/local/java/bin/java-Djava. util. logging. config. file =/usr/local/tomcat/conf/logging. properties-Djava. awt. headless = true-Dfile. encoding = UTF-8-server-Xms1024m-Xmx1024m-XX: NewSize = 256 m-XX: MaxNewSize = 256 m-XX: PermSize = 256 m-XX: MaxPermSize = 256 m-XX: + DisableExplicitGC-Djava. util. logging. manager = org. apache. juli. classLoaderLogManager-Djava. endorsed. dirs =/usr/local/tomcat/endorsed-classpath/usr/local/tomcat/bin/bootstrap. jar-Dcatalina. base =/usr/local/tomcat-Dcatalina. home =/usr/local/tomcat-Djava. io. tmpdir =/usr/local/tomcat/temp org. apache. catalina. startup. bootstrap start

* If You Want To directly kill Tomcat, you can use the kill command to directly kill the Tomcat process.

Kill-9 7010

Check whether Tomcat is disabled.

Ps-ef | grep java

If the following information is displayed, Tomcat is disabled.

Root 7010 1 0 Apr19 00:30:30 [java]

Finally, start Tomcat

./Startup. sh

Note: Use the root user to log on to the Linux system. Enter the Tomcat directory correctly. Restart Tomcat after you confirm that Tomcat is disabled. Otherwise, an exception occurs when the port is occupied.

View tomcat logs

1. Switch to: cd usr/local/tomcat5/logs

2. tail-f catalina. out

3. In this way, you can view the running logs in real time.

Ctrl + c is the exit command.

However, when you use a linux ip address for external access, you will find that it fails, because by default, the linux firewall is enabled, and only after the system is installed, there are several special ports that can be accessed externally. If the software installed later needs to be accessed through an external port, there are two solutions: 1. run the command: sevice iptables stop to stop the Firewall service. However, when you start the linux system, the firewall restarts. 2. the most fundamental solution is to add a port number rule that requires external access to the firewall rule, and use the following command to implement it: first enter the command: /sbin/iptables-I INPUT-p tcp -- dport 8080-j ACCEPT to edit the firewall rule file, and then enter the command:/etc/rc. d/init. d/iptables save to the iptables file and enter the command: service iptables restart to restart the Firewall service so that the newly added rule takes effect.

Configure the default access path

2. Common commands

Ls display file or directory

-L list file DETAILS l (list)

-A: List all files and directories in the current directory, including hidden a (all)

Mkdir create directory

-P: Creates a directory. If no parent directory exists, p (parent) is created)

Cd switch directory

Touch creates an empty file

Echo creates a file with content.

Cat View File Content

Cp copy

Move or rename music videos

Rm delete file

-R recursively deletes sub-directories and files.

-F force Delete

Find searches for a file in the file system

Wc counts the number of rows, words, and characters in the text

Grep searches for a string in a text file.

Rmdir Delete empty directory

Tree structure display directory, you need to install the tree package

Pwd displays the current directory

Ln create link file

More and less display text file content by PAGE

Head and tail show file header and tail content

Ctrl + alt + F1 command line full screen mode

3. system management commands

Stat displays the details of the specified file, which is more detailed than ls.

Who displays online login users

Whoami displays the current user

Hostname display Host Name

Uname: displays system information

Top dynamically displays the process information that currently consumes the most resources

Ps displays the Instantaneous Process status ps-aux

Du: view the directory size. du-h/home displays the directory information in units.

Df view disk size df-h Displays disk information in units

Ifconfig

Ping test network connection

Netstat displays network status information

The man Command won't be used anymore. Look for a man like man ls.

Clear Screen

Alias rename the command, for example, alias showmeit = "ps-aux", and unaliax showmeit

Kill to kill a process. You can view the process id with the ps or top command, and then kill the process with the kill command.

4. Compress related commands

Gzip:

Bzip2:

Tar: Package and Compression

-C. archive file

-X compressed file

-Z gzip compressed file

-J bzip2: compressed file

-V shows the compression or decompression process v (view)

-F indicates the file name.

Example:

Tar-cvf/home/abc.tar/home/abc Package only, not compressed

Package tar-zcvf/home/abc.tar.gz/home/abc and compress it with gzip

Package tar-jcvf/home/abc.tar.bz2/home/abc and compress it with bzip2

If you want to decompress the package, replace "c" in the tar-cvf/tar-zcvf/tar-jcvf command with "x.

5. Shut down/restart the machine

Shutdown

-R: shutdown and restart

-H Shutdown without restarting

Now shut down immediately

Halt Shutdown

Reboot restart

6. Linux Pipelines

Use the standard output of one command as the standard input of another command. That is, several commands are combined for use, and the result of the last command is exclusive to the previous one.

For example, grep-r "close"/home/* | more searches for all files in the home directory, including close files, and outputs them by page.

7. Linux software package management

Dpkg (Debian Package) management tool. The Package name is suffixed with. deb. This method is suitable when the system cannot be connected to the Internet.

For example, to install the installation package of the tree Command, first upload tree. deb to the Linux system. Run the following command to install the SDK.

Sudo dpkg-I tree_1.5.3-1_i386.deb Installation Software

Sudo dpkg-r tree uninstall software

Note: There are multiple methods to upload tree. deb to Linux. VMwareTool, using the mounting method; using the winSCP tool;

APT (Advanced Packaging Tool) Advanced software tools. This method is suitable when the system can connect to the Internet.

Tree is used as an example.

Sudo apt-get install tree installation tree

Sudo apt-get remove tree uninstall tree

Sudo apt-get update Software

Sudo apt-get upgrade

Convert the. rpm file to the. deb file.

. Rpm is the software format used by RedHat. It cannot be used directly in Ubuntu, so you need to convert it.

Sudo alien abc. rpm

8. Use vim

Vim mode: Command mode, insert mode, and edit mode. Use ESC or I or: to switch the mode.

In command mode:

: Q exit

: Q! Force exit

: Wq save and exit

: Set number: displays the row number.

: Set nonumber hide row number

/Apache finds in the document that apache jumps to the next one by pressing n, shift + n

Copy and paste the row where the cursor is located.

H (move one character to the left), j (next line), k (last line), l (move one character to the right →)

9. User and User Group Management

/Etc/passwd storage User Account

/Etc/group storage group account

/Etc/shadow stores the password of the user account

/Etc/gshadow: password used to store user group accounts

Useradd Username

Userdel Username

Adduser User Name

Groupadd group name

Groupdel group name

Passwd root SET Password for root

Su root

Su-root

/Etc/profile system environment variable

Bash_profile user environment variables

. Bashrc user environment variable

Su user switches users and loads the configuration file. bashrc

Su-user: Switch the user, load the configuration file/etc/profile, and load the bash_profile

Users and user groups who change files

Sudo chown [-R] owner [: group] {File | Directory}

For example, jdk-7u21-linux-i586.tar.gz is used as an example. Belong to user hadoop, group hadoop

To switch the user and group to which the file belongs. You can use commands.

Sudo chown root: root jdk-7u21-linux-i586.tar.gz

10. File Permission Management

Three basic Permissions

The R read value is 4.

W write value is expressed as 2

X executable value is 1

The permission for the jdk-7u21-linux-i586.tar.gz file is-rw-r --

-Rw-r -- a total of 10 characters, which are divided into four segments.

The first character "-" indicates a common file. This location may contain "l" links, and "d" indicates a directory.

The second, third, and fourth characters "rw-" indicate the permissions of the current user. Therefore, the value is 4 + 2 = 6.

The fifth, sixth, and seventh characters "rw-" indicate the permissions of the current group. Therefore, the value is 4 + 2 = 6.

The 80 or 90 character "r --" indicates other user permissions. So the value is 2.

Therefore, the permission to operate this file is expressed as 662 in numerical values.

Change permissions

Sudo chmod [u user g owner group o other user a all users] [+ add permissions-Reduce permissions] [r w x] Directory Name

For example, if you have a file filename with the "-rw-r ---- x" permission, change the permission value to "-rwxrw-r-x", and the value is 765.

Sudo chmod u + x g + w o + r filename

The preceding example can be represented by numerical values.

Sudo chmod 765 filename

11. Disable Firewall

11.1

1) takes effect after restart

Enable: chkconfig iptables on

Close: chkconfig iptables off

2) takes effect immediately and becomes invalid after restart

Enable: service iptables start

Disable: service iptables stop

You can use the preceding command to enable or disable other services in Linux.

When the firewall is enabled, make the following settings to enable the relevant ports,

Modify the/etc/sysconfig/iptables file and add the following content:

-A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT

-A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 22-j ACCEPT

11.2 CentOS 7.0 disable Firewall

CentOS 7.0 uses firewall as the firewall by default. You must reset it when using iptables.

1. Directly disable the Firewall

Systemctl stop firewalld. service # stop firewall

Systemctl disable firewalld. service # disable firewall startup

2. Set iptables service

Yum-y install iptables-services

If you want to modify the firewall configuration, such as adding the firewall port 3306

Vi/etc/sysconfig/iptables

Add Rules

-A input-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT

Save and exit

Systemctl restart iptables. service # restart the firewall to make the configuration take effect.

Systemctl enable iptables. service # Set firewall startup

Restart the system to make the settings take effect.

12. Network

Service network restart Nic

13. File Upload

-Bash: rz: command not found

Rz command not found

Run the sz command.

Install lrzsz:

# Yum-y install lrzsz

Now you can use the rz and sz commands to upload and download data.

Usage:

Upload files

# Rz filename

Download files

# Sz filename

14. compression and decompression

Tar command

Unpack: tar zxvf FileName.tar

Package: tar czvf FileName.tar DirName

Gz command

Decompress 1: gunzip FileName.gz

Decompress 2: gzip-d FileName.gz

Compression: gzip FileName

.Tar.gz and. tgz

Decompress: tar zxvf FileName.tar.gz

Compression: tar zcvf FileName.tar.gz DirName

Compress multiple files: tar zcvf FileName.tar.gz DirName1 DirName2 DirName3...

Bz2 command

Decompress 1: bzip2-d FileName.bz2

Decompress 2: bunzip2 FileName.bz2

Compression: bzip2-z FileName

.Tar.bz2

Decompress: tar jxvf FileName.tar.bz2

Compression: tar jcvf FileName.tar.bz2 DirName

Bz command

Extract 1: bzip2-d FileName. bz

Decompress 2: bunzip2 FileName. bz

Compression: Unknown

. Tar. bz

Decompress: tar jxvf FileName.tar. bz

Z command

Decompress: uncompress FileName. Z

Compression: compress FileName

. Tar. Z

Decompress: tar Zxvf FileName.tar. Z

Compression: tar Zcvf FileName.tar. Z DirName

Zip command

Decompress: unzip FileName.zip

Compression: zip FileName.zip DirName

15. Vi editor commands

L move the cursor in addition to the upper, lower, and lower buttons on the keyboard. It can also be in lowercase mode. "h, j, k, l" on the keyboard ",

"Ctrl + B": move one page behind the screen

"Ctrl + f": Move the screen one page forward

"Ctrl + u": half page behind the screen

"Ctrl + d": Move the screen half page forward

Enter any integer, and then enter "shift + G" to start the page.

Press the upper case "G" on the keyboard to move to the end of the article.

Move the cursor to the end of the line by the "$" symbol

"^" Move the cursor to the line Header

"W": move the cursor to the next line

"B": opposite to "w". Move to the header of the previous row

"E": move the cursor to the end of the next line.

If you want the text to display the row number, enter the ": set nu" command at the end of the text in command line mode.

L copy

"Yw": copy the character at the end of the cursor to the buffer zone.

"Yy": copy the row where the cursor is located to the buffer zone.

"# Yy": for example, "6yy" indicates copying 6 lines of text from the row where the cursor is located "down.

P: place the characters in the buffer to the cursor position. Note: All copy commands related to "y"

Must work with "p" to complete the copy and paste Function

L search

Use "/" to add the content to be searched. For example, "/hello" or "hello.

L Replacement

"R": Replace the character at the cursor position. Click "r" and enter the name.

"R": Replace the character wherever the cursor goes until you press the "ESC" key.

L restore the last operation

"U": If you mistakenly execute a command, you can immediately press "u" to return to the previous operation.

Press "u" multiple times to perform multiple recovery. This is equivalent to "CTRL + Z.

16. Enable Apache and Mysql

/Opt/zbox start

Run the/opt/zbox start command to enable Apache and Mysql.

Run the/opt/zbox stop command to stop Apache and Mysql.

Run the/opt/zbox restart command to restart Apache and Mysql.

17. Check whether the port is occupied

Ss-tunlp | grep-v grep | grep 8080

18. Nginx

L check whether the configuration is correct

After the configuration is modified, run the command to check whether the configuration is correct. In this way, you can exclude the invalid configuration due to incorrect configuration format and affect the stable running of the server.

Nginx-t

L configuration takes effect

After you modify the configuration, restart NGINX to take effect. If you disable NGINX and call another meeting to affect service operation, we can send a signal to Nginx to smoothly restart the service.

Kill-HUP process number

The process number is the NGINX process number, which can be viewed using the ps aux | grep nginx command.

Or use the following command to make the configuration take effect.

Nginx-s reload

Related Article

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.