This article detailed Linux commonly used commands and the use of methods, welcome to the collection, convenient for future use.
1. #表示权限用户 (such as: root), $ for ordinary users
Boot prompt: Login: Enter user name
Password: Enter password user is the system registered user successful landing, you can enter the corresponding user environment.
Exit Current shell, enter: Exit
2.useradd netseek Add a Netseek user
passwd Netseek to Netseek This user to set a password.
(/etc/passwd/etc/group)
Userdel Netseek Delete Account
Userdel-r Netseek Delete account with your own directory.
[For more details, see man page, and account Admin]
3. View commands
Ls-l
Show file list
Ls-al
-a displays all files and directories (LS default starts with the file name or directory name as ".") As a hidden
File, not listed)
Ls-al |grep ' ^d '
Show Table of Contents
Ls-al |grep ' ^[^d] ' queries all files in a directory that do not contain a directory
Ls-sh (man ls to view Man help.)
Linux several file types:
D indicates that this file is a directory
-Indicates that this file is a normal file
b indicates that this file is a special block device I/o file
c indicates that this file is a special character device I/O
The file command determines the type of files by probing the contents of the file
4. Create files and directories
Touch 1.txt
Cat > 2.txt (Create a file with a directional character, fill in the content, press Ctrl+d to save the content)
mkdir mywork Build mywork This directory
5. copy files or directories
CP filename1 Filename2
Cp-r dir1 DIR2 Replication Directory
CP-RF parameter f is to delete a target file that already exists without prompting
Cp-i parameters I and F, the target file will be prompted for confirmation before overwriting the target file
Is overwritten, is an interactive copy.
6. Delete files and directories (delete files or directories can be done with RM)
RM 1.c//Delete 1.c this file
RM-RF (Force delete file or directory, do not prompt when deleting.)
7. Remove the catalogue or change the file name
MV [opitons] source file or directory
[Options] Main parameters
Destination file or directory
-I: interactive operation, if the MV operation will lead to an existing target file overwrite, at this time the system asks if the heavy
Write, asking the user to answer "y" or "n",
This prevents the file from being overwritten incorrectly.
-F: Disables interaction. MV operation to overwrite an existing target file without giving any indication, specify this parameter after I
The parameters will no longer work.
MV Hello. /move the Hello directory or file to the next level.
8.alias Alias
Alias Dir= ' Ls-l ' enters Dir, which is actually equivalent to executing the LS-L
9. Control of permissions (RWX 421)
chmod +x hello.sh is assigned executable permissions.
(A detailed description of the control of permissions)
chmod Command Permission Modification usage: chmod a 8 binary number filename (rwx 421)
Eg:chmod u+x Filenmame
Just want to run for yourself, others can only read
Chown netseek.netseek mydir change user group
U: Representing the owner of the file
G: Representing the same group of users
O: Indicates other user
A: Represents all users
Opt is representative of the operation, can be:
+: Add a permission
-: Cancel a permission
=: give the given permission and revoke the original permission
and mode represents the right:
R: Readable 4
W: Can write 2
X: Executable 1
10.PWD Display current directory full path and change directory
CD Netseek into Netseek this directory
CD Exit current directory
Cd.. /go to the previous level directory.
CD-Back to previous directory
CD ~ Back to home directory
cat,more,less command.
To display the contents of a file, two different commands are: Cat print the contents of the file all the time, and more
is displayed in a separate exhibition.
Less can scroll up and down to view content.
Cat > 1.txt can fill in or copy content, press Ctrl+d to save
Cat 1.c
More 1.c
Head-n filename shows the contents of the nth line
Tail-n filename Displays the contents of the following n rows
Tail-n 20/var/log/message Displays the latest 20-line log
12. Set Linux time and date
Date command ("date MMDDHHMMYYYY.SS")
July 24, 2006 12:37, 30 seconds
Date 072412372006.30
Date-s 20:30:30 #设置系统时间为 20:30:30
Date-s 2006-7-24 #设置系统时期为 2006-7-24
Clock-r #对系统Bios中读取时间参数
Clock-w #将系统时间 (such as time set by date) to the BIOS
13. View Find Files
Several introductions:
Find path-name filename
Find/etc-name named.conf
Locate tool to search for files by file name (to first establish an index database via UpdateDB)
Localte named.conf
Whereis is looking for a binary file and will also find its Help file
Which is similar to where it is, only the set of the environment variables we set in the path of the search;
14. Killing Process
PS aux
Ps-ef |grep
Kill-9
See which process consumes the most memory
Ps-aux|sort +5n
Put programs in front of the background to perform
CP file1 File2 &
& and Ctrl+z You can use & or ctrl+z to put commands in the background to perform.
FG is the program that will be put in the background and put back in the foreground.
15.DD Command Backup
DD if= "Input_file" of= "Out_file" bs= "block_size" count= "number"
Parameters:
If: is the input file can be a device
Of: Is output file can also be a device
BS: Plan the size of a block, if not set, preset is 512bytes
Count: How many BS mean.
DD If=/etc/password Of=/tmp/passwd.bak Backup
16.mount Load a hardware device
Usage: Mount [parameters] the device mount point to load
Eg:mount/dev/cdrom
Cd/mnt/cdrom//access to the CD directory
U disk:
Mkdir/mnt/usb; (Note: Create mount directory)
Mount/mnt/sda1/mnt/usb; (Note: Mount U disk)
Now you can use the U disk, the contents of the/mnt/usb directory is the contents of the U disk;
After use, with the command to uninstall the U disk can be.
Umount/mnt/usb
Mount
List all partitions of the system
Mount-t Iso9660/dev/cdrom/mnt/cdrom
Mount-t Vfat/dev/fd0/mnt/floppy
Mount CD
Mount Floppy
Mount-t Vfat-o Iocharset=utf8,umask=000/dev/hda2/mnt/hda2
FAT32 partition
Mount
Mount-t Ntfs-o Nls=utf8,umask=000/dev/hda3/mnt/hda3
Partition
Mount NTFS
Linux-ntfs project:http://linux-ntfs.sourceforge.net/
Umount/mnt/hda3 Unloading load
Note: Before mounting the equipment, please look fdisk-l first.
17.SU switch to another identity without exiting the login
Usage: SU-L user name (switch to root if user name is default)
Eg:su-l netseek (Switch to netseek This user, will prompt for password), plus-Indicates switching to
The environment variable of the user.
Sudo leverages the permissions he can perform root execution
18.whoami,id,w,lastlog,users,groups
W View User login information
Who view current login
Last one months of user login
Lastlog check the last logon time for a particular user and format the output of the last logon log/var/log/lastlog
WhoAmI confirmed his identity.
ID prints out its UID as well as the GID. (UID: A unique identity for a user. GID: The user group identity is uniquely identified.
Each user can have only one UID and GID.
Users
Groups the user group to which the user belongs;
Finger-l Netseek Root
Finger-s or Direct finger
Allows users to query some other user's information
Eg:finger//View the user information used by the users
Finger root//view root information
19. User-used commands and execution history commands
History displays commands that the user used to kill
!! Perform the most recent command
20.uname View Linux System Information
Parameters:-A All information-R version number-N Host name
21. Establish Soft Connection
ln [-SF] source target
ln Souce-file Hard-link
LN-SF Source-file Soft-link
s indicates a soft connection, f means that if there is a file with the same name, it is overwritten.
Note: Hard links cannot be created for directories, only files can create hard links.
22. View Table of Contents
Du-sh
Directory or file
Du-m du system The default output is in kilobytes, and the parameter-M is indicated in MB.
Cat/etc/fstab
Fdisk-l
View a list of partitions
Df-h
Df-ah
23. View the resources that the Linux system occupies (top,free,uptime)
Top view background program, monitor system performance
TOP-D 2 new column every two seconds
top-d -2-p3690 View a PID
Top-b-N 2 >/tmp/top.txt The top information 2 times, and then outputs the results to/tmp/top.txt
Free-m View system memory usage
Uptime Displays the current system boot time (see how long, how many people log in, the past 1,5,15 minutes system load)
24. File Ratio software:
The CMP CMP (abbreviated by "compare") command is used to briefly indicate whether two files are different and use permissions for all users
The diff diff command is used for comparisons between two files and points to the difference between the two, and it uses permissions for all users
25. Remote operation and File transfer
SSH User@remote.machine
SCP User@remote.machine:/remote/path/local/path
Scp/local/path User@remote.machine:/remote/path
26. Compile the C + + file
Gcc
Gcc-v View GCC version
Gcc-o Test test.c 2>errfile Compile the test.c with an error message, redirect the error message to the Errfile
27.chattr +i filename Prohibit deletion, chattr-i filename cancellation prohibited
Lsattr View Hidden file properties
28. Automated implementation
At execution once
crontab Timer Cycle Execution procedure
Crontab Introduction
1 log in as root
2 # CRONTAB-E
3 Join a line
1 */12 * * */usr/sbin/ntpdate pool.ntp.org
Minutes
Small Hours
(0-59)
(0-23)
Date (1-31)
Month
(1-12)
Week
(0-6)//0 representative on Sunday
29. Shutdown and reboot:
Shutwond [-t-seconds] [-RKHNCFF] time [warning message]
-T seconds: Sets the delay time (in seconds) between warning and deletion of the two signals before switching to a different runlevel
-K issued a warning message, but not really to shutdown
-R shutdown reboot after this
-H shutdown This rear boot
-N does not go through init, by the shutdown command itself to boot work (not recommended)
When-F restarts, skips the fsck instruction and does not check the file system.
When-F restarts, force a fsck check.
-C cancels the action already being shutdown
Shutdown-h now shuts down immediately, in which time is 0,halt,poweroff or shut down, or direct init 0
Shutdown-h 20:30 system will be shut down in 8:30 tonight.
The Shutdown-h +10 system automatically shuts down after 10 minutes.
Shutdown-t3-r now reboots immediately, but in the warning and deletion processes this room,
Shutdown-k Now ' hey! Go away! Now ... ' Send a warning message, but there is no real shutdown.
Reboot
Shutdown-r now is almost the same as reboot, not related to the proposed reboot execution as follows:
Shutdown-r +30 ' The system Wiil reboot '
Shutdown-r +10 ' hey! Go away! ' The system reboots after 10 minutes.
#sync; Sync Sync Reboot Note: Sync writes data to the hard disk synchronously
The halt command is equivalent to shutdown-h now, which means that the machine shuts down immediately.
The reboot command is equivalent to Shutown-r now, which means that it immediately resets.
30. How to change the startup mode run level
Vi/etc/inittab
Change the 5 to 3, and it will turn into character mode after startup.
StartX or init 5 can enter the graphical interface.
RunLevel Display current run level
How to switch to single user mode
Use Telinit or init (in fact Telinit is just a synbol link to init)
Telinit 1 or Init s can, of course, Telinit S is ok.
How to make Ctrl+alt+del three key failure method
#vi/etc/inittab
Add a comment before ca::ctrlaltdel:/sbin/shutdonw-t3-r now #
Then execute #telinit q, the parameter q is to Telinit again/etc/inittab
31.TAB using the TAB key, when you do not know the full name of the file or command, please press the TAB key continuously.
32.clear Clear Screen
33.DMESG |more Display boot information (view hardware information at system startup)
34. Change the performance of the program to a good level
Nice
Set Priority Nice-n-5 VI & with ROOT to a nice value of-5, used to perform VI
Renice adjustment already exists priority
35. Module-related commands
LSMOD displays modules that have been loaded into the system
Depmod analysis of the dependencies of the loading system
Modinfo display information for kernel modules
Insmod Loading Module
Modprobe Automatic Process Loading module
Rmmod Delete Module
The 36.chkconfig--list displays the status of various services and makes it easy to manage the init script with Chkconfig.
Several decompression commands for 37.linux
Compress AAA to compress AAA files into AAA. Z
compress-d aaa.z to compress aaa.z files into AAA
Gzip AAA Compression Command
gzip-d aaa.gz Decompression Command
Bzip2-z filename compression, ditto plus-D parameter decompression
Bzcat filename.bz View Compressed file contents
Tar czvf aaa.tar.gz AAA compresses catalog AAA into aaa.tar.gz
Tar-n ' 2007/03/01 '-ZCVF home.tar.gz/home in/home, is backed up by a new file in 2007/03/01.
Tar--exclude/home/cao-zxvf myfile.tar.gz/home/*/etc to back up/home,/etc, but don't/home/cao
cd/tmp; TAR-CVF-/etc | TAR-XVF-After packing the/etc/, untie/tmp directly, without producing a file.
Tar zxvf aaa.tar.gz decompression command.
Tar jxvf aaa.tar.bz2 Decompression command
Tar zxvf aaa.tar.gz-c/var/www extract aaa.tar.gz to/var/www directory
Cpio-covb > [File|device] Backup
Cpio-icduv < [file|device] Restore
38. Network command
Ifconfig display or set up a network device, you can view the current IP, similar to the ipconfig in Windows
Service Networkrestart (/etc/rc.d/init.d/network restart) Reboot network card
Ifdown eth0 off the NIC
Ifup eth0 Open Network card
Route-n View routing Table
Route add-net 192.168.20.1 netmask255.255.255.0 Dev eth0
Netstat View network connectivity
Netstat-i display of network card operation
Netstat-r View the list of routes for a host
Traceroute
Hostname Display host name
HOSTNAME-I Displays the IP of the current host name.
39. System Integration Management menu.
Setup System service Management command
NTSYSV Set up system services
40.FDISK/MBR Delete Grub
41. Database Startup
Start MySQL:
Service mysqld Start (/etc/rc.d/init.d/mysqldstart)
Mysql-uroot-p Enter the password to operate the MySQL database.
Start Oracle
Su-oracle
$lsnrctl stop
$lsnrctl start
Sqlplus/nolog
Conn/as SYSDBA (connected)
Startup
42. Install Package
RPM Package Installation:
RPM-IVH xxx.rpm
Install the RPM package
Rpm-qa--last | Less
Display packages that have been installed based on the installation date
RPM-QA |grep mysql-i Query System install MySQL package (-I, ignore case)
RPM-E to remove installed packages
RPM-E mysql*--nodpes forced deletion of related packages
RPM--test Test Installation
Rpm-qi Query MySQL Suite description information
RPM-QPL xxx.rpm View the contents of the RPM package.
RPM-QC[D] Profile and specification file
RPM-UVH Upgrade Installation
Rpmbuild--BB Specs/xxx.spec will be xxx.spec compiled into an RPM package.
Rpmbuild--rebuild packagename.src.rpm again, src.rpm compiled into an RPM package.
Source code compilation installation (classic)
./configure Check System Information (./configure--help | More help information, you can see the relevant parameter settings)
Make clean erase files left before
Make compilation
Make install Installation
Note: Source package installation, the general will first extract the file, installation process is generally above a few steps, specific description of the general opinion after the catalogue
(install,reademe description.)