Ubuntu Common commands)

Source: Internet
Author: User

Ubuntu Common commands

From: http://www.blogjava.net/bukebushuo/archive/2009/08/27/283427.html

View the installation content of software xxx
# Dpkg-l xxx

Search software
# Apt-cache search Regular Expression
Find the package of the file
# Dpkg-s filename apt-file search filename

Queries which packages the software XXX depends on
# Apt-Cache depends xxx

Queries which packages depend on the software xxx
# Apt-Cache rdepends xxx

Add a CD Source
# Sudo apt-CDROM add

System Upgrade
# Sudo apt-Get update
# Sudo apt-Get upgrade
# Sudo apt-Get dist-Upgrade

Clear the residual configuration file of the deleted package.
# Dpkg-L | grep ^ RC | awk '{print $2}' | tr ["" N "] [" "] | sudo xargs dpkg-p-

Automatic Processing of H files is missing during compilation
# Sudo auto-apt run./configure

View the temporary directory for storing downloaded packages during software installation
# Ls/var/Cache/APT/Archives

Back up the list of all packages installed in the current system
# Dpkg-get-selections | grep-V deinstall> ~ /Somefile

Restore all packages from the list file of the installation package backed up above
# Dpkg-set-selections <~ /Somefile sudo dselect

Clear old software caches
# Sudo apt-Get autoclean

Clear all software caches
# Sudo apt-Get clean

Delete isolated software that is no longer used by the System
# Sudo apt-Get autoremove

View the address of the package on the server
# Apt-get-QQ-print-Uris Install SSH | cut-d "'-F2

System
View the kernel
# Uname-

View Ubuntu version
# Cat/etc/issue

View the modules loaded by the kernel
# Lsmod

View PCI devices
# Lspci

View USB devices
# Lsusb

View Nic status
# Sudo ethtool eth0

View CPU Information
# Cat/proc/cpuinfo

Display current hardware information
# Lshw

Hard Disk
View Hard Disk Partitions
# Sudo fdisk-l

View IDE Hard Disk Information
# Sudo hdparm-I/dev/hda

View stat hard disk Information
# Sudo hdparm-I/dev/SDA
Or
# Sudo apt-Get install blktool
# Sudo blktool/dev/SDA ID

View remaining disk space
# DF-H
# DF-H

View space occupied by Directories
# Du-HS directory name

The USB flash drive cannot be detached.
# Sync Fuser-km/Media/usbdisk

Memory
View Current memory usage
# Free-m

Process
View Processes
# Ps-
Abort a process
# Kill process number (the number in the first column of PS-A) or killall process name

Force stop a process (used when the process failed to be aborted)
# Kill-9 process no. Or killall-9 process name

StopProgram
# Xkill the mouse with the skeleton icon. Click the program to be aborted.

View the real-time status of the current process
# Top

View files opened by a process
# Lsof-P

Configure ADSL
# Sudo pppoeconf

ADSL Manual dialing
# Sudo Pon DSL-provider

Activate ADSL
# Sudo/etc/PPP/pppoe_on_boot

Disconnect ADSL
# Sudo poff

View dialing logs
# Sudo plog

How to Set dynamic domain names
# First go to the http://www.3322.org to apply for a dynamic domain name
# Then modify/etc/PPP/IP-up to update the domain name command sudo Vim/etc/PPP/IP-up when dialing.
# Add the following line w3m-no-cookie-dump at the end

Network
Query Nic addresses based on IP addresses
# Arping IP Address

View current IP Address
# Ifconfig eth0 | awk '/inet/{split ($2, X, ":"); print X [2]}'

View the IP address of the current Internet
# W3m-no-Cookie -dumpwww.edu.cn | grep-o '[0-9] "{1, 3 "}". [0-9] "{1, 3 "}". [0-9] "{1, 3 "}". [0-9] "{1, 3 "}'
# W3m-no-Cookie -dumpwww.xju.edu.cn | grep-o '[0-9] "{1, 3 "}". [0-9] "{1, 3 "}". [0-9] "{1, 3 "}". [0-9] "{1, 3 "}'
# W3m-no-cookie-dump ip.loveroot.com | grep-o '[0-9] "{1, 3 "}". [0-9] "{1, 3 "}". [0-9] "{1, 3 "}". [0-9] "{1, 3 "}'

View the program listening to port 80
# Lsof-I: 80

View the physical address of the current Nic
# ARP-A | awk '{print $4}' ifconfig eth0 | head-1 | awk '{print $5 }'

Enable the network to support NAT now
# Sudo Echo 1>/proc/sys/NET/IPv4/ip_forward
# Sudo iptables-T nat-I postrouting-J Masquerade

View route information
# Netstat-Rn sudo route-n

