Summary of Common Linux commands

Source: Internet
Author: User
Tags get ip mysql in tmp folder

directory structure of Linux files: tree-like structure,/for the highest root directory

Root:root User's personal folder (home directory)
Bin: Holds commands available to most users
Boot: Store startup files and configuration information, which will be used when the system starts
Dev: storage device file,/DEV/HDC for optical drive
ETC: Store the service configuration file
Home: Other users ' home directories
LIB: The library file required to store the program to run
Media: Mount directory for removable devices
MNT: Device Mount Directory
USR: User program storage Directory
var: storing frequently changed data files
TMP: Storing temporary files
Sbin: The command required to maintain the system, generally only available as root
Proc: Stores the files generated by the core runtime, which are located in memory and not on the hard disk
SYS: Similar to proc, the design is clearer than proc and the file is in memory
SRV: The storage directory for the data required by the service
Lost+found: Lost files recovered when file system repair
OPT: Additional Software installation directory
Misc: Miscellaneous files that are not easily categorized
Selinux:selinux File System Instance

To view the parameters and usage of a command:
Command--help

User management:
ID: You can view the current user
[[email protected] ~]$ ID
uid=501 (Lhy) gid=501 (lhy) group =501 (LHY) environment =unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
WHOAMI: Viewing the current user
[Email protected] ~]$ WhoAmI
Lhy
Who: See how many users are currently logged in
[email protected] ~]$ who
Root pts/0 2017-05-11 21:41 (192.168.20.1)
Root PTS/1 2017-05-11 22:53 (192.168.20.1)
W: See how many users are currently logged in
[Email protected] ~]$ W
22:58:21 up 2:09, 2 users, Load average:0.00, 0.00, 0.00
USER TTY from [email protected] IDLE jcpu PCPU
Root pts/0 192.168.20.1 21:41 0.00s 0.11s 0.00s W
Root pts/1 192.168.20.1 22:53 1:41 0.03s 0.03s-bash

Add user
Useradd Lhy #添加用户
Useradd-g GroupName Uername #添加用户时候制定加入的组名
passwd lhy #给添加的用户加密码, you can also reset your password
The user's default home directory is in the/home/directory:
[Email protected] ~]# cd/home/
[[email protected] home]# ls
Lz

Operations on a directory (folder)
PWD Displays the current path you are in
which directory (folder) the CD enters

~ Wavy lines represent home directories:
Quick Home Directory:
CD ~
Cd

To switch users:
[email protected] ~]# su lhy
[[email protected] root]$ Ls→root directory is the home directory of Superuser root (normal user's home directory is under////)
LS: Unable to open Directory.: Insufficient permissions
[[Email protected] root]$ exit
Exit
[email protected] ~]# su lhy
[[Email protected] root]$ exit
Exit
[Email protected] ~]# Su-lhy
[Email protected] ~]$
[Email protected] ~]$ pwd
/home/lhy
[[email protected] ~]$ su lz→ Current user is lhy, not superuser, to switch to the LZ user will need to enter the password
Password:
SU username
Su-username
The difference is Su-the user's environment variables are reloaded

sudo get super User privileges
To add sudo permissions for a normal User:
/etc/sudoers file, find root all= (all) All this line, add below it
Username all= (All) Nopasswd:all then save
When you're done, other users will be able to switch to the super user by typing "sudo su-".
Sudo-s switch root user, do not load environment variables

Delete User (must use root user to operate)
Userdel username
Userdel-r XW Delete the user's home directory when it is deleted

Group Management:
Add Group
Groupadd Name
Delete a group
Groupdel Name

File operation:
Create a folder
Mkdir
Mkdir-p/tmp/besttest/blk

Delete a folder
RM-RF/
RmDir: Only empty folders can be deleted

See what's Under the file:
Ls-l = = ll
ll
Ls-a

Renamed
MV Besttest Linux
MV Besttest/tmp
MV if followed by a filename rename, if followed by the path is moved

Copy
CP ax/tmp/Copying files
Cp-r linux/tmp/Copy Folder
CP-RF Linux

Rename:

Alias lhy= ' Cd/opt/lampp '
If it's permanent, add it to/etc/profile.

Path:
/top directory, My Computer equivalent to Windows
Relative path: Equivalent to the current path
Absolute path: The actual path
Cd.. #回到上一级目录
Cd.. /.. /#回到上两级目录
CD-Return to the previous directory

permissions:
Permissions of the same group permissions for other users
rw-r--r--
rwx represent read, write, respectively , execute permissions

