Common Linux Operations

Source: Internet
Author: User
Tags bz2 install php parent directory php error unzip bz2 administrator password server port ssh server

Quick action

tab (Auto-padded, press two tab when multiple selections appear list) Ctrl+d (exit current operation) CTRL + C (Stop the currently executing command)

System commands

Shutdown–h now (shut down immediately) Shutdown–h 15:30 (15:30 minutes off) shutdown–h +20 (30 minutes later off) shutdown–r +20 "System would reboot" (restart after 20 minutes, prompt sy Stem will reboot) (Forget root admin password) 1. When the system is started, press a key to enter the Grub menu (Forget the root Administrator password) 2. Press the E key to enter edit mode (forget root admin password) 3. Move to the kernel line, press E to continue editing ( Forgot root admin password) 4. Enter (single) + Carriage return (forgot root admin password) on the last side 5. Press B to boot the system into one-user mode (Forget root admin password) 6. Execute passwd command, enter new password (forget root admin password) 7. Restart your computer Reboot

Directory file Operations

. (current directory): (Parent directory)-(previous working directory) ~ (home directory) CD. (Return to parent directory) LS. (show current directory) LS (display directory contents) ls-a (contains hidden files) ls-l (listing file details such as properties and permissions information) LS–LH (display in easily identifiable units such as GB/MB/KB) CD (switch directory)  CD: (Go to parent directory) CD ~AA (enter HDXJ user host directory) CD=CD ~ (return to current user home directory) cd/tmp (go to root tmp directory) Touch (create empty piece) mkdir h (Create Houdunwang directory in host directory) mkdir–p/a/ B/C (recursive creation directory) RM hd.php (delete file hd.php) rm–r h (Recursive delete directory) rm–rf h (delete without confirmation) CP hdphp/tmp/hdphp (copy file hdphp to tmp directory) CP A1.txt A2.txt TMP (A1.txt and A2.txt copied to/tmp directory) CP hdphp*.php/tmp (copy to hdphp start with. PHP results file to/tmp directory) ln–s/home/hdxj/index.php/tmp/index_ link.php (Create a soft link index_link.php to the TMP directory for the index.php file) ln/home/hdxj/hdxj.php/tmp/hdxj.bak.php (create hdxj.php hard link to/tmp/ hdxj.bak.php) RM hdphp (delete hdphp file) rm–f hdphp (file does not exist without error) Rm–r hdphp (Recursive delete (delete directory)) MV hdphp HD (renamed hdphp to HD) MV Hdphp/tmp ( Move the hdphp file into/tmp) Head–n 2/etc/passwd (show first 2 rows head) Tail–n 5 index.php (take 5 lines of content tail) Cat index.php (show file contents) Cat–n index.php ( Show file contents with line number) MORE/ETC/PASSWD (split screen display file contents more) + Q (exit Display) grep ' Houdunwang ' hd.php (shows rows containing Houdunwang) (grep–v "^\s*[#;]" /ETC/SAMBA/SMB.CONF) (Show all non-commented lines) Grep-v (display does not contain matching textGrep-n (displays matching rows and line numbers) Grep-i (no size difference) which passwd (find passwd command location) Whereis passwd (find file named passwd) Find/-name index.php (Find files named index.php) Find/-size +10000k (find files larger than 10Mb) Find/www-type d-exec chmod 750 (Directory set to +) Find/www! -type d-exec chmod 640 {} \;(file is 640) Find/-name \*.php-exec rm-i {} \;(delete files found) compression processing (gzip passwd/gz-d passwd.gz) gzip Compressed, file compression with. gz/extension. gz extension (bzip2 passwd/bzip2-d passwd.bz2) bzip2 compression with the extension. bz2/extract file compression with. bz2 (Tar zcvf hdxj/tar ZXVF hdxj.tar.gz) Use gzip compression and package/unzip gzip file compression processing (tar jcvf hdxj/tar jxvf hdxj.tar.bz2) using BZIP2 compression and package/unzip bz2 file compression processing (-z/-j/-v/-c/ -X) Compress/display the packaging process in gzip/bzip2/New package file/unpack

VI Editor

Vim index.php (open file) press the I key (input) press ESC (return to Standard mode) Press: Wq (Save exit) I/i/a/a/o/o/esc (I at current cursor Insert/I line insert/a cursor next word prompt insert/a end insert// o Previous line insert/return standard mode): W/:w!/:q/:q!/:wq!/:w [filename]/:! Command/:set Nu (Save/Force save/Exit Do not save, Force exit/Force Save to exit/hold AS/Temporary execute command/display line number) NG (n is number)/g/(:/word)/:?word/(: n1,n2s/word1/word2/g) (: N1, $s/word1/word2/gc) (move to the first line, such as 2G move to line 2nd/move to the last line of the file/down search word string/Search up Word's string/search word1 from line N1 to section N2 to word2/Replace with the same, Just ask when replacing) Dd/ndd/yy/nyy/p,p/u/ctrl+r (cut current line/Cut down n rows/copy current line/copy down n rows/p paste to next line, p paste to previous line/Undo previous action/Redo previous action) when using Vim for file editing, A staging file with a suffix of. SWP is generated so that it can be used to recover edits when we interrupt unexpectedly. ()

Network configuration

(prepare) The Virtual machine settings network connection mode is bridged (• Modify the configuration file) (Vi/etc/sysconfig/network-scripts/ifcfg-eth0) (• Modify the content (; for line wrapping)) Onboot=yes; bootproto=static; netmask=255.255.255.0 (subnet mask); ipaddr=192.168.1.? (Network IP); gateway=192.168.1.1 (gateway address);D ns1=8.8.8.8 (DNS server IP) (configured to restart Service) service network restart (test network) Ping baidu.com (empty firewall rule) IPTABLES-F (storage rules) service Iptables Save (• Modify config file) vi/etc/selinux/config (• Modify content) selinux=disabled (link host, can use software) ssh root @ 192.168.1.?

User Management

Useradd MA (add account) Useradd–g Houdunwang HD (Add account HD and specify additional group as Houdunwang) passwd–s ma (view password status) passwd ma (Modify ma password) su root ( Switch to root account su Switch account operation) Usermod–l MA (lock user) Usermod–u ma (unlock user) usermod–g work ma (Set account MA additional group to work) Userdel MA (delete user) Userdel–r Ma ( Delete User with user home directory deleted) Groupadd MA (new user group) Groupdel MA (delete user group) ID MA (View account information)

Permission control

Drwxrwxr-x 2 ma ma 4096 March 11:26 houdunwang.com (file permissions connection owner belongs to group size modified time file name) d/-/l (Directory/File/link) r/w/x (Readable/writable/executable) permissions per 3 groups (1th Group RWX Code Owner/2nd Group RWX on behalf of Group/3rd group RWX on behalf of other users) Chown ma Houdunwang (change file Houdunwang owner to Ma) chown ma:ma Houdunwang ( Change file Houdunwang owner is MA, owning Group is MA) chown–r ma:ma hdphp (change directory hdphp and all file owners under MA, owning Group is MA) R (4)/w (2)/x (1) (read/write/execute permissions) 4+2+1= 7/4+0+1=5/4+0+0=4 (owner/owning group/other person (number of permissions represented as 754) chmod 777 Houdunwang (the owner, the owning group, other people's permissions are all turned on, that is, 777) if the system does not support ACLs, modify the configuration file/etc/ Fstab content is as follows (/dev/sdb1/wwwext4defaults,acl0 0) setfacl-m U:HDXJ:RW/WWW/HD (set HDXJ to HD has RW permission) GETFACL/WWW/HD (view file HD permissions) Setfacl–m g:work:rwx Shop (the work user group has RW permissions on the catalog shop) Setfacl–b Shop (remove all ACL settings) setfacl-m d:u:hdxj:rwx hdphp (set default ACL permissions ( Subdirectories are automatically inherited)) SUID (1. If the X permission bit in the file is S, it means that the suid;2.suid is set for the binary only, invalid for the directory, invalid for the shell script, 3. The performer obtains the owner's rights in the execution of the program, 4. The performer has X permission) SGID ( When the binary program is set Sgid, the performer obtains the program, the user group permissions to the directory settings Sgid, in this directory the user group becomes the directory group; the filegroup created by the user in the settings Sgid directory will be the same group as the directory)

Disk operations

Prepare to work (virtual machine, set join disk) du–a/du–ah/(du–sh/etc)/df-h/fdisk–l (list directory and subdirectory size/display size in easy-to-identify units/list total size/view partitions in easily identifiable units/view hard disk and partition information on the computer) Disk partition (partition the SDB disk) FDISK/DEV/SDB disk partition (new partition) n disk partition (continue operation/News logical partition) P/L disk partition (new primary partition) 1 disk partition (starting cylinder, default 1) Enter disk partition (end cylinder, fill disk size) +2G disk partition (create extended partition) E2 disk partition (start cylinder, enter default) enter disk partition (end cylinder, enter remaining space) enter disk partition (print partition I information) p disk partition (write partition to disk) W disk partition (formatted partition) Mkfs–t EXT4/ DEV/SDB1 disk partition (view mount point) Mount disk partition (new mount directory) MKDIR/MNT/SDB1 disk partition (hangs in partition/dev/sdb1 to/MNT/SDB1) MOUNT/DEV/SDB1/MNT/SDB1 disk partition ( View partition Contents) LS/MNT/SDB1 disk partition (view partition contents) DF disk partition (Unmount partition) UMOUNT/DEV/SDB1 disk partition (partition auto mount, modify/etc/fstab)/dev/sdb1/www ext4 defaults 0 0 disk partitions (commands are mount partitions based on/etc/fstab settings) mount-a

Software Installation (Configure lamp environment)/NTP Time Server

(Install wget command:) yum-y install Wgetiftop installation (Iftop is a tool for real-time viewing of network traffic, which is handy for monitoring network traffic.) ) iftop Install (Install wget command:) yum-y install wgetiftop installation (download software:) wget http://www.ex-parrot.com/~pdw/iftop/download/ Iftop-0.17.tar.gziftop installation (Installation environment) yum-y Install GCC make flex byacc libpcap ncurses perl ncurses-devel Libpcap-develiftop installation (Environment detection, under the Iftop folder)./configure--prefix=/usr/local/iftopiftop Install (compile and install) made & make Install view all installed Vim software (Rpm–qa | egrep-i vi) Delete command (rpm–e mysql) rpm install MySQL (: Service) wget http://mirrors.sohu.com/mysql/ mysql-5.5/mysql-server-5.5.38-1.rhel5.i386.rpmrpm Installing MySQL (: client) wget http://mirrors.sohu.com/mysql/MySQL-5.5/ mysql-client-5.5.38-1.rhel5.i386.rpmrpm Installing MySQL (install: Service) RPM-IVH mysql-server-5.5.38-1.rhel5.i386.rpmrpm install MySQL (install: client) rpm-ivh mysql-client-5.5.38-1.rhel5.i386.rpmrpm install MySQL (Error handling: Missing Perl package: error:failed Dependencies:/usr/bin/perl is needed by mysql-server-5.5.36-1.rhel5.i386): Yum install-y perlrpm install MySQL (Error handling: conflict with original version:) View system: MySQL rpm-qa | grep mysql Force delete original version mysql:rpm-e--nodeps mysql-libs-5.1.71-1.el6.i686rpm install MySQL (copy config file:) cp/usr/share/mysql/my-large.cnf/etc/my.cnfrpm install MySQL (start MySQL:) Mysql:service mysql startrpm install mysql (connect MySQL:) mysql-uroot-p (no password for the newly installed MySQL) Yum info mysql (view software info) Yum Search tree (search contains TR EE software) yum install MySQL (install tree software) Yum Update (update system software) Yum Erase tree (remove software tree) install apache  (yum install httpd) install MySQL (yum install MySQL mysql-server) install php  (yum install php php-mysql php-mbstring) launch Apache (Service httpd start) Start MySQL (Service mysqld start) (* Note) Web root Default in/var/www/html (* note) Turn off Firewall service iptables Stop (* note) turn off SELinux vi/etc/selinux/config (* Note) PHP code is placed by default in/var/www/ HTML (* Note) Open PHP error tip: 1) Vi/etc/php.ini 2) Set display_errors = On (530 rows or so) the NTP time server (yum-y install NTP) Yum installs NTPNTP time server ( Chkconfig–level ntpd on) Turn on service ntpdntp time server (service ntpd restart) turn on service

Scheduled Tasks

Start the Crontab service (service Crond start) to set the scheduled crontab task (CRONTAB-E) Format (* * * * * */command path) for the first 5 segments to indicate the time: The month of the week; * Code at any time; , code, such as the time period written 5,9 refers to 5 points and 9 points; -The representative interval is written as a 5-9-point 5,6,7,8,9 of time; /n represents an interval, such as a fragment written */10 refers to a scheduled backup database every 10 minutes (cd/backup) creates a backup.sh file and gives him x permission btime= ' Date +%y_%m_%d_%h '/usr/bin/mysqldump-uroot- padmin888 Hd>/backup/database/hd_$btime.sql

Process Management

Kill 2388 (normal shutdown process) Kill-9 2011 (Forced shutdown process) PS aux | More (View all processes) top run in the press? Get Help () top run by P (sort by CPU) top run by m (Sort by memory) top Run press N (sort by PID) top Run Press Q (leave top)

System Services

(CentOS provides a service script that executes scripts under/etc/init.d/to start or shut down services, service commands are also one of the services scripts under Operation/etc/init.d/) service httpd start (Turn on httpd server) Service mysqld Stop (shutdown MySQL server) service httpd Restart (restart httpd service) chkconfig--level 345 httpd on (chkconfig Open service) Chkconfig- -level 345 httpd off (chkconfig off service) Chkconfig--list httpd (view service startup status)

Network Command/network security

Netstat–a (List all ports (including listening and non-listening) Netstat–at (list all TCP ports) Netstat–pat (show PID and process name) netstat-tanl (displays the port (number) to listen on) (wget support via HTTP , HTTPS, FTP download) iftop is a tool for real-time viewing of network traffic and is very convenient for monitoring network traffic. (details) network security (iptable chain input chain/output chain) inbound packet Rules/Outbound packet Rules network security (processing mode Accept/drop) packets are allowed to reach the destination via it. /The packet is rejected without returning any information. Network Security (IPTABLES–L) View Firewall network security (iptables–f) empty firewall Rules network security (iptables-a input-s 192.168.1.106-p tcp--dport 22-j DROP) prohibit 192.168. 1.106 remote connection via SSH server network security (-a) attach the input rule chain (-i) Insert rule (-s) Source IP, the example is currently logged in to SSH using the computer IP (-d) destination address, in the example is the server IP (-d) Delete rule (-P) communication protocol (-- Dport) Destination port, in example, is the SSH default port (-j) operation mode (-i) packet enters the network card (-O) outgoing packet network card (-l) View firewall rule (--sprot) source port (--dport) Destination port (--line-number) Display with line number (-p) Default rule (-N) Displays the network security in digital form (iptables-p INPUT ACCEPT) default packet to allow network security (Iptables–i input–s 192.168.1.106–j DROP) Do not receive from 192.168.1.106 Packet Network security (iptables-d input 2) Delete 2nd input chain Rule network security (Iptable–i input–s 192.168.1.106–p tcp–dport 22–j ACCC EPT) to release the SSH service from 192.168.1.106 network security (iptables-i input-i lo-j ACCEPT) data packets connected to localhost Allow network security (Iptable–a Input–s 192.168.1.106–p icmp–j DROP) Disables the ping operation of the 192.168.1.106 network security (Service iptables save Iptables Rule Network security (Web Server firewall rule) ipt= "/sbin/iptables" #删除所有规则 $IPT-f# Default rule for all suppress $ipt-p INPUT DROP   $IPT-P FORWARD drop  $IPT-P OUTPUT drop# setting allows data to enter the server established $IPT-A when the connection status is related and input-m state--state R Elated,established-j accept# Setting external Client Connection server port 80,22,21$ipt-a input-p tcp-m TCP--dport 80-j accept$ipt-a input-p tcp-m tcp --dport 22 -j ACCEPT$IPT -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT$IPT -A INPUT -p tcp -m tcp --dport 20 -j ACCEPT# Allow external ping server $ipt-a input-p icmp-j accept# allow internal data back $ipt-a input-i lo-j accept# Set the data for related and established to be sent from the server to the external $ip T-a output-m State--state related,established-j accept# allows access to external DNS servers $ipt-a output-p udp-m UDP--dport 53-j accept# Internal data back $ipt-a output-o lo-j accept# Access external server 80,22,21 port $ipt-a output-p tcp-m TCP--dport 80-j accept$ipt-a output-p tcp -m tcp --dport 22 -j ACCEPT$IPT -A OUTPUT -p tcp -m tcp --dport 21 -j ACCEPT$IPT -A OUTPUT -p tcp -m tcp --dport 20 -j accept# allows the data output of the ping operation $ipt-a OUTPUt-p icmp-j accept# Save Restart iptables service effective services iptables Saveservice iptables restart


This article is from the "Lin Chunje Road" blog, please be sure to keep this source http://kratoslinux.blog.51cto.com/9844108/1784245

Common Linux Operations

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.