Common commands for Linux development

Source: Internet
Author: User
Tags bz2 locale file transfer protocol nslookup root access

Often use Linux for development, software installation, environment deployment, etc., will use some common commands, below is I usually use or collected under the Linux Common command set:


Type command to see whether a command is an external command or an internal command
[[Email protected] test]# type cd
CD is a shell builtin
CD is an internal command

[[Email protected] test]# type mount
Mount Is/bin/mount
Mount is an external command


Internal commands can access environment variables directly, and external commands can not


View Internal Command set
Mans type


Environment variables
View environment variables
Echo $PATH
ENV View all environment variables


Self-setting environment variables
[Email protected] test]# Aa=hello
[Email protected] test]# echo $AA
Hello
View environment variables to be given to $


environment variable Configuration angle Ben/etc/profile


View a command or function in which chapter
Whatis command
Man-f command


Man document
1. Basic shell command Whatis ls
2. System invoke Command Whatis open
3. System call Library command Whatis malloc
4.
5. File interface Whatis passwd Whatis inittab Whatis Shadow
7. General statement Miscellaneous Whatis signal Whatis socket
8. Network interface, core interface Whatis ifconfig Whatis mii-tool


Info command
Help


LS List Directory contents


ls file or directory
Ls-l in the form of a list ==> ll
Ls-a all the files
Ls-r Recursive folder
Ls-h File size with units
Ls-t in chronological order


Touch to create a file
1. If the file does not exist, a file is created
2. If the file exists, changes the file's timestamp, does not change the file content




CD Change working directory changes working directory
CD Directory
Cd. Current directory
Cd.. Up a layer
CD-Return to the previous directory before jumping over
CD to the appropriate user's home directory
CD ~ to the appropriate user's home directory




Absolute paths depart from Root

Relative paths depart from the current working directory


RM remove a files or a Directorys
Rm-r Deleting a directory
Rm-f Force Removal


mkdir Create a directory
mkdir Directorys
mkdir dir1/dir2/dir3-p Creating a multilevel directory


CP copy a file or a directory


CP file1 File2
CP file Directory
CP Directory1 Directory2-r
\CP file directory Overwrite mode


Mv
1. Cut
MV File1 Directory
MV File1. /file1
2. Renaming
MV File1 File2




Permissions
7 7 7
-Rwx rwx rwx
belongs to the user group other
r--4
Rw-6


chmod 0777 file to set permissions
chmod 0777 directory-r All the same permissions
chmod a+x file adds x to all Bits
chmod a-x File Delete all bits X




Umask Viewing the mask of the current user
By default it is 0022


The maximum permission to create a file is 666
Create folder maximum permission is 777


Maxpriority-umask = file or directory priority
Folder 777-022 = 755
File 666-022 = 644




-Normal file Plain files black
D Directory Blue
C Characterdevice character device yellow
B blockdevice block Equipment
s Socketdevice Network Equipment
L Link File light blue
P Pipe Piping File


/root Home for super users
Home for ordinary users
/bin commands for ordinary users
/sbin Commands for super users
/dev Device
Directory for/etc configuration files
/net/sys Network related systems related
/media Auto Mount Peripherals
/mnt manually mounted peripherals, network resources
/misc automatically mount the native hard disk resource
/proc automatic generation, device parameters
/var system logs and services
/usr third software automatic installation directory
/OPT installing third-party software manually
/selinux SELinux Firewall
/lost+found ext2 ext3 EXT4 disk format
/boot kernel, grub boot a separate disk partition


Vim Editor


Three different modes
Command mode
Last-line mode
Insert mode

Insert mode
Complete CTRL + P
Delete entire row Ctrl + U

Command mode
Command mode into insert mode
I insert before the current cursor
I Insert at the beginning of the current cursor
A inserts after the current cursor
A inserts at the end of the current cursor line
o Insert at the beginning of the next line of the current cursor
O Insert at the beginning of the previous line of the current cursor


YY Copy a row
4YY Copy the following four lines from the current cursor
DD Delete a row
4DD Delete the following four lines from the current cursor
D + up key to delete the current cursor line and the previous line
D + Next key to delete the current cursor line to have the next line
P Paste on the next line of the current cursor
P paste at the current cursor where the row is on the previous line
R + replaces one character of the current cursor with the substituted character