Plus permissions:
X for Execute W represents write R for read
chmod o+x other users
chmod g+x This group of users
Chmod u+x themselves
chmod +rwx all
chmod a+x There are
Remove permissions, that is, the + into-
r=4 w=2 x=1 digital mode represents the permissions
chmod 755 file
If the permission is a folder, add-R

Chown Change the owner of the file
Chown File User
If it is a folder, add-R
[[email protected] tmp]# ll sqltest
-rw-r--r--. 1 lhy lhy 8038 May 16:55 sqltes t
[[email protected] tmp]# chown LZ sqltest
[[email protected] tmp]# ll sqltest
-rw-r--r--. 1 LZ lhy 8 038 May 16:55 sqltest

CHGRP changing the owning group of a file
CHGRP file Group
If it's a folder, add-R
[email protected] tmp]# LL
Total Dosage 12
-rw-r--r--. 1 lhy root 0 January 20:52 AA
-rw-r--r--. 1 root root 472 January 20:40 test
[Email protected] tmp]# chgrp lhy AA
[email protected] tmp]# LL
Total Dosage 12
-rw-r--r--. 1 lhy lhy 0 January 20:52 AA
-rw-r--r--. 1 root root 472 January 20:40 test

Wc-l file Count rows:
| Pipe break: Connect two commands and execute the result of the previous command to handle the following command
[email protected] tmp]# cat test |wc-l
33
[[email protected] tmp]# ls |wc-l
5
&& connection two commands, successively executed
[[email protected] tmp]# ls && wc-l test
AA Bitrock_installer.log Test Yum.log YUM_SAVE_TX-2015-11-01-00-38WNQS4B.YUMTX
Test
SH startup.sh && tail-f/logs/catlina.out

Editing operations on files:
Vi
Toggle edit mode and command mode:
I: Current position
O: The next line of the current row
A: Edit in the next position
ESC: Edit mode switch to command mode
Exit VI:
Command mode:
Exit:
": Q" #没有修改的话可以直接退出
": q!" #不保存退出
": Wq" #保存退出
": X" #也是保存退出
Find:
/test looking from the beginning.
? Test starts at the end of the file
Display line number: ": Set Nu"
Suppress line number: ": Set Nonu"
Go to a line: ": num"
Fast to end of file: Shift+g
X: Delete a single character
DD: Delete entire row
19DD: Delete 19 rows
U: Undo
YY: Copy a whole line
19YY: Copy 19 rows
P: Paste
.: Repeat previous action
$: Move cursor to end of line
0: Move cursor to beginning of line
Replacement string:
":%s/src_str/new_str/g"

Screen Tumbling Class command
Ctrl+u: First half screen to file
Ctrl+d: Half-screen to the end of the file
CTRL+F: Flip a screen to the end of a file
ctrl+b; Turn one screen to the top of the file
Vim:
In command mode CTRL + V into Visual editing mode, select multiple columns
Shfit+i Enter edit mode, enter the content you want to add
Press ESC again

To view files:
Cat
More
Less
Tail-f
Ln/opt/lampp/xampp ~/wxy

Find:
Find/-name MySQL #查找文件/folder
grep xxx file finds the contents, processes
[[email protected] ~]$ grep select/tmp/sqltest
SELECT * from Student;
SELECT * from Student where ID between 2 and 4;
Select Id,name,department from Student;
SELECT * from Student where department= "computer department" or department= "English Department";
GREP-V filter out the specified keywords
Grep-w matches the specified string
Tail-f/opt/lampp/logs/access_log |grep Lhy

To view a process:
Ps-ef|grep mysql|grep-v grep lookup process and does not show grep process
PS just shows you the state of the moment of execution
Top dynamic viewing process, but cannot find

Kill Process:
Kill-9 PID kill process can be with multiple PID
Nohup./jmeter-server & Running a program in the background

Du-sh * Can see the space occupied by all the files in the current directory
Du-sh dirname
Df-h can see how much of the current disk has been used

Upload, Download:
FTP tool: Direct drag, anything can be uploaded, to the SFTP protocol
RZ, sz command can upload the download directly, but it cannot upload the folder
RZ, SZ session options x/y/zmodem settings upload download directory
RZSZ command installation: Use Yum installation, yum–y install Lrzsz,
Compile and install: http://blog.chinaunix.net/uid-20639775-id-154615.html

Switching machine, restart:
Shutdown
Shutdown-h #定时关机
Shutdown-h now #立即关机
Init 0 #立即
Reboot restart
Shutdown-r 20 "I'm going to reboot." Timed reboot

Log off User
Exit

Internet:
IP A
Ifconfig
dhclient# Auto Get IP

