Common Linux Commands

Source: Internet
Author: User
Tags bz2 cpu usage

Delete: Rm-rf./jsp/(Delete JSP folder and all sub-files in this directory)
Graphics switch to command interaction mode: CTRL+ALT+F1
Go to the JSP folder under directory: CD folder name or CD./jsp
Return to the previous level: CD.
Switch User: SU user name
New User: Useradd user name
Change Password: passwd user name
. Tar unpacking: Tar xvf Filename.tar
. Tar package: Tar cvf filename.tar DirName
Find directory: Find/(Look in)-name ' find keyword '-type d
Find JDK path: which Java; query Java_home variable value: Echo $JAVA _home
Find files: Find/(Look in)-name look up keywords-print
Finding files: Whereis my.cnf
The location of the hosts file is/etc/hosts
Linux to see the number of CPUs: Cat/proc/cpuinfo View physical ID There are several
Df-h viewing hard disk space
Free-m output memory by megabytes, unused, total, etc.
View that process takes up the XXX port: lsof-i:xxx
See where the process of process number XXX is: ps-ef|grep xxx
View CPU Usage: Top (RES: Process-occupied physical memory,%CPU: Process consuming CPU utilization)
VI exit Edit, first Esc->:wq save and exit, Q exit does not save
chmod u+x Changing the access mode of one or more files (u user, x execution)
Check URLs can be accessed: wget Http://10.150.75.43:8080/PMS
Telnet 10.150.75.43 80
Modify host Name: temporary vi/etc/hosts
Shutdown: Halt immediately shutdown, shutdown-h 10 10 minutes after auto power off

Create folder: mkdir filename
Create file: Touch filename
--
The shutdown and restart commands are as follows:
1, halt immediately shut down the machine
2, Poweroff immediately shut down the machine
3, Shutdown-h now immediately shut down (root user use)
4, shutdown-h 10 10 minutes after the automatic shutdown
5, Shutdown-r now restart
If you set the shutdown through the shutdown command, you can cancel the restart with the Shutdown-c command.
---
Use Vim to modify the file error, the system prompts the following:
E37:no write since last change (add! To override)
Cause of failure: The file is read-only and cannot be modified.
WORKAROUND: Use the command: w! to force the disk, in Vim mode, type the following command:
: w!
-------
Querying and killing inforsuite processes
Ps-ef|grep Java
Kill-9 73086 73061 71995

---

Start Middle-gen middleware and add processes to the backend: Nohup/home/inforsuite/appserver/as/bin/startserv >/home/inforsuite/startlog.log &
------------------------------------------------------------------------------------------
20 commonly used commands.


1. CD command
This is a very basic, is also a common need to use the command, it is used to switch the current directory, its parameters are to switch to the path of the directory, can be an absolute path, can also be a relative path. Such as:
Cd/root/docements # Switch to directory/root/docements
cd./path # Switch to the path directory in the current directory, "." Represents the current directory
Cd.. /PATH # Switch to the path directory in the upper directory, "..." Represents a previous level of directory

2. ls command
This is a very useful view of the file and directory commands, List of meaning, it has a lot of parameters, the following list some of my commonly used parameters, as follows:
-L: Lists Long data strings, including file attributes and permission data, etc.
-A: Lists all the files, together with hidden files (files that begin with.) (common)
-D: Lists only the directory itself, not the file data for the directory
-H: List the file capacity in a more readable way (GB,KB, etc.)
-R: Listed along with the contents of the subdirectory (recursively listed), equal to all the files in that directory will be displayed note: These parameters can also be used together, the following two examples:
Ls-l #以长数据串的形式列出当前目录下的数据文件和目录
LS-LR #以长数据串的形式列出当前目录下的所有文件

3. grep command
This command is often used to parse a row of information, if there is information we need, the row is displayed, the command is usually used with the pipeline command, for the output of some commands to filter processing, etc., its simple syntax is
grep [-ACINV] [--color=auto] ' find string ' filename its common parameters are as follows:
-A: Find data in a binary file as a text file
-C: Calculate the number of times to find ' find string '
-I: Ignore case differences, that is, case is considered the same
-V: Reverse selection, which shows the line without the ' Find string ' content
For example
# Remove the line containing Manpath in the file/etc/man.config and add color to the Found keyword
grep--color=auto ' MANPATH '/etc/man.config
# put the output of ls-l with the letter file (case-insensitive) content output
Ls-l | Grep-i file

4. Find command
Find is a very powerful search-based command, relatively speaking, its use is relatively complex, parameters are also more, so here will be to classify them, its basic syntax is as follows:
Find [PATH] [option] [action]

