Linux Command Collection

Source: Internet
Author: User
Tags aliases clear screen parent directory sorts switches system log rsyslog egrep

Command summary:

mkdir Create directory make Directorys (full name)-P (Recursive)

Ls-l (Long) d (dieectory) displays the directory or file name list. -A (can show hidden files)

Ls-f=ls-p (to view the file with different symbols at the end of the classification,/is the directory,-p mainly for the directory)

Ls-h (file humanization)-I (index number of the file)-T (sorted by modified time)-R (Flip sort)

Ls-l--time-style=long-iso: See the full time.


Modify Host Name:

1.hostname + hostname (temporarily modifies host name).

2.[[email protected] ~]# vi/etc/sysconfig/network

Networking=yes

Hostname=xuexi (host name can be permanently modified)

3.[[email protected] ~]# vi/etc/hosts (the corresponding hostname in the Hosts file should also be changed


Date: Time,-s modify time

Cal: Show Calendar


Ping:-c times-S packet size-I interval

CD switch directory-(cut back to previous directory), • (Cut home directory)

echo Print output (printf print output)-N: No wrap output,-e: can specify special characters

echo "Input" > path. For single-text insertion, overwriting the original text information

echo "Input" >> path. For appending single-text insertions, without overwriting the original text information


Vi/vim Notepad Editor Command mode (: Wq wq! q!)) <--> insert mode (ESC Toggle Command mode) line number plus GG anchor row

: Set Nu (shows line number). DD (delete the current line, and n rows of ndd). YY (copies the current line). P (paste). G (Switch to end of file). GG (switch to file header).

W:write Save Q:quit (exit)! Force

Current line start ^, end of current line $, undo delete u, search down/character (n repeat search), search up? Character








Partprobe: Notifies the kernel partition table that a change has occurred. The best way to connect/dev/sdb

[[email protected] ~]# FDISK/DEV/SDB disk partition format

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF Disklabel

Building a new DOS disklabel with disk identifier 0x63d6f553.

Changes'll remain in memory only, until the decide to write them.

After that, of course, the previous content won ' t is recoverable.


Warning:invalid flag 0x0000 of partition Table 4 would be a corrected by W (rite)


Warning:dos-compatible mode is deprecated. It ' s strongly recommended to

Switch off the mode (command ' C ') and change display units to

Sectors (Command ' u ').


Command (M for help): N (disk partition)

Command Action

E Extended

P primary partition (1-4)










Tar ZCVF (package combination) ZXVF (unpacking combination) JCVF (package combination) JXVF (unpacking combination)

Z (gzip packaged format) j (bzip Packaging format) c (create) v (verbose), F (file)

--exclude-x (--exclude-form),-C To specify directory decompression,-p to keep the original file attributes


Cut-d specify delimiter,-F numeric selection,-C by character


More (view files cannot be flipped upwards)

Less-n (view file can be turned up, show line number)

Cat view File Content-N Display line number

TAC: Flip Content output

CP-APR Copy files or directories (common-a).

MV moving files or directories and renaming

RM Delete,-F forced Delete,-R recursive Delete,-FR delete specified directories and files, rmdir delete empty directory


Head Head Show file header row number-N rows default header 10 rows

Tail tail display trailing file rows-n rows default tail 10 line-F + file name (trace end of file)-F (trace the end of file)-F (monitor log change information, and constantly try to connect the function),/var/log/messages (System log file)


grep filters one of the core commands (Three Musketeers of the old three)-V exclusion Syntax: grep+ content + file name, filtering out the content. grep+-V + content + file name, except for all content

grep+ Filter Content +--color=auto (let filter content have color)

Grep-e=egrep (multiple strings can be filtered, strings separated by |).

Grep-n. File name (show line number)-I replace

Sed takes all sorts of content (the Three Musketeers ' Dick)-n cancels the default output p=print (print) D=delete takes the line with SED. Syntax: sed-n rows (multirow: Rows, rows) p file name

Syntax: sed+-N/content/p + filename, filter out content. sed+/content/d + filename, everything outside the content




Awk also has a filtering effect (the boss of the Three Musketeers). Syntax: awk+/content/+ file name, filtering out content

View Eet.txt line Count (20-30): awk ' {if (nr>19&&nr<31) print $} ' Ett.txt

awk ' {print NR} ' + file name (print file line number)

NF: The last column, example $NF take the last column.

$: Take the first column, and fetch all the columns.

NR: Display line number




Examples of filtering IP addresses:

[Email protected] ~]# ifconfig eth0|grep "inet addr"