Compress, unzip files
Tar cvf linux.tar Linux #直接打包, Front is the name of the package, followed by who you want to pack
Tar zcvf linux.tgz linux# #压缩
Tar zcvf linux.tar.gz Linux #压缩
Tar xvf linux.tar linux #解压, you can unlock it, no matter how compressed or uncompressed it is.
Zip linuz.zip Linux hit zip package →zip need yourself yum
Unzip Linuz.zip
Gzip file can only package files, packaging the original file will be gone, need to own Yum
Gunzip file.gz

REDIRECT :
Cat xx > New_xx covers the original content
>xx.log→ emptying the log without restarting the service
Cat xx >> new_xx append

Scheduled Tasks:
CRONTAB-E Editing timed tasks
Crontab-l See which scheduled tasks are currently available
The format of the crontab file is "M H d M D cmd".
where m stands for minutes (0~59), H for hours (0~23), D for Day (1~31), M for month (1~12), d for Day of week (0~6,0 for Sunday). CMD represents the program to run, * represents every minute of execution
* * * * * * sh/opt/lampp/test.sh means to execute test.sh this script every minute
*/5 * * * * * sh/opt/lampp/test.sh means to execute test.sh this script every 5 minutes
* * * * * */usr/local/apache/bin/apachectl restart means 21:30 restart Apache per night
Example:
Crontab-e
* * * * * * touch/tmp/lhy
[Email protected] ~]# CRONTAB-E
No crontab for root-using an empty one
Crontab:installing New Crontab
View under the/tmp folder:
[[email protected] tmp]# ls
Bitrock_installer.log crontab. Sjf8er sqltest Yum.log yum_save_tx-2015-11-01-00-38wnqs4b.yumtx
[email protected] tmp]# ll Lhy
-rw-r--r--. 1 root root 0 May 07:50 lhy
[email protected] tmp]# ll Lhy
-rw-r--r--. 1 root root 0 May 07:51 lhy

To view the port number:

Netstat-nlpt|grep 18983 #查询这个进程号启动端口号是什么
Netstat-nlpt|grep Port #可以查看这个端口号有没有被占用

Environment variables:
The role of environment variables is to have a script/command in whatever directory you want to use
System Environment Variables:/etc/profile→ is valid for all users
User Environment variables: ~/.bashrc→ User's home directory
Ls-al all files in the display directory, including hidden files "." All that starts is hidden files.
The system assembled a MySQL and added the MySQL directory to the environment variable
I also have a user, own a MySQL, this time there are two MySQL, want to use their own MySQL, environment variables added to the previous MySQL, then this time, you can put their own MySQL in the user's environment variables
Export path= $PATH:
Source/etc/profile
SOURCE ~/.BASHRC

/etc/profile environment variable Modification:
#/usr/share/doc/setup-*/uidgid File
If [$UID-gt 199] && ["' id-gn '" = "' Id-un '"]; Then
Umask 002
Else
Umask 022
Fi