# time-related parameters:
-mtime N: = n is a number, meaning a file that has been changed in "One Day" before the nth day;
-mtime +n: Lists the file names that were changed before n days (excluding the N-day itself);
-mtime-n: Lists filenames that have been changed within n days (including n days themselves);
-newer file: List file names that are newer than file
For example
Find/root-mtime 0 # Find files that have changed within the current directory today

# parameters related to user or user group name:
-user Name: List files with file owner name
-group Name: List files that belong to the user group named name
-uid N: List file owner as User ID n
-gid N: Lists files that belong to the user group whose user group ID is n
For example
Find/home/ljianhui-user Ljianhui # Find the owner-Ljianhui file in the directory/home/ljianhui

# Parameters related to file permissions and names:
-name FileName: Find the file named filename
-size [+-]size: Find a file larger than size (+) or small (-)
-tpye Type: Find file of type of file, the value of type is mainly: General file (f), device file (b, C),
Directory (d), connection file (L), socket (s), FIFO pipeline file (p);
-perm mode: Find file permissions just equal to the mode file, mode is represented by a number, such as 0755;
-perm-mode: Find file permissions must all include the mode permission of the file, mode is represented by a number
-perm +mode: Find file Permissions file that contains the permissions of either mode, mode is represented by a number
For example
Find/-name passwd # Finding files with file name passwd
Find. -perm 0755 # 0755 file to find file permissions in the current directory
Find. -size +12k # Find files larger than 12KB in the current directory, note that C means byte

5. CP command
This command is used to copy the file, copy the meaning, it can also copy multiple files to a directory at one time, its common parameters are as follows:
-A: Copy the attributes of the file together
-P: Copied along with the properties of the file, not by default, similar to-a, often used for backup
-I: If the target file already exists, the action will be asked before overwriting
-R: Recursive continuous Replication for directory replication behavior
-U: The destination file is copied when it differs from the source file, for example:
Cp-a file1 file2 #连同文件的所有特性把文件file1复制成文件file2
CP file1 file2 file3 dir #把文件file1, file2, file3 copy to directory dir

6. MV Command
This command is used to move a file, directory, or rename, and its common parameters are as follows:
-f:force mandatory Meaning, if the target file already exists, will not ask and directly overwrite
-I: If the target file already exists, you will be asked to overwrite
-U: If the target file already exists and is newer than the target file, note: The command can move a file or multiple files one folder at a time, but the last target file must be "directory".


For example:
MV File1 file2 file3 dir # move the file file1, File2, file3 to the directory dir
MV File1 file2 # Rename the file file1 to File2

7. RM command
This command is used to delete files or directories, between remove, and its common parameters are as follows:
-F: Force means ignoring files that do not exist and warning messages are not present
-I: Interactive mode, ask the user whether to operate before deleting
-R: Recursive deletion, most commonly used for directory deletion, is a very dangerous parameter such as:
Rm-i File # To delete files, ask for the action before deleting
RM-FR dir # force removal of all files in directory dir

8. PS command
This command is used to select and output the process run at a point in time, and its common parameters are as follows:
-A: All processes are displayed
-A: All processes not related to terminal
-U: Related processes for effective users
-X: Generally used in conjunction with a parameter to list more complete information
-L: Longer, more detailed PID information listed in fact, we just remember PS general use of command parameters can be, they are not many, as follows:
PS aux # View all process data for the system
PS Ax # View all processes not related to terminal
Ps-la # View all process data for the system
PS AXJF # View together with a subset of process tree states

9. Kill command
This command is used to send a signal to a job (%jobnumber) or to a PID (number), which is typically used with the PS and jobs commands, with the following basic syntax:
The common parameters of Kill-signal pidsignal are as follows:
Note: The first number is the signal code, use can be used to replace the corresponding signal code.
1:sighup, start the terminated process
2:sigint, equivalent to input CTRL + C, interrupts the process of a program
9:sigkill, forcing the interruption of a process
15:sigterm to terminate the process with normal end-of-process mode
17:sigstop, equivalent to input CTRL + Z, pauses a process for example:
# at the end of the normal process to finally the first background work, you can use the Jobs command to view the background of the first worker process
Kill-sigterm%1
# re-change process ID to PID process, PID can be filtered using the PS command with the command of the command plus grep
Kill-sighup PID10, Killall command
This command is used to send a signal to a process initiated by a command whose general syntax is as follows:
Killall [-iie] [command name] its parameters are as follows:
-I: interactive meaning, if need to delete, will ask the user
-E: Indicates that command name is followed by the same, but command name cannot exceed 15 characters
-I: Command name ignores case
For example
Killall-sighup syslogd # Restart Syslogd11, File command
This command is used to determine the basic data of files after the file command, because the type of the file under Linux is not the suffix of the future, so this command is very useful for us, its usage is very simple, the basic syntax is as follows:
File filename
#例如:
File./test