inet addr:192.168.116.128 bcast:192.168.116.255 mask:255.255.255.0

[Email protected] ~]# ifconfig eth0|grep "inet addr" |cut-d ":"-f3

192.168.116.255 Mask

[Email protected] ~]# ifconfig eth0|grep "inet addr" |cut-d ":"-f3|cut-d ""-f1

192.168.116.255

[Email protected] ~]# ifconfig eth0|grep "inet addr" |awk-f ":" ' {print $} '

192.168.116.255 Mask

[[email protected] ~]# ifconfig eth0|grep "inet addr" |awk-f ": ' {print $} ' |awk ' {print $} '

192.168.116.255

[Email protected] ~]# ifconfig eth0|grep "inet addr" |awk-f "[:]+" ' {Print $4} '

192.168.116.128

[Email protected] ~]# ifconfig eth0|grep "inet addr" |awk-f "[:]+" ' {print $} '

inet

[Email protected] ~]# ifconfig eth0|grep "inet addr" |awk-f "[:]+" ' {print $} '

Addr

[Email protected] ~]# ifconfig eth0|grep "inet addr" |awk-f "[:]+" ' {print $} '


[Email protected] ~]# ifconfig eth0|grep "inet addr" |awk-f "[:]+" ' {print $} '

Bcast

[Email protected] ~]# ifconfig eth0|grep "inet addr" |awk-f "[:]+" ' {print $6} '

192.168.116.255

[Email protected] ~]# ifconfig eth0|grep "inet addr" |awk-f "[:]+" ' {print $7} '

Mask

[Email protected] ~]# ifconfig eth0|grep "inet addr" |awk-f "[:]+" ' {Print $8} '

255.255.255.0


Sed and regular Expressions mate IP addresses:

[Email protected] ~]# ifconfig eth0|sed-n ' s#^.*addr:\ (. *\) BCA.*$#\1#GP '

192.168.116.128

Note: ^.*addr (is the beginning addr end of any character) \ Escape (), the content of the () example is the end of the addr. bca.*$ (the end of any character starting with the BCA). \1 (is the first parenthesis in the preceding section)


Sed and regular Expressions mate IP addresses:


[Email protected] ~]# ifconfig eth0|sed-n ' s#^.*addr:\ (. *\) BCA.*$#\1#GP '

192.168.116.128

[Email protected] ~]# ifconfig eth0|sed-n ' s#^.*addr\ (. *\) SCOP.*$#\1#GP '

: FE80::20C:29FF:FE9D:93E8/64

[Email protected] ~]# ifconfig eth0|sed-n ' s#^.*addr:\ (. *\) SCOP.*$#\1#GP '

Fe80::20c:29ff:fe9d:93e8/64

[Email protected] ~]# ifconfig eth0|sed-n ' s#^.*mtu:\ (. *\) metric:\ (. *\). *$#\1 \2#GP '

1500 1

[Email protected] ~]#


Stat: You can view the number represented by a file or directory permission. Syntax: Stat/etiantian


[Email protected] ~]# stat-c%a/etiantian

644

-C Select Format,%a: Represents the octal number that the permission represents.



Ways to filter spaces within a file:

[Email protected] ~]# Cat/text.txt

Oldboy



Tretet



Text


[Email protected] ~]# grep-v "^$"/text.txt

Oldboy

Tretet

Text

[[Email protected] ~]# sed '/^$/d '/text.txt

Oldboy

Tretet

Text

[[email protected] ~]# awk '/^[^$] '//text.txt

Oldboy

Tretet

Text










SED specializes in the line awk is good at column awk-f ":" ' {print $} '/etc/password

Sed-i s# changed file # New file #g text name. (s: Edit Replace, G: replace All)

Alias view existing aliases in the system, Unalias + command, cancel the alias of the command

The role of Aliases: (1) by adding some protection parameters to the dangerous command to prevent human error operation. (2) Turn many complex strings or commands into simple strings or commands.

which to see where the command is located


Find Find command-type (f,d)-name "ddd" Lookup by name-mtime by modified time

Delete with Find, fing/-type f-name "file name or format, etc." |xargs rm-f. Xargs: Used to follow the previous command processing results for batch processing of files

-maxdepth+ number (Find the depth of the directory)

Find./-type f-name "*log"-mtime +7|xargs rm-f (delete seven days old log, find delete)


History: View Historical Command record history-d + Specify the line number of history command record can delete the record history-c Clear History command record