For I in/etc/profile.d/*.sh; Do
If [-R "$i"]; Then
if ["${-#*i}"! = "$-"]; Then
. "$i"
Else
. "$i" >/dev/null 2>&1
Fi
Fi
Done

unset I
Unset-f Pathmunge


Export path= $PATH:/tmp→ Configuring environment variables
"/etc/profile" 81L, 1821C written
[[email protected] tmp]# ls
AA bitrock_installer.log lhy Test Yum.log yum_save_tx-2015-11-01-00-38wnqs4b.yumtx
[[email protected] tmp]# source/etc/profile→ re-introduce the configuration file

[[email protected] tmp]# Whereis Ls→whereis See where the command is
LS:/bin/ls/usr/share/man/man1/ls.1.gz

env→ used to display environment variables that already exist in the system

Examples of environment variables:
Under the TMP directory, create a new script Lhy:
[Email protected] tmp]$ VI lhy
echo "Love hongye!"
[[email protected] tmp]$ lhy→ system will only be found in the directory where the environment variable is configured, so this script will run in any directory and must be placed in a folder with environment variables already configured
-bash:lhy:command not found
or specify the directory where the files are located
[Email protected] tmp]$./lhy
Love hongye!
[Email protected] tmp]# MV Lhy/bin
[[Email protected] tmp]# CD
[Email protected] ~]# Lhy
Love hongye!!
[Email protected] ~]$ Lhy
Love hongye!


Shell script:
The shell is actually multiple commands written together
Inside the shell, defining variables must not have spaces
Ps-ef|grep jmeter|grep-v grep |awk ' {print $} '
awk ' {print $} ' #取第二列的数据
Example:
#!/bin/bash
Count= ' ps-ef|grep jmeter|grep-v grep |awk ' {print $} ' |wc-l '
Pid= ' ps-ef|grep jmeter|grep-v grep |awk ' {print $} '
if[$count-GT 0]
Then
Kill-9 $pid
echo "JMeter stoped."
Else
echo "JMeter not runing."
Fi

The Linux default Shell interpreter is bash

Software Installation:
Rpm:
RPM-IVH xx.rpm #安装
RPM-E xxxxx #卸载
Rpm-qa|grep xxx# Query Whether this software is already installed
Rpm–qa >list.txt to export the installed packages to the List.txt file.
After installing the RPM installation package, you do not need to add the environment variable, you will create a good
Yum
The Red Hat series system comes with
XX yum-y Install XXX
When you download Red Hat system, there will generally be two ISO files, a ISO1 is the installation files of the system, a Iso2yum source is the relevant software installation package, if not on the external network, will ISO2 mounted on the system, perform the installation
Common commands:
Yum Install httpd# Apache installation
Yum-y Install httpd# If you have the option to all agree to the installation
Yum List|grep httpd# Find the software you need from the Yum list
Yum Update httpd #yum升级Apache
Yum List installed |grep mysql# query if MySQL is installed
Yum Remove mysql# uninstall yum installed MySQL
SOURCE Installation:
What is GCC:GCC is the abbreviation for GNU Compiler Collection. Originally a C language compiler, it now supports multiple languages such as C, C + +, Java, Pascal, Ada, COBOL, etc.
Because the software packages on Linux are basically developed in the C language, you install GCC to compile the source code for installation.
Yum-y Install gcc*

./configure--prefix=/path# Generating compiled files
Make #编译
Make install #把编译好的文件放到你指定的目录下

RZSZ command installation: Use Yum installation, yum–y install Lrzsz,
Compile and install: http://blog.chinaunix.net/uid-20639775-id-154615.html

Environment Construction:
1, download dependent software, install the good
2. Get source code (package)
Depending on the language, see if you need to compile, package
3. Import Basic Data
4. Modify the configuration file
5. Start
Java programs (Tomcat, WebLogic, jetty, resin, WS)
PHP, Ruby, Python (Nginx, Apache)

Daily deployment:
1. Get the latest code (compile, package)
If you have a table structure change, you need to execute SQL
2. Modify the configuration file
3. Restart the program

Get system time:
[Email protected] ~]# date +%y%m%d%h%m%s
20170121095305

1, Daily 23:59 backup Lampp
The file name of the backup is named at the time
201612241852_acces.log
/tmp/logs/

Cd/opt/lampp/logs/access_log

① Write a bak_log.sh script in the bin:
Src_path= '/opt/lampp/logs/access_log '
Tar_path= '/tmp/logs/'
Time= ' Date +%y%m%d%h%m%s '

CP-RF ${src_path} ${tar_path}${time}_access_log
>${src_path}→ empty the source log, no need to restart the service
②crontab-e
* * * SH bak_log.sh

Note: Because the bak_log.sh script is placed in the bin directory, the bin directory is already configured in the environment variable, so when writing crontab, bak_log.sh does not need to specify the absolute path of the file
If the folder where the bak_log.sh script is located is not configured in the environment variable, bak_log.sh need to specify the absolute path of the file when writing crontab, as follows:
* * * * sh/tmp/bak_log.sh

------------------------------------------------

Use of related tools:

Sumline:

Preferences → settings → default open configuration file:

Remove the "ignored_packages": ["Vintage"] in brackets at the end of the file, and you can use the VI command of Linux.

"Ignored_packages": ["Vintage"]

"Ignored_packages": []

When a text file uploaded from Windows to Linux is garbled, it is because the encoding of Windows and Linux is different, using the sublime file → Set the file encoding, so that the file needs to be uploaded encoding method and the encoding on Linux is the same ( File Save As can also be set), there will be no garbled.

Xshell:

Configure selected text Right-click: tools → options → keyboard and mouse

In addition Xshell, there is a function to determine the file type according to the color of the filename:

1) The default color represents normal files. Example: Install.log

2) green represents the executable file. Example:rc.news

3) Red represents the tar package file. Example:vim-7.1.tar.bz2

4) Blue represents the catalog file. Example:lhy

5) Shuihong represents the image file. Example:lhy.jpg

6) Cyan represents the linked file. Example:rc4.d (This type of file is equivalent to a shortcut)

6) yellow represents the device file. Example:fd0

------------------------------------------------------------------

Summary of Common Linux 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.