Linux Common Commands
(1) Command ls--list files
Ls-l listing the details of a file
Ls-la gives a long list of all the files in the current directory, including a "hidden" file that begins with a period
LS A * lists all files in the current directory that begin with the letter A
Ls-l *.sh gives all files in the current directory ending with. sh
(2) command cp--copy files
CP afile Afile.bak Copy the file as a new file Afile.bak
CP afile/home/bible/Copy the file Afile from the current directory to the/home/bible/directory
CP */tmp copies all hidden files in the current directory to the/tmp/directory
CP-A Docs Docs.bak recursively copies the docs directory under the current directory to the new directory Docs.bak, preserves the file attributes, and copies all the files, including hidden files that begin with a period.
(3) command mv--to move and rename files
MV Aflie bfile Renaming afile to bfile
MV Afile/tmp Move the afile under the current directory to the/tmp/directory
(4) Command rm--delete files and directories
RM afile Deleting files Afile
RM-RF domed Delete the domed directory and all the content it contains
which
-R: Down recursive delete
-F: Directly forcibly removed without any hint
(5) Command cd--change Directory
CD ~ Switch to home directory
CD/TMP switch to Directory/tmp
cd dir switch to dir directory in current directory
CD/Switch to root directory
Cd.. Switch to the top level directory
Cd.. /.. Switch to the top level two directory
(6) command mkdir--to create a directory
mkdir phots to create a directory named photos in the current directory
Mkdir-p a/b/c Creating a specified nested subdirectory under the current directory
Mkdir-m 777 Test3 Create test3 directory with permissions of 777
Mkdir-p A/{a,b,c} Create an ABC three subdirectory in the a directory at the same time
(7) Command grep--search for file contents
grep Bible/etc/exports finds all rows that contain Bible in file exports
Tail-100/var/log/apache/access.log|grep 404 finds rows that contain "404" in the 100 rows of the Web server log file Access.log
(8) Command find--Find files
Find-name test finds the Test folder in the current directory and returns its path
Find |grep test finds files in the current directory and its subdirectories with the file name containing test
Locate test Find the file name that contains test in any part of the system
(9) Command cat--display file contents
Cat a.txt Show content in A.txt
(10) Command ps--view process
PS [Options]
DESCRIPTION (description): PS command displays some information about the run program options. If you want to display some duplicate information for an option, use the top command instead.
Use standard syntax to view each process on the system.
Ps-e
Ps-ef
Ps-ef
ps-ely
(11) Command top--view CPU, memory
(12) Command pwd--view current path
(13) Order tar--package, unpack rar
TAR-CVF Ab.tar a.jsp B.java a.jsp and B.java into Ab.rar
TAR-XVF **.tar a.jsp B.java **.tar Unpacking
(14) Command tail--view file details
Tail-f Aaa.txt See more information of aaa.txt file
Tail-n x Aaa.log x: Last few lines
(15) Command ln--to establish a connection
ln source_path Target_path Hard Connection
Ln-s source_path Target_path Soft Connection
(16) command touch--create an empty file
Touch Aaa.txt creates an empty file with a file name of Aaa.txt
(+) VI
One, vi open edit file
Example: VI test.conf,vi/tmp/test.conf, ...
If the specified filepathandname is present, the contents of the file are automatically loaded and automatically created if it does not exist.
Note: A wave symbol is displayed before each line to indicate that the behavior is blank line.
Second, vi into the input mode
VI works in two modes: instruction mode and input mode. The instruction mode is the default mode mode after the file is opened, and any character entered is considered a control instruction. Input mode is the normal editing mode, at this time input word defaults think input content.
Third, vi editing instructions
1, Screen page
Ctrl+u: Flip up half screen
Ctrl+f: Turn up one screen
Ctrl+d: Flip Down half screen
CTRL+B: Flip one screen down
2. Move cursor Instruction
Moving the cursor is commonly used in the direction of the key, consider compatibility issues, vi definition too many direction instructions, the following is just a small part (common several):
Space: Move the cursor right one character
Backspace: Cursor moves left one character
Enter: Move the cursor down one line
NG: Cursor moves to the beginning of nth
n+: The cursor moves down n rows
N: Move the cursor up n rows
n$: Cursor moves to end of Nth line
0: Cursor moves to the beginning of the current line
$: Cursor moves to the end of the current line
3. Insert Delete Instruction
Common insert and delete directives are as follows:
I: Insert before current cursor, text moves backwards after cursor
A: Inserted after the current cursor, after the cursor text is moved
I: Insert at the beginning of the cursor (the first non-whitespace character match either)
A: Insert from the end of the line where the cursor is located
O: Add a row below the cursor line (and enter the input mode)
O: Add a row above the cursor line (and enter the input mode)
X: Delete the character of the cursor, equivalent to the [delete] function key
X: Delete cursor before character, equivalent to [Backspace]
DD: Delete the line where the cursor is located
R: Modify the character of the cursor
R: Replace the current character and its characters until you press [ESC]
S: replaces the specified number of characters with the input text starting at the current cursor position
S: Deletes the specified number of rows and replaces them with the input text
Do: Delete to the beginning of the line
d$: Delete to end of line
Iv. Vi. exit
To exit input mode, click the [ESC] key (sometimes double-click), and then execute:
: w--Save current file
: wq--Save (same as command: x function)
: q--Direct exit, if modified will prompt to save
: q! --Do not save direct exit
(18) Command uname--View system version
Uname-r shows the version of the operating system kernel
(19) Command reboot, shutdown--shut down and restart the computer
Reboot restart your computer
Shutdown-r Now restarts the computer, stops the service, and then restarts the computer
Shutdown-h now shut down the computer, stop the service, and then shut down the system
Halt shutting down the computer
Generally with Shutdown-r now, in rebooting the system is to close the related services, Shutdown-h now is also the case.
(20) command su--Switch User
Su-Switch to root user
Su-test switch to test user,
Note:--he is critical, using--that will use the user's environment variable
(21) Command free--view memory and swap partition usage
sarge:~# Free-tm
(22) Command uptime--the current time, the system is running to the current elapsed time, the number of users connected, the last minute, five minutes and 15 minutes of system load
sarge:~# Uptime
(23) Command vmstat--Monitor virtual memory usage
# Vmstat
(24) Command iostat--disk throughput
-C Displays only CPU rows
-D Display Disk rows
-k displays disk output in kilobytes
-T includes timestamps in the output
-X includes extended disk metrics in the output
(25) Command clear--clear Screen
(26) Start-up service
Service Name Start
(27) Resources
View memory usage and swap usage
Free-m
View the usage of each partition
Df-h
To view the size of a specified directory
Du-sh < directory name >
View Total Memory
grep memtotal/proc/meminfo
To view the amount of free memory
grep memfree/proc/meminfo
View system uptime, number of users, load
Uptime
View System Load
Cat/proc/loadavg
(28) disks and partitions
To view the status of a mounted partition
Mount | Column-t
View all partitions
Fdisk-l
View all swap partitions
Swapon-s
View disk parameters (for IDE devices only)
Hdparm-i/dev/hda
To view IDE device detection status at startup
DMESG | grep IDE
(29) Network
To view the properties of all network interfaces
Ifconfig
View firewall settings
Iptables-l
View the routing table
Route-n
View all listening ports
Netstat-lntp
View all connections that have been established
Netstat-antp
View network Statistics
Netstat-s
(30) process
View All Processes
Ps-ef
Show process status in real time
Top
(31) Service
List all system services
Chkconfig--list
List all system services that are started
Chkconfig--list | grep on
Linux Common Commands