Ctrl+r Find executed commands

!! View recently executed commands

! + Letters to see the most recent command that starts with that letter


Tree view directory structure-L show layers-D column Directory

Xargs is used to give the output of the find/ls to the back processing

Seq-s (print delimiter) prints a sequence of numbers similar to echo {1..9}

Man view Help for commands and configuration files, etc.

Touch Create file or modify file timestamp

PWD Displays the current path

W: Shows which users are currently logged in


Stat: View file properties, syntax stat file name

PS-EF: Viewing processes, for example:

[Email protected] ~]# Ps-ef|grep crond|grep-v grep

Root 927 1 0 01:13? 00:00:00 Crond





CP pre-add \ does not prompt for overwrite information, syntax: \cp+ original path File destination path

CP pre-plus command path does not prompt overwrite, syntax:/bin/cp+ original path File destination path

Uname-a (View all),-r (view kernel),-m (see how many bits the system is).

WHOAMI View Current User

Useradd + username (create user)-U (change uid)-m (Do not create home directory)-s/sbin/nologin (do not allow its users to log in). -e+ Expiration date (set user term) C5 the user expires two days or so before stopping the login, C6 expires on the login, but Su can switch. -C ("Add comment information to create new user" content with double quotes)-D (Specify home directory)

Userdel (delete user)-R even its home directory page is deleted.

Note: Try not to delete the user in the work, can vi/etc/passwd its user comments

Usermod: Modifies the user information.

Chage-l + user name (view user expiry time)-U (unlock)

Groupadd Group Name-G (add Group Change ID)

Groupdel: Deleting a group

passwd + username (set password for this user)-L (lock the user so that it cannot change the password)

passwd user name By default is to set the password for the current user (ordinary users can only change their own password)

passwd--stdin Modify the user password, and if you do not specify a user, modify the current user password. (Normal users can only change their own password)

Superuser root switches to a normal user and does not require a password. Passwords are required for normal users to switch to root or other users.

SU switches the user role, (to add-. )

sudo su-(switch to root requires the current user password). sudo + command (can execute commands but cannot switch users).

Visudo edit sudo (do not delete nopasswd indicates that you do not need to enter the current user's password) visudo-c: Check the syntax.

Sudo-l to see what permissions the current user has

Visudo (Authorization 98gg): Authorization oldboy Execute Delete command

/etc/sudoers (sudo configuration file) Visudo=vi/etc/sudoers (the former has the ability to check the syntax of the latter does not).

# # Syntax:

##

# # User Machine=commands

##

# # The COMMANDS section could have an other options added to it.

##

# allow ROOT to run any commands anywhere

Root all= (All) all

Oldboy all= (All) nopasswd:/bin/rm

(Authorization group in front of group name plus%, Example%oldboy,oldboy Group)

# # allows members of the ' sys ' group to run networking, software,

# # Service Management apps and more.

#%sys all = NETWORKING, software, SERVICES, STORAGE, delegating, PROCESSES, LOCATE, DRIVERS


sudo timestamp file c5.8 location/var/run/sudo c6.5 location/var/db/sudo



ln (creates a connection containing directory between two files)

Ln-s source file name new file name



Lsof view file is process-I: Port number (view port number) to see if the file is being consumed by the process.


The Syslog service is c5.8 and is rsyslog on 6.





RPM-IVH Software Installation command-qa (view installed packages)-e Delete, uninstall--nodeps (with-e uninstall regardless of dependencies, direct uninstall)

To change the update source:

cd/etc/yum.repos.d/

mirrors.163.com Domestic CentOS website

Yum grouplist (view installed packages)


CD-(Back to previous catalog)


Basic tuning and security settings after installation:

A. Simple optimization of Linux

1. Turn off SELinux (the U.S. National Security Agency (NSA) for mandatory access control implementation).


RunLevel View current system RunLevel

Init switch Run level

Netstat view network status Intup or an.

STRACE: Tracking service port to see why services are slow


Chkconfig: View the power-on self-boot entry.

For Oldboy in ' Chkconfig--list|grep "3:on" |awk {print $1}|grep-ev "Network|sshd|rsyslog|crond"; Do chkconfig $oldboy off; Done: Close all Startup items except Network|sshd|rsyslog|crond


Added security: (Backup before change)

Port 52113 (change port number). 43permitrootlogin No (root login not allowed)

123usedns no 66permitemptypasswords No (no blank password allowed).

Restart Sshd:/etc/init.d/sshd Reload or restart

Check if the remote service is on: Isof-i + (port number).


/etc/init.d/iptables Stop (temporarily shuts down the firewall).


$PATH (environment variable), echo $PATH (see which paths the system has).

Global effective:/etc/profile. Normal user ~/.bash_profile or ~/.BASHRC


Ulinit-n viewing file descriptors

ULINIT-HSN + add value (temporarily increase file descriptor).



Halt,poweroff shut down the machine

Reboot restart

Shutdown-r Now (restart)-H now (shutdown)

Exit: Logoff Ctl+d (Logoff)


Linux comparison tool:

diff filename File name (compare two file differences)


Vimdiff filename File name (compare two file differences)


Vi/etc/profile (can change the alias of the command inside the permanent entry into force) Source/etc/profile (make it effective after the modification)



>/etc/issue (Hide boot prompt version information).

Chattr +i (add File path): Locks critical system files.

Chattr-i (add File path): Unlocks critical system files.

lsattr + file name (see if the file is locked)


Ps-ef Viewing processes


File Permission Description:

R:read is readable, which indicates the right to read the contents of a read file.

W:write writable, indicating the right to have new, modified file contents (the permission to delete a file (to modify the filename) is controlled by the parent directory's permissions, regardless of the permissions of the file itself)

X:execute execution, indicates that has the permission to execute the file (the file itself to be able to execute, the ordinary user also needs R (readable) permissions, the root user does not have the R (readable) permission can also execute, of course, the file itself needs to be able to execute.

-No permissions

Note: Site Directory 755, Web site file 644 is relative security permissions (user root, and user group root)

The Linux default permissions are controlled by: umask

The default normal user is 002. Note When the user Id-gn unequal Id-un 022

Cat/etc/login.defs: There is permission to manage the home directory umask, default 077


Uniq: de-weight-c count

[Email protected] ~]# echo 123456 >a.txt

[Email protected] ~]# echo 123456 >>a.txt

[Email protected] ~]# echo 123456 >>a.txt