Visual block
Delete
Ctrl + V put the characters that need to be manipulated Vlasov black +delete remove the black character
Add to
CTRL + V to add the cursor to the Black + I edit + Esc
Replace
CTRL + V will need to replace the pull Black + R + The characters needed to replace such as: a


Last-line mode
:! Force relative to Super user
: W Save
: Q exit
: Wq Save and exit: QW No
: X Save and exit
: X does not enter a password for a file, or cancel
:!<commad> jump out of vim execution <commad> command
: SH creates a new shell to save the current editing state, after the operation, with Ctrl+d reply to the current editing state




How to drop a program into the background
CTRL + Z falls to the background to stop running
./a.out & Drop a program into the background execution
View background tasks
Jobs

Background tasks drop to foreground
Fg


Find
/target Find target object looking down from current cursor
n looks down to the next
N look up the previous
target object is searched up.

Cancel highlighting
: Nohl ==> No high light


Let vim display the row label
Set Number ==> set Nu
Let vim not display row labels
Set Nonumber ==> Set Nonu


Modifying a configuration file
Set row labels
Vim/etc/vimrc

Write at a blank line
Set number or set Nu
Save exit

Modify Tab length
Vim/etc/vimrc
Set ts=4
Save exit




Replace
% all lines s replace G line all C check checks
:%s/this/that Replace the first this of all rows with that
: All this for all rows of the%s/this/that/g is replaced by that
: 14,16s/this/that/g from line 14th to line 16 is replaced by that
:%S/THIS/THAT/GC Check access mode replacement


View Time
Date
Date +%f View current time
Date +%f--date= "1 days Ago"
Date +%f--date= "1 day Ago"
Date +%f--date= "1 day"
Date +%f--date= "1 days"

Set the time
Date-s 2014-07-14 Set Current time
Date-s 2014/07/14
Date-s 11:40
Clock-w Write Sync time


View the history of the current command
History
History-w Save History Command for current operation
~/.bash_history
History-c clears the history of the current operation

View the languages supported by the current system
Locale
Locale-a View All
locale-a | grep ZH view supported file formats
Pipeline Filtration
Cat txt | grep Hello View txt This file contains a line with the word hello


Linux system RunLevel Run level
0 Turn off the machine
1 single-user mode, no network, no service, active root access
2 Multi-user mode, with service, no network
3 multi-user mode, with service, network, server mode
4 reserved
5 graphical interface, X11
6 restart


Configure Corner Book
/etc/inittab
Id:5:initdefault

Init 0
Shutdown-r +10 10 minutes after restart
Shutdown-h now shuts down the machine
Halt is also off.
Halt-p-F forced shutdown, direct power-down
Reboot restart
Init 6
init + runlevel

CTRL + F2-F7 Enter character interface
CTRL + F1 Reply graphical interface


stdin stdout stderr
Standard input standard output standard error
0 1 2


redirect
By default, standard output redirection clears the file
echo "Hello World" > txt if TXT does not exist, it will be created
Standard error redirection
echo "Hello World" 2> txt
(LS && fjdkslf) 2> txt only redirect standard error
REDIRECT standard error and standard output
(LS && fjdksfj) &> txt

Additional
echo "Hello World" >> txt will not empty the file
Error append
(LS && fdkfjdk) 2>> txt
(LS && fdkfdjf) &>> txt




Network configuration
192.168.110.254
Network Segment IP
IP network IP
Gateway Router--"switch does not have an extranet forwarding function
Subnet mask 255.255.255.0 If 255 fixed, 0 variable
DNS resolution turns a domain name into a specific server IP

How to see if there is a local network card
Ping 127.0.0.1
Ping to prove that there is a network card, if the ping does not pass, prove that there is no network card

See if the network cable is connected
Mii-tool eth0 (NIC interface name) eth0 eth1
[Email protected] ~]# Mii-tool eth1
eth1:negotiated 100basetx-fd, link ok
No link

Turn off the network management background process
Service NetworkManager stop//restart start




Configure host IP
1. Temporarily Configure IP
Ifconfig eth0 192.168.110.xxx
Configure this machine to 192.168.110.xxx
As long as the network service restarts. It will expire.
Service Network restart

2. Manually configure the IP
/etc/sysconfig/network-scrpts/ifcf-eth0
Should have:
Device=eth0 Device Name
Bootproto=none or (static) static or DHCP (dynamically acquiring an IP address)
Onboot=yes Open this network card work *
Ipaddr=192.168.110.xxx IP Address
gateway=192.168.110.1 Gateway
netmask=255.255.255.0 Subnet Mask

