Instructions for common Ubuntu operating commands
Use a USB flash drive to copy compressed files
For more information about File compression methods, see 3.6 File Archive compression and its release.
The USB flash drive is directly inserted into the USB interface of the machine. Wait for the automatic pop-up window. In the pop-up window, select "file-> open terminal". The current directory of the opened terminal is the directory of the USB flash drive by default, copy the file directly in the current directory. Do not close this window.
For example,> cp/home/cps/package.tar.
Or> cp/home/cps/package.tar.gz.
In the pop-up window, select "file-> detach file volume", or find the USB flash drive icon on the desktop, right click, and select "detach file volume" from the shortcut menu ", wait for the window or icon to disappear, indicating that the USB flash drive is successfully popped up and you can unplug the USB flash drive.
Process Query
Query Process
Ps-aef | keywords of the grep process to be queried
Example:> ps-aef | grep proc
Processes with the keyword "proc" in the process name are listed in the query results.
The entries displayed in the query result include uid pid ppid c style tty time cmd.
The PID is the process number.
Example:> ps-aef | grep proc
UID PID PPID C STYLE TTY TIME CMD
Root 48 0 0 :29? 00:00:02/usr/bin/proc
Based on the preceding results, the process number to be queried is 48.
Kill a process
Kill-9 process number to be killed
For example, to kill the queried process, run the following command:
Kill-9 48
Du command to query the file system size
Use the du command to count the disk space occupied by directories (or files ).
Common:
Du-k directory name/file name or du-m directory name/file name
The difference between-k and-m is that the block-size is 1 K and 1 M respectively (that is, the unit is k and M)
If you only need to provide the total number of occupied data blocks, add the-s parameter. Otherwise, all the data blocks occupied by the subdirectories in the directory will be listed.
If you need to recursively display the number of data blocks occupied by each file in the specified directory and its Child directory, you need to add the-a parameter.
Example:> du-sm/home/cps/CPS_Project
4054/home/cps/CPS_Project
If the-s parameter is not added
Du-m/home/cps/CPS_Project
18/home/cps/CPS_Project/ubuntu/lib
1/home/cps/CPS_Project/ubuntu/data/accident
22/home/cps/CPS_Project/ubuntu/data/log
.
.
.
.
Df command to query disk space usage
The du and df commands are used to obtain information about the file system size. du is used to report the number of blocks used by the file system, and df is used to report the total number of blocks and the remaining number of blocks of the file system.
Df/home/cps
File System 1 K-block used available % mount point
/Dev/sda6 94952392 19262412 70904620 20%/home
Query multicast configurations
Netstat-r,-I, or-
-R: displays route information.
-I: displays interface information.
The execution result is as follows:
Netstat-r
You can see the multicast configuration: Network A is 228.0.0.0, corresponding to the bge0 Nic, Network B is 229.0.0.0, and corresponding to the qfe0 Nic.
File Archive compression and release
1. Create an archive (generate files suffixed with tar) and release the archive:
First, enter the directory of the directory or file to be packaged
Cd/home/cps
The absolute path must be specified in the package. If no path is specified, it is stored in the current directory by default.
Tar cvf package.tar./package /*
The archive package named package.tar is generated under the/home/cpsdirectory.
Run the following command to release the archive package:
Tar xvf package.tar
2. Archive and compress (generate an Archive with the extension tar.gz) and release the archive package
First, enter the directory of the directory or file to be packaged
Cd/home/cps
The absolute path must be specified in the package. If no path is specified, it is stored in the current directory by default.
Tar zcvf package.tar.gz./package /*
A compressed archive package named package.tar.gz is generated under the/home/cpsdirectory.
Run the following command to release the archive package:
Tar zxvf package.tar.gz
Modify file owner and permissions
1. chmod permission to change the document or directory
Command Format: chmod [-R] mode name
(Name can be the document name or directory name; mode can be 3 8-digit numbers, or use the ls-l command, the abbreviation of the permission to read, write, and execute a document or directory .)
Example:
Chmod 755 dir1 sets the directory dir1 to any user and has the right to read and execute the directory,
But only the owner can modify it.
Chmod 700 file1
Set file1 to allow only the owner to read, write, and execute the file.
Chmod u + x file2
Add the file file2 to the owner's right to execute the file.
Chmod g + x file3
Add the file file3 to the group user's right to execute.
Chmod o-r file4
Remove the file file4 from the permission that other users can read.
Chmod a-r file4
Remove all users with the right to read the file file4.
2. chmod changes the owner of a document or directory
Command Format: chown [-R] username (name can be the document name or directory name .)
Example:
Chown user file1 changes the ownership of file file1 to that of user.
Chown-R user dir1 holds the dir1 directory and all its documents and subdirectories,
Changed to user.
Query or modify the value of the DISPLAY Parameter
The DISPLAY parameter is used to set where the image is displayed. directly log on to the graphic interface or log on to the command line interface and use startx to start the image. The DISPLAY environment variable is automatically set to 0: 0, and the image is displayed in the local window.
1. query parameters
To view the value of the current DISPLAY parameter, run the following command:
Echo The DISPLAY output contains the following content: DISPLAY =: 0.0DISPLAY environment variable format: host: NumA. numB, host refers to the Host name or IP address of the Xserver. The image is displayed on this host. If the Host is empty, it indicates that the Xserver runs on the local machine and is connected using TCP, numA is the connection port minus the value of 6000. If NumA is 0, it means to connect to Port 6000. NumB is almost always 0.2. to modify the parameters, you must modify the current value of the DISPLAY parameter, run the following command, for example, exportDISPLAY =: 10.0, and then run echo. DISPLAY
The output result contains the following content:
DISPLAY =: 10.0
Indicates that the port displayed on the graphic interface is changed to 6010.
Query System resource usage
The top command is a common performance analysis tool in Linux. It can display the resource usage of various processes in the system in real time.
Top
The output result is as follows:
Top-11:04:21 up, 4 users, load average: 0.05, 0.04, 0.00
Task: 136 total, 1 running, 134 sleeping, 0 stopped, 1 zombie
Cpu (s): 0.3% us, 0.0% sy, 0.0% ni, 99.7% id, 0.0% wa, 0.0% hi, 0.0% si, 0.0% st
Mem: 2073728 k total, 746756 k used, 1326972 k free, 67212 k buffers
Swap: 10739412 k total, 0 k used, 10739412 k free, 350840 k cached
Pid user pr ni virt res shr s % CPU % mem time + COMMAND
5998 cps 20 0 21588 8636 7284 S 1 0.4. 62 multiload-apple
1 root 20 0 2844 1692 544 S 0 0.1. 40 init
2 root 15-5 0 0 S 0 0.0. 00 kthreadd
3 root RT-5 0 0 S 0 0.0 0: 00. 00 migration/0
............
The first five lines are the overall statistics of the system. The first line is the task queue information.
Second and Third, information about the process and CPU:
Tasks: 136 total process count
1. Number of running Processes of running
134 sleeping sleep Processes
0 stopped process count
0 zombie botnets
Cpu (s): 0.3% us CPU usage
0.0% sy CPU usage in kernel space
0.0% percentage of CPU used by processes that have changed their priorities in ni user process space
99.7% id idle CPU percentage
0.0% wa CPU time percentage waiting for Input and Output
Memory information of the last two behaviors:
Mem: 2073728 k total physical memory
Total physical memory used by 746756 k used
1326972 k free Memory Total
Memory usage of 67212 k buffers as kernel Cache
Swap: 10739412 k total number of Swap Areas
Total number of swap areas used by 0 k used
10739412 k free swap zone total
350840 k cached buffer swap zone total
The process information area displays detailed information about each process:
PID process id
USER: USER Name of the process owner
PR priority
NI nice value. A negative value indicates a high priority, and a positive value indicates a low priority.
% Percentage of CPU time used since the last CPU update to the present
TIME + total cpu time used by the process, in the unit of 1/100 seconds
% MEM percentage of physical memory used by the Process
Total virtual memory used by the VIRT process, in kb
Physical memory used by the RES process, Not swapped out, in kb
Size of SHR shared memory, in kb
COMMAND name/COMMAND line
View the file generation time:
Ls-l