[Email protected] ~]# echo wwwww >>a.txt

[Email protected] ~]# echo wwwww >>a.txt

[Email protected] ~]# echo wwwww >>a.txt

[email protected] ~]# cat A.txt

123456

123456

123456

Wwwww

Wwwww

Wwwww

[Email protected] ~]# Uniq a.txt

123456

Wwwww

[[email protected] ~]# uniq-c a.txt (shows the number of repetitions)

3 123456

3 wwwww

Sort: Sorts-n Sort by number-R reverse-T specify delimiter-K mate-T specify number of columns

[Email protected] ~]# sort A.txt

123456

123456

123456

456789

456789

Qqqqq

Qqqqq

Qqqqq

Qqqqq

Wwwww

Wwwww

Wwwww

[Email protected] ~]# sort-n a.txt

Qqqqq

Qqqqq

Qqqqq

Qqqqq

Wwwww

Wwwww

Wwwww

123456

123456

123456

456789

456789

[Email protected] ~]# SORT-NR a.txt

456789

456789

123456

123456

123456

Wwwww

Wwwww

Wwwww

Qqqqq

Qqqqq

Qqqqq

Qqqqq




Permissions for the Linux directory:

Readable: R indicates the right to browse directories under files and directories, LS dir. (Unable to enter the directory, that cannot cd dir), if there is no X permission, the list is also a problem to see, plus-l view the property will also appear a question mark, prompt does not have permission but can see the file name.

Writable: W indicates the right to add, delete, and modify file names (typically referred to as file names) within the directory (requires X permission mates).

Executable: x indicates permission to enter the directory, for example: CD dir.


SETUID: Placeholder 4000

1. The first three digits of the user corresponding to the X-bit if there is s on the suid. When there is no X on the X-position, SUID uses S.

A 2.setuid bit is a program or command that allows an ordinary user to run a root (or other) user role in a root (or other) account, or a program command that corresponds to a file that does not have permission to operate. (Note the difference between Su and sudo).

3. Only valid for binary command programs, cannot be used on similar script files like shell (because shell scripts only invoke binary commands, so it depends on the permissions of the command itself).

4. Binary command program needs to have executable permission X.

5.suid permissions are only valid during program execution.

6. Any system user executing the command can obtain all the permissions of the corresponding owner of the command program during execution.

7.suid is a double-edged sword, is a more dangerous function, the security of the system has a certain threat. The system suid useless to cancel (the premise to evaluate whether it is useless).