Restart Network after configuration save
Service Network restart
Second hit can be abbreviated
!ser


View Gateway
Route-n
Add a Gateway
Route add default GW 192.168.110.1
Delete a gateway
Route del default GW 192.168.110.1

View and configure DNS
Nslookup
Server
Default server:192.168.2.1
address:192.168.2.1#53
Exit

Set up DNS
/etc/resolv.conf
NameServer 192.168.2.1
8.8.8.8
dns1=8.8.8.8


Configure a subnet virtual network card
cd/etc/sysconfig/network-scripts/
CP Ifcfg-eth0 ifcfg-eth0:0
Vim ifcfg-eth0:0
device=eth0:0 Modify the NIC name

Change to one of the 2 network segment IP
gateway=192.168.2.1

Save
Service Network restart
Ping 192.168.2.1
Ping to pass

Whether DNS can be used
Nslookup
->server
192.168.2.1-8.8.8.8
Exit

Nslookup www.baidu.com
If the parse succeeds. You'll see the resolved address

Ping www.baidu.com
If the ping makes sense, you can surf the Internet.


Wireless
# ls usbwifi.sh
# ls wireless_tools.29/
# yum-y Install zd1211*
# ifconfig-a View Wlan0
# ifconfig Wlan0 up
#./usbwifi.sh to Essid "Androidap"
# WPA--Wpa_tool


Configure host Name

1. View your host name
1> echo $HOSTNAME//environment variable mode easy to change
2> hostname//Command mode
3> Cat/etc/sysconfig/network | grep HOSTNAME


2. Set host name
/etc/sysconfig/network
Hostname=xxxx.xxxx.com


To reboot for the host name to take effect
Reboot


3. Connect the native IP to the native host name
/etc/hosts
IP + hostname + short name of hostname
192.168.110.xxx xxxx.xxxx.com xxxx

Ping 192.168.110.xxxx
Ping xxxx.xxxx.com
ping xxxx
You can ping all the way through OK.

UserID User ID

Useradd xxxx
useradd-c xxxx Note
Useradd-s/bin/bash-c "Hello World" xxxx
Useradd-g root-g test-s/bin/bash

-C Comment
-S Specify shell
-g Specifies the owning group
-g Specifies the attached group to which it belongs
-U Specify User ID
-D Specify the user's home directory
-M if no creation exists

Userdel xxxx Delete a user
Userdel-r xxxx Delete a user also has the corresponding home directory

Usermod-c "Hello World"-s/bin/bash-g root-g test-d/home/bbbb xxxx

Give a user password
passwd xxxx
**
/etc/passwd
User ID
0 Root Super User
The general user has a home directory, you can log into the system
> 0 && < 500 ordinary user/sbin/nologin
User name has password user ID belongs to group ID comment home directory specified shell
Root:x: 0:0: Root:/root:/bin/bash


/etc/shadow
User name MD5 password after encryption encrypted password
Root:$6$hyiuhhnp$u8jduxpnqr3jnbelzmut5p8fwvmimifq8ojcywii/ov/gs3ir


Date of last password change
J5ljatowqap7dtyhzefb6bs59ft7qrknyptz/:16246:0:99999:7:::
Mans 5 Shadow


Disk partitioning