12. Tar command
This command is used to package the file, which is not compressed by default and, if specified, it also invokes the appropriate compression program (such as Gzip and bzip) for compression and decompression. Its common parameters are as follows:
-C: New package file
-T: See what file names are included in the contents of the packaged files
-X: Unpacking or decompression function, can be used with-C (uppercase) to specify the extracted directory, note-c,-t,-x cannot appear in the same command
-J: Compression/decompression via BZIP2 support
-Z: Compression/decompression with GZIP support
-V: Displays the file name being processed during the compression/decompression process
-F filename:filename for files to be processed
-C dir: Specifies the compressed/decompressed directory The above explanation can already make you dizzy, but usually we just need to remember the following three commands:
Compression: Tar-jcv-f filename.tar.bz2 The name of the file or directory to be processed
Enquiry: Tar-jtv-f filename.tar.bz2
Decompression: Tar-jxv-f filename.tar.bz2-c to extract the directory Note: The file name is not set to the end of the suffix tar.bz2, here is mainly to illustrate the use of the compression program for the BZIP2


13. Cat Commands
This command is used to view the contents of a text file, followed by the name of the file to be viewed, and is typically used in conjunction with more and less to allow you to view the data one page at a time. For example:
Cat text | Less # View the contents of the text file
# Note: This command can also use less text instead

14. CHGRP command
This command is used to change the user group to which the file belongs, it is very simple to use, its basic usage is as follows:
CHGRP [-R] Dirname/filename
-R: Recursive persistent changes to all files and subdirectories
For example
Chgrp users-r./dir # Recursively modifies the user group for all files and subdirectories under the Dir directory to users

15. Chown Command
The command is used to change the owner of the file, using the same method as the CHGRP command, except that the modified file attributes are different and are no longer detailed.
For example: Chmod-r 777/www/itbulu.com/wp-content/*
The representative sets all the files in the above folder to read and write
16. chmod command
This command is used to change the permissions of a file, as follows:
chmod [-r] XYZ file or directory
-R: Continuous change of recursion, that is, all files under the subdirectory are changed simultaneously, chmod can also use U (user), G (group), O (Other), a (all) and + (join),-(delete), = (set) with rwx to make changes to the permissions of the file.


For example
chmod 0755 File # Changes files permissions to-rxwr-xr-x
chmod g+w File # Adds a user group writable permission to files ' permissions

18. Vim Command
This command is primarily used for text editing, which takes one or more file names as parameters, opens if the file exists, and creates a file with the file name if it does not exist. Vim is a very useful text editor, it has a lot of very useful commands, here no longer say. You can download a detailed description of VIM's common operations from here.


19. GCC command
For a person who developed a C program with Linux, this command is very important, it is used to compile the C language source program files, compiled into an executable program, because many parameters of g++ and it very similar, so here only the parameters of the GCC, its common parameters are as follows:
-o:output, used to specify the file name to generate an executable file
-C: Used to generate a target file (. o) from the source file and prevent the compiler from creating a complete program
-I: Increase the path of the search header file at compile time
-L: Increase the path of the search static connection library at compile time
-S: Generate assembly code files for source files
-LM: A library of libraries named LIBM.A in the directory that represents the standard library
-lpthread: Connecting NPTL-Implemented lines libraries
-std=: Used to specify the version of the C language to use

For example
# Compile the source file test.c into executable program test according to C99 standard
Gcc-o Test Test.c-lm-std=c99
#把源文件test. c conversion to the appropriate assembler source file Test.s
Gcc-s test.c20, Time command
This command is used to measure the execution time of a command (that is, a program). It's very simple to use, just like you would normally enter a command, but add a time to the front of the command, for example:
Time./process
Time PS aux after the end of the program or command run, at the last output of three times, they are:
User: CPU time, the user CPU time that the command executes, that is, the command executes the sum of time in the user state;
System: CPU time, the system CPU time that the command executes, that is, the command executes the sum of time in the kernel mentality;
Real: The actual time, from the command line to start execution to the end of the elapsed time;


Note: The sum of CPU time and system CPU time is CPU time, that is, the total amount of time the command consumes CPU execution. The actual time is greater than the CPU time, because Linux is a multitasking operating system, often when executing a command, the system also handles other tasks. Another problem to be aware of is that even though the same command is executed every time, the time spent is not the same, and the time spent is related to the operation of the system.

Common Linux Commands

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.