8.suid priority higher than sgid


Sgid for directory: Placeholder 2000

Creating a file in the directory corresponds to the group to which the inherited directory belongs.

Number of special permissions:

suid:4000 s,sgid:2000 s, sticky bit: t










R:4 w:2 x:1-:0

Change the Permission Properties command: chmod (changing mode).

Chmod-r: Indicates recursion,

U: Owner or Superuser g: Group O: Other User A: all


Win32 executable File: *.exe,*.bat,*.com

Linux executable file: *.sh,*.py,*.perl, etc.





+: Increase-: decrease =: Clear the original into the present

Chown: Change user or user group-R (indicates recursion)

Syntax: Chown user name: User group file name

[Email protected] ~]# chown oldboy/text.txt

[Email protected] ~]# Ll/text.txt

-rwx--x-w-1 Oldboy root in 17:15/text.txt

CHGRP: Changing user groups


How to find the SUID command:

[Email protected] oldboy]# Find/usr/bin-type f-perm 4755-exec ls-l {} \;

-rwsr-xr-x. 1 root root 66352 Dec 8 2011/usr/bin/chage

-rwsr-xr-x. 1 root root 71480 Dec 8 2011/usr/bin/gpasswd

-rwsr-xr-x. 1 root root 54240 Jan 2012/usr/bin/at

-rwsr-xr-x. 1 root root 30768 Feb 2012/usr/bin/passwd

-rwsr-xr-x. 1 root root 51784 Nov 2013/usr/bin/crontab

-rwsr-xr-x. 1 root root 27576 Sep 2013/usr/bin/pkexec

-rwsr-xr-x. 1 root root 36144 Dec 8 2011/usr/bin/newgrp


FDISK disk partition command-l view list less than 2T partition tool

Parted GNU disk partitioning tool for partitioning tools larger than 2T

Mount Mount command,-T file system type-o mount option

Umount Uninstall command,-LF Force Uninstall

DD (dd IF=DEV/SDA of=mbr.bin bs=512 count=1)

MKFS format command-t file system type or MKFS.EXT3

Df-h Viewing disk mount information

Du-sh viewing the size of a file

DUMPE2FS to view file system Information


Sync: Write data to disk, async: Write Data to Memory









Shortcut key command:

CTRL + A: Cursor is set to the beginning

Ctrl+e: Cursor is set to the end

CTRL + C: Interrupt command

Ctrl+d: Logout

Ctrl+l: Clear Screen

Ctrl+u: Cut (also available for deletion.) Deletes the previous cursor. )

CTRL+K: Deletes the cursor after the.

Ctrl+r: Find History Command execution

CTRL + Z: End Process

Ctrl+s: Lock Screen

CTRL+Q: Unlocking the lock screen



















Symbol:

; Delimiter for multiple commands

/root or path delimiter

> Standard output redirection (data flow in the direction of the arrow), overwriting the original file

>> standard output append redirect (data flow flows in the direction of the arrow), without overwriting the original file

< standard input redirection

<< Chasing heavier orientation

. Represents the current directory (the file with the. Start is a hidden file).

.. Indicates a return to the top level directory

~ User's Home directory

| Pipe, give the output of the previous command to you after a command is processed

$ normal User

# Super User

{} with echo print sequence echo {1..6}

^+ letter (starting with what)

The letter or symbol +$ in the filter can be the end of what

^$ represents a space

In Find! Represents a non-

[^ Add content] is the exception to the content



A regular expression is actually some special character that gives it a specific meaning.

1.^word search begins with Word.

2.word$ search ends in Word.

3.. Represents and can only represent any one character.

4. \ example \. Escape symbols, so that characters with special identity meaning, change back to original no special meaning.

5. * Example 0* repeats one character in front of 0 or more asterisks.

6. * Matches all characters, ^.* starts with any number of characters.

7. [] Symbol for repeating special characters of the character set

8.[^word] matches the content of any character that does not include ^.

9. a\{n,m\} repeats n times to M times, preceded by a repeating character (all \ means escaped, egrep not escaped)

\{n,\} repeats at least n times, the previous character.

\{n\} repeats n this, the previous repeating character.


Extended Regular expression: ERE

1.+ repeats one or more of the preceding characters.

2.? Repeat 0 or one of the 0 preceding characters. (Repeat up to one time)

3.| Find multiple matching strings in or out of the way.

4. () find the "user group" string


This article from the "Linux" blog, reproduced please contact the author!

Linux Command Collection

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.