1. Insert the disk you want to partition first
2. Unlock the disk partitions that are mounted automatically
umount/media/*
3.D Grid Disk
1> Confirm disk Device node
Fdisk-l such as:/DEV/SDB1 = = "end up with the entire disk/dev/sdb
2> D lattice
DD If=/dev/zero of=/dev/sdb bs=1024 count=1
3> Confirm if D lattice is successful or not.
Fdisk-l successful If you do not see the child partition
4. Write the partition table
1> Fdisk/dev/sdb
A set a partition as active partition
n Add a new partition
D Delete a partition
P Print partition information
t change the partition format
L print disk format with corresponding ID number max 0xFF
Q Exits but does not save changes
W write partition table to disk and exit
2> confirm that the partition information has been written to the partition table
Fdisk-l
If you get the partition table information that matches your information. The partition table writes successfully
5. Format the corresponding partition format into the corresponding file system format
1> to view specific partition formats
Fdisk-l
2> partx-a/dev/sdb
If you do not see the corresponding device node
ls/dev/sdb*
/dev/sdb1/dev/sdb2/dev/sdb3/dev/sdb4
Unplug and reinsert until you can see the specific partition device node
3> Format File System
Mkfs.vfat/dev/sdb1
Mkfs.vfat/dev/sdb2
Mkfs.ext2/dev/sdb3
Mkfs.ext3/dev/sdb4
Note that there is no NTFS format in the Linux system.

6. Unplug and reinsert to see if the Auto Mount window has four



Process Management

1. View the processes running on the current system
PS-AUXF Long PS-XF Short
Snapshot Snapshot Snapshot mode


User Information
PID Process ID Number
%CPU CPU Usage
%MEM Memory Usage
VSZ Virtual Memory
RSS Real Memory
Whether the TTY has a control terminal
Start time
Time Runtime
command to run the commands executed by this process
STAT process Status


D Non-disruptive sleep (deep sleep)
S interruptible Sleep
R is actually executing or preparing for the continuation of the process
T paused process
X dead process (not visible)
Z Zombie or defunct process

< high-priority
N Low-priority
S session leader
L page Lock
L Muti-thread Multithreading
+ foreground foreground running relative to background background


2. Monitoring mode
Top
Can press H to provide help


3. Kill a Process
Kill-9 ProcessID
Man 7 Signal View signal number 9th

Killall
Kill one or more processes with a process name

4.pstree
Tearful the process in a tree way
See only parent-child relationships








Service
Yum Source Search
Yum Search vsftpd
Installation
Yum-y Install VSFTPD
Delete
Yum-y Remove vsftpd


1.FTP Service
//-------------------------------------
Service side
File Transport Proctol
File Transfer Protocol

Installing the FTP Service
Yum-y Install VSFTPD

The path to the FTP service is turned on by default
/var/ftp/pub

Restart Service
Service VSFTPD Restart

Set boot up
Chkconfig vsftpd on

To FTP directory permissions
chmod 777/var/ftp/*-R


Guarantee
The firewall is off.
Setup
--Firewall--Remove *-OK
Turn off SELinux.
Setenforce 0


//----------------------------------------
Client
1. Open Firefox--ftp://192.168.110.xxx
2. Location--Connect to server--Enter FTP server ip--> OK
3.yum-y Install Lftp
Lftp 192.168.110.xxx
->commad command
Target Machine native
--Get Xxxx-o/root/xxxx
Exit

//--------------------------------------------------
Yum Source
Ls/var/ftp/pub/rhel-server-6.4-i386-dvd.iso


1. Attach the installation package inside the ISO
Mount-o loop/var/ftp/pub/rhel-server-6.4-i386-dvd.iso/mnt

2. Confirm that it is already mounted
Df-h
[Email protected] pub]# df-h
File system capacity has been used with available percent mount points
/var/ftp/pub/rhel-server-6.4-i386-dvd.iso
3.0G 3.0G 0 100%/mnt


Configure the corner book for the Yum Source
/etc/yum.repos.d/xxxx.repo
XXXX name can be written casually, but the end must be. Repo
It's best to make sure there's only one Xxxx.repo

3.vim/etc/yum.repos.d/xxxx.repo
[xxxx]//yum source Theme
baseurl=file:///mnt/
Enabled=1//Open Yum Source Service
Gpgcheck=0//Check key




4.yum Clean all//Yum source cache
Yum List
If the theme is configured before success




//-------------------------------------
Local non-mounted

1.mount-o loop/var/ftp/pub/rhel-server-6.4-i386-dvd.iso/mnt
2.echo $? If it is 0 OK or df-h see if there is a mount
3.mkdir/yum
4.cp/mnt/*/yum/-R
5.vim/etc/yum.repos.d/xxxx.repo
[XXXXX]
baseurl=file:///yum/
Enabled=1
Gpgcheck=0
6.yum Clean All
7.yum List


Be a server for a Yum source
Ftp
Service side
1.yum Source Released
/var/ftp/pub
2.mkdir/var/ftp/pub/yum
3.cp/yum/*/var/ftp/pub/yum-r
4.service vsftpd Restart

Client
Vim/etc/yum.repos.d/server.repo
[XXXX]
1. Test the Yum source path on the server side first
Open Firefox ftp://192.168.110.xxx
baseurl=ftp://192.168.110.254/pub/rhel6.4_32/
Enabled=1
Gpgcheck=0
2.yum Clean All
3.yum List


Install the source package
./configure ==> Generate makefile
Make ==> generate executable file
Make install ==> Copy the executable file to the appropriate directory on the system

Cleaning bag
Make clean ==> Delete the executable or intermediate file that has been compiled
Make Distclean ==> clears the link relationship of the package, most notably the deletion of makefile


Attention:
If the package is too large
Make-j4


NFS Services
How to view host-published NFS services
SHOWMOUNT-E 192.168.110.xxx

1. Mkdir/test if/test is the directory we need to publish
2. Vim/etc/exports
/test * (rw) * All IP R readable w writable
3. Service NFS Restart
4. Showmount-e 192.168.110.xxx
If you find
Export list for 192.168.110.254:
/test *
Publishing success

Client Connection Host NFS Service
1.SHOWMOUNT-E 192.168.110.xxx (host IP)
Export list for 192.168.110.254:
/test *
2. Mount-t NFS 192.168.110.xxx:/test/mnt (client directory)
3.df-h
192.168.110.254:/test
193G 33G 151G 18%/mnt
Prove Mount succeeded

* Note: Client
If you finish the work, you need to hang up.
Umount/mnt
If not in time to hang up, as long as the server unexpectedly shutdown, the client will panic (slowly)




Cifs
Mount-t CIFS 192.168.2.211:/share/mnt
Df-h
Umount/mnt



Ssh
SSH 192.168.110.xxx

Ban
Service sshd Stop
Chkconfig sshd off

Open
Service sshd Restart
Chkconfig sshd on

Remote Copy Preparation
Scp
Copy to other machines from this machine
SCP Direcotry/file 192.168.110.xx:/directory/file
PASSPWD:
Copying from other machines to the machine
SCP 192.168.110.xxx:/directory/file/directory/file
Attention
These directories can not have a write error




Mount USB Drive
Mount/dev/sdb1/mnt

NTFS format
Install NTFS Packages
Ntfs-3g/dev/sdb1/mnt
Mount-t ntfs-3g/dev/sdb1/mnt

Package Unpacking
Xxx.zip xxx.bz2 xxx.gz Aaa.xz
xxx.tar.gz xxx.tar.bz2 Xxx.tar.xz


Packaged
Zip xxx.zip xxx
Pack xxx into Xxx.zip

gzip XXX ==> xxx.gz
bzip2 xxx ==> xxx.bz2
XZ XXX ==> Xxx.xz

Unpack
Unzip Xxx.zip ==> xxx
Gunzip xxx.gz ==> xxx
BUNZIP2 xxx.bz2 ==> xxx
xz-d xxx.xz ==> xxx
Or
Unxz xxx.xz ==> xxx

Composite Package
xxx.tar.gz xxx.tar.bz2 Xxx.tar.xz

Composite Package packaging (Strict)
TAR-CF Xxx.tar XXX
Or
TAR-CVF Xxx.tar XXX
Package xxx into a Xxx.tar
-C Create creation
-F File files
-V packaged directories or unpacked directories can be seen
-T view the contents of the package
-X Decompression

TAR-ZCVF xxx.tar.gz XXX
Package xxx directly into a xxx.tar.gz

TAR-JCVF xxx.tar.bz2 XXX
Package xxx directly into a xxx.tar.bz2

XZ Xxx.tar ==> Xxx.tar.xz

Unpacking of a composite package

TAR-XVF Xxx.tar ==> xxx
TAR-ZXVF xxx.tar.gz ==> xxx
TAR-JXVF xxx.tar.gz ==> xxx
Unxz xxx.tar.xz ==> Xxx.tar
TAR-XVF Xxx.tar ==> xxx

Bin/startup.sh #启动tomcat
Bin/shutdown.sh #停止tomcat
Tail-f Logs/catalina.out #看tomcat的控制台输出

#看是否已经有tomcat在运行了
Ps-ef | grep Tomcat
#如果有, use kill;
Kill-9 pid #pid for the corresponding process number
#直接查看指定端口的进程pid
Netstat-anp|grep 8196

Log in to MySQL remotely
Mysql-uroot-p-h192.168.9.161-p3306


To turn on the firewall:
Firewall-cmd--zone=public--add-port=8080/tcp--permanent
Firewall-cmd--permanent--zone=public--add-port=8080/udp
Firewall-cmd--reload
Firewall-cmd--state View firewall status
Systemctl Stop Firewalld.service Firewall off

Common commands for Linux development

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.