Manually add or delete a route entry
# Sudo route add-net 192.168.0.0 netmask 255.255.255.0 GW 172.16.0.1
# Sudo route del-net 192.168.0.0 netmask 255.255.255.0 GW 172.16.0.1

How to modify the MAC address of a NIC
# Sudo ifconfig eth0 down disable Nic
# Sudo ifconfig eth0 HW ether 00: AA: BB: CC: DD: EE and change the address
# Sudo ifconfig eth0 up and then start the NIC

Count the number of current IP connections
# Netstat-Na | grep established | awk '{print $5}' | awk-F: '{print $1}' | sort | uniq-c | sort-r-n
# Netstat-Na | grep SYN | awk '{print $5}' | awk-F: '{print $1}' | sort | uniq-c | sort-r-n

Count the IP addresses of up to 20000 IP packets in the current 100 IP Packets
# Tcpdump-tnn-C 20000-I eth0 | awk-F ". '{print $1 ″. "$2 ″. "$3 ″. "$4} '| sort | uniq-c | sort-Nr | awk' $1> 8080'

Mask IPv6
# Echo "blacklist IPv6" | sudo tee/etc/modprobe. d/blacklist-ipv6

Service
Add a service
# Sudo update-rc.d service name defaults 99

Delete a service
# Sudo update-rc.d service name remove

Temporarily restart a service
#/Etc/init. d/service name restart

Temporarily close a service
#/Etc/init. d/service name stop

Start a service temporarily
#/Etc/init. d/service name start

Set
Configure which Java is used by default
# Sudo Update-alternatives-config Java

Modify user information
# Sudo chfn userid

Set proxy for Apt
# Export http_proxy = http://xx.xx.xx.xx: XXX

Modify system logon information
# Sudo Vim/etc/motd

Chinese
Convert the file name from GBK to utf8
# Sudo apt-Get install convmv-r-F cp936-T utf8-notest-nosmart *

Batch convert all files in the src directory from GBK to utf8
# Find Src-type D-exec mkdir-P utf8 /{}"; find Src-type F-exec iconv-f gbk-T UTF-8 {}-O utf8/{} "; MV utf8/* SRC Rm-fr utf8

Convert the file content from GBK to utf8
# Iconv-f gbk-T utf8 $ I> newfile

Convert MP3 tag Encoding
# Sudo apt-Get install Python-mutagen find.-INAME "*. MP3"-execdir mid3iconv-e GBK {}";

Display Chinese characters in the console
# When Using sudo apt-Get install zhcon, enter zhcon.

File
Quickly search for a file
# Whereis filename
# Find directory-name file name

View File Types
# File filename

Display the last six lines of XXX File
# Tail-N 6 XXX

Let tail keep reading the latest content
# Tail-N 10-F/var/log/apache2/access. Log

View the content between the fifth line (inclusive) and the second line (inclusive) in the file.
# Sed-n'5, 10p'/var/log/apache2/access. Log

Search for files containing XXX strings
# Grep-l-r xxx.

Full file search (desktop visualization)
Gnome-search-Tool

Query XXX commands
# Apropos XXX man-K xxx

Transfer files through SSH
# SCP-RP/path/filenameusername @ remoteip:/path
# Copy a local file to the server
# SCP-rpusername @ remoteip:/path/filename/path
# Download a remote file from the server to your local computer

View the applications that read and write a file.
# Lsof file name

Change the suffix of all files from RM to rmvb
# Rename's/. rm $/. rmvb /'*

Replace uppercase letters in all file names with lowercase letters.
# Rename 'tr/A-Z/a-z /'*

Delete a file with a special file name, for example, file name: -help.txt
# Rm--help.txt or RM./-help.txt

View subdirectories of the current directory
# Ls-D */. Or echo */.

Move the files in the current directory that have been accessed in the last 30 days to the upper-level back directory.
# Find.-Type F-atime-30-exec MV {} ../back ";

Display the files in the current directory within the last 2 hours to 8 hours
# Find.-mmin + 120-mmin-480-exec more {}";

Delete all files modified 30 days ago
# Find.-Type F-mtime + 30-mtime-3600-exec RM {}";

Search for and delete the file ending with Avi or RM of the guest user.
# Find.-Name '*. avi'-o-name' *. rm '-user 'guest'-exec RM {}";

The files found do not end with Java or XML and are not used for seven days.
# Find .! -Name *. Java! -Name '*. xml'-atime + 7-exec RM {}";

Count the number of current files
# Ls/usr/bin | WC-W

Count the number of current directories
# Ls-L/usr/bin | grep ^ d | WC-l

Display the file name of 2006-01-01 in the current directory
# Ls-L | grep 2006-01-01 | awk '{print $8 }'

FTP
File upload and download tool-filezilla
# Sudo apt-Get install filezilla

Filezilla cannot list Chinese directories?
Site-> Character Set-> Custom-> input: GBK

Local Chinese interface
1) download the filezilla Chinese package to a local directory, such ~ /
2) # unrar x filezilla3_zhcn.rar
3) If you do not have unrar, install RAR and unrar first.
# Sudo apt-Get install RAR unrar
# Sudo ln-F/usr/bin/RAR/usr/bin/unrar
4) back up the original language pack before installing it. Actually, copy a Language Pack.
# Sudo CP/usr/share/locale/zh_cn/filezilla.mo. Bak
# Sudo CP ~ /Locale/zh_cn/filezilla.mo/usr/share/locale/zh_cn/filezilla.mo
5) Restart filezilla!

Extract
Decompress xxx.tar.gz
# Tar-zxvf xxx.tar.gz

Decompress xxx.tar.bz2
# Tar-jxvf xxx.tar.bz2

Compress AAA bbbdirectory as xxx.tar.gz
# Tar-zcvf xxx.tar.gz aaa bbb

Compress AAA bbbdirectory as xxx.tar.bz2
# Tar-jcvf xxx.tar.bz2 aaa bbb

Extract RAR files
1) first install
# Sudo apt-Get install RAR unrar
# Sudo ln-F/usr/bin/RAR/usr/bin/unrar
2) decompress
# Unrar x aaaa.rar

Decompress the ZIP file
1) first install
# Sudo apt-Get install zip unzip
# Sudo ln-F/usr/bin/zip/usr/bin/unzip
2) decompress
# Unzip x aaaaaa.zip

Nautilus
Show Hidden Files
CTRL + H

Show Address Bar
CTRL + L

Special URI address
* Computer: //-all mounted devices and networks
* Network: //-browse Available Networks
* Burn: // a data virtual directory for burning CdS/DVDs
* SMB: //-available Windows/samba Network Resources
* X-Nautilus-desktop: //-desktop project and icon
* File: //-local file
* Trash: //-local recycle bin directory
* Ftp: //-FTP folder
* SSH: //-ssh folder
* Fonts: //-font folder. You can drag the font file here to complete the installation.
* Themes: //-system topic folder

View installed Fonts
Enter "fonts: //" in the address bar of Nautilus to view all the fonts on the local machine.

Program
Detailed display of program running information
# Strace-f-o OUTFILE

Date and Time

Set date
# Date-s mm/DD/yy

Set Time
# Date-s hh: mm

Write time to CMOS
# Hwclock-systohc

CMOS read time
# Hwclock-hctosys

Synchronize time from the server
# Sudo ntpdate time.nist.gov
# Sudo ntpdate time.windows.com

Console

Switch between different consoles
CTRL + ALT + ↓ CTRL + ALT + →

Console switch
CTRL + ALT + FN (N: 1 ~ 7)

Console scrolling
Shift + Pageup/Pagedown

Console screenshot
# Setterm-dump n (n: 1 ~ 7)

Database
Place Mysql Data Inventory
#/Var/lib/MySQL

Export and import data from MySQL
# Mysqldump Database Name> file name # Export Database
# Mysqladmin create database name # create a database
# MySQL database name <file name # import database

What should I do if I forget the MySQL Root Password?
# Sudo/etc/init. d/MySQL stop
# Sudo mysqld_safe-Skip-grant-tables
# Sudo mysqladmin-u User Password 'newpassword"
# Sudo mysqladmin flush-Privileges

Modify the root password of MySQL
# Sudo mysqladmin-uroot-P password 'your new password'

Others
Download website documentation
# Wget-r-p-NP-khttp: // www.21cn.com
· R: Create a server directory structure on the local machine;
·-P: Download and display all images of HTML files;
·-NP: only download the contents of the specified directory and Its subdirectories of the target site;
·-K: convert non-relative links to relative links.

How to delete the playback history of a totem player
# Rm ~ /. Recently-used

How to replace the shortcut key of the gnome Program
Click the menu and move your mouse over a menu. Enter any key you need on the keyboard, which can be a combination key and will take effect immediately. To clear the shortcut key, use backspace.

How to display color characters in VIM
# Sudo CP/usr/share/Vim/vimcurrent/vimrc_example.vim/usr/share/Vim/vimrc

How to delete the startup program set in the session on the command line
# Cd ~ /. Config/autostart RM need to delete the Startup Program

How to Improve wine response speed
# Sudo sed-Ie '/GBK/,/^}/D'/usr/share/X11/locale/zh_CN.UTF-8/xlc_locale

# Chgrp
[Syntax]: chgrp [-R] File Group...
[Note]: the GID of a file indicates the file group of the file. The file group can be represented by numbers or a valid group name. This command changes the GID of a file. For more information, see chown.
-R recursively changes the access mode of all files in all subdirectories.
[Example]:
# Change the file group of the file to group in chgrp group file.

# Chmod
[Syntax]: chmod [-R] mode file...
Or chmod [ugoa] {+ |-| =} [rwxst] File...
[Note]: changes the file access mode. The access mode can be expressed as a number or a symbol string, for example:
# Chmod NNNN file, where n is a number between 0 and 7, the meaning is as follows:
4000 uid can be changed during runtime
2000 GID can be changed during runtime
1000 stick position
0400 file master readable
0200 file master writable
0100 file master executable
0040 readable for users in the same group
0020 users in the same group can write
0010 users in the same group can execute
0004 other user readable
0002 other users can write
0001 Executable by other users
NNNN is obtained by adding the numbers in the upper column. For example, chmod 0777 file sets the file access permission to readable and executable by all users.
-R recursively changes the access mode of all files in all subdirectories.
U file master
G same group users
O other users
A All Users
+ Added the post-column permission.
-Cancel the post-column permission
= Post-column permission
R readable
W writable
X executable
UID can be set during s operation
T indicates that GID can be set during running.
[Example]:
# Chmod 0666 file1 file2 set file1 and file2 to readable and writable for all users
# Chmod U + X file: add the file master executable permission to the file
# Chmod o-rwx cancel all permissions of other users on file

# Chown
[Syntax]: chown [-R] File master file...
[Note]: The file uid indicates the file master. The file master can be represented by numbers or a valid user name. This command changes the UID of a file, only when the file master or super user of this file is available.
-R recursively changes the access mode of all files in all subdirectories.
[Example]:
# Chown Mary file: Change the file master of the file to Mary
# Chown 150 file: Change the file UID to 150

Modify the network configuration under the Ubuntu command line
Taking eth0 as an Example
1. Configure the NIC in DHCP Mode
Edit the file/etc/Network/interfaces:
# Sudo VI/etc/Network/interfaces
Replace eth0 with the following rows:
# The primary network interface-use DHCP to find our address
Auto eth0
Iface eth0 Inet DHCP
Run the following command to make the network settings take effect:
# Sudo/etc/init. d/networking restart
Of course, you can also enter the following command under the command line to obtain the address
# Sudo dhclient eth0

2. configure a static IP address for the NIC
Edit the file/etc/Network/interfaces:
# Sudo VI/etc/Network/interfaces
Replace eth0 with the following rows:
# The primary network interface
Auto eth0
Iface eth0 Inet static
Address 192.168.3.90
Gateway 192.168.3.1
Netmask 255.255.255.0
Network 192.168.3.0
Broadcast 192.168.3.255
Replace the above IP address and other information with your own.

Run the following command to make the network settings take effect:
# Sudo/etc/init. d/networking restart

3. Set the second IP address (virtual IP address)
Edit the file/etc/Network/interfaces:
# Sudo VI/etc/Network/interfaces
Add the following lines to the file:
Auto eth0: 1
Iface eth0: 1 Inet static
Address 192.168.1.60
Netmask 255.255.255.0
Network x. x
Broadcast x. x
Gateway x. x
Fill in all information such as address, netmask, network, broadcast, and gateways according to your situation.
Run the following command to make the network settings take effect:
# Sudo/etc/init. d/networking restart

4. Set Host Name (hostname)
Run the following command to view the Host Name of the current host:
# Sudo/bin/hostname
Run the following command to set the Host Name of the current host:
# Sudo/bin/hostname newname
When the system starts, it reads the host name from/etc/hostname.

5. Configure DNS
First, you can add some host names to/etc/hosts and the IP addresses corresponding to these host names. This is a simple static query on the local machine.
To access the DNS server for query, you need to set the/etc/resolv. conf file.
If the IP address of the DNS server is 192.168.3.2, the content of the/etc/resolv. conf file should be:
Search test.com
Nameserver 192.168.3.2

Install the amp service
If you start installation with Ubuntu server CD, you can choose to install it. The system automatically installs apache2, PhP5, and mysql5. The following describes how to install Ubuntu server if it is not installed.
Using a command to set up lamp in Ubuntu is actually very simple. You can use a single command to complete it. Enter the following command on the terminal:
# Sudo apt-Get install apache2 mysql-server PhP5 php5-mysql # phpMyAdmin
After installation, the MySQL administrator is root and has no password. You can access MySQL through http: // localhost/phpMyAdmin.

Modify MySQL password
Terminal input:
# Mysql-u Root
# Mysql> grant all privileges on *. * to root @ localhost identified by 123456 ″;
'123' is the root password and can be set as needed, but it is best to set a security point.
# Mysql> quit; exit MySQL

Apache2 Operation Command
Start: # sudo/etc/init. d/apache2 start
Restart: # sudo/etc/init. d/apache2 restart
Close: # sudo/etc/init. d/apache2 stop
Default home directory of apache2:/var/www/

 

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.