Linux common commands (2)

Source: Internet
Author: User
Tags clear screen diff time and date rpmbuild

1.# represents a privileged user (for example: Root), $ represents a normal user
Boot prompt ogin: Enter user name
Password: Enter password user is the system registered user successfully login, 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 the account along with your home directory.
[For more details, see man page, and account management]

3. View commands
Ls-l Display file list
LS-AL-A displays all files and directories (LS-default starts the file name or directory name as ".") As hidden files, not listed)
Ls-al |grep ' ^d ' Display directory
Ls-al |grep ' ^[^d] "querying all files in a directory that do not contain a directory
Ls-sh (man LS view man help.)

Several file types for Linux:
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 file
      L indicates that this file is a connection file. The path and name of the file to which it is attached immediately after its file name

      The file command determines the document type by probing the file contents

4. creating 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 Set up mywork this directory

5. Copying Files or directories
CP filename1 Filename2
Cp-r dir1 dir2 Copy Directory
The CP-RF parameter f is to delete a target file that already exists without prompting
Cp-i parameters I and f instead, a prompt is given before overwriting the target file that asks the user to confirm that the target file will be overwritten when the answer is Y and 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 directory or change the file name
MV [opitons] source file or directory destination file or directory
[Options] Main parameters
-I: interactive operation, if the MV operation will cause an overwrite of the existing target file, the system asks whether to rewrite, asks the user to answer "y" or "n",
This avoids overwriting the file by mistake.
-F: Disables interactive operation. MV operation to overwrite an existing target file without giving any indication, after specifying this parameter the I parameter will no longer work.
MV Hello.. /move the Hello directory or file to the previous level.

8.alias aliases
Alias dir= ' ls-l ' input dir is actually equivalent to performing a ls-l

9. Control of permissions (RWX 421)
chmod +x hello.sh is assigned to executable permissions.
(Details about the control of permissions)
chmod Command Permission Modification usage: chmod one 8 binary number filename (rwx 421)
Eg:chmod u+x Filenmame just want to run for himself, others can only read
Chown netseek.netseek mydir change user group

u:表示文件所有者g:表示同组用户o:表示其它用户a:表示所有用户opt则是代表操作,可以为:+:添加某个权限-:取消某个权限=:赋予给定的权限,并取消原有的权限而mode则代表权限:r:可读 4w:可写 2 x:可执行 1

10.pwd Show current directory full path and change directory
CD Netseek Enter Netseek this directory
CD Exit current directory
Cd.. /go to the top level directory.
CD-Back to last catalog
CD ~ Back to home directory

    1. cat,more,less command
      The contents of a file are displayed, and the two commands differ: Cat Prints the contents of the file and the more is displayed.
      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 Displays the contents of the nth row
      Tail-n filename Displays the contents of the following n rows
      Tail-n 20/var/log/message Show the latest 20 rows of logs

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 the time set by date, is written to the BIOS

13. Look for files (Find,grep,awk more please refer to man page or Shell programming topic)
Several introductions:
Find path-name file name
Find/etc-name named.conf
Locate tool to search for files by file name (to establish an index database first through UpdateDB)
Localte named.conf
Whereis is looking for a binary file and will also find its Help file
Which and where are similar, just the set of environment variables we set in the path to find;

14. Avira Process
PS aux
Ps-ef |grep
Kill-9
See which process consumes the most memory
Ps-aux|sort +5n

Put the program in front of the background execution
CP file1 File2 &
& and CTRL + Z you can use & or CTRL + Z to place commands in the background.
FG is a program that is executed in the background and then put back in the foreground.
Jobs

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: The output file can also be a device
BS: Plan the size of a block, if not set, the preset is 512bytes
Count: How many BS means.

DD If=/etc/password Of=/tmp/passwd.bak Backup

16.mount Loading a hardware device
Usage: Mount [parameter] the device load point to load
Eg:mount/dev/cdrom
Cd/mnt/cdrom//Enter the disc directory
U disk:
Mkdir/mnt/usb; (Note: Create mount directory)
Mount/mnt/sda1/mnt/usb; (Note: Mount USB drive)
Now you can use a USB stick, the content in the/MNT/USB directory is the content of the U disk;
When you are finished, use the command to uninstall the USB flash drive.
Umount/mnt/usb
Mount lists all of the system's partitions
Mount-t Iso9660/dev/cdrom/mnt/cdrom Mount Disc
MOUNT-T vfat/dev/fd0/mnt/floppy Mount floppy disk
MOUNT-T Vfat-o IOCHARSET=UTF8,UMASK=000/DEV/HDA2/MNT/HDA2 Mount FAT32 partition
MOUNT-T ntfs-o NLS=UTF8,UMASK=000/DEV/HDA3/MNT/HDA3 Mount NTFS partition
Linux-ntfs project:http://linux-ntfs.sourceforge.net/
Umount/mnt/hda3 Unloading load
Note: Before mounting the device, please fdisk-l look at it first.

17.SU switch to another identity without exiting the login
Usage: SU-L User name (if user name is default, switch to root state)
Eg:su-l netseek (Switch to netseek This user, will prompt for a password), plus-represents a switch to the user's environment variable.

sudo 利用他可以执行root执行的权限

18.whoami,id,w,lastlog,users,groups
W View User login information
Who view current login user
Last one months user login status
Lastlog check the last logon time for a particular user and format the output of the last logon log/var/log/lastlog
WhoAmI confirm his identity.
ID prints out its UID as well as the GID. (UID: A unique identification of the user identity.) GID: User group identity unique identity. Each user can only have a unique UID and GID.)
Users
Groups users belong to the user group query;
Finger-l Netseek Root
Finger-s or Direct finger
Allows users to query some other user's information
Eg:finger//View the user's usage profile
Finger root//view root information

19. Commands used by the user and execution history
History displays commands used by users in the past
!! Perform the most recent command

20.uname Viewing Linux System Information
Parameter:-A All information-R version number-N Host name

21. Establishing a soft connection
ln [-SF] source target
ln Souce-file Hard-link
LN-SF Source-file Soft-link
s indicates a soft connection, and F indicates that if a file with the same name is in, it will be overwritten.
Note: Hard links cannot be created for a directory, only files can create hard links.

22. View the Catalog
Du-sh directory or file
The default output of the Du-m du system is in kilobytes, with the parameter-m representation in megabytes.
Cat/etc/fstab View a list of partitions
Fdisk-l
Df-h
Df-ah

23. View resources occupied by Linux systems (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 outputs the result to/tmp/top.txt

Free-m Viewing system memory usage

Uptime shows the current system boot time (see how long the boot, how many people logged in, the past 1,5,15 minutes system load)

24. File than software:
The CMP cmp ("compare" abbreviation) command is used to briefly indicate whether there are differences between the two files, and its use rights are all users
The diff diff command is used for comparisons between two files and indicates the difference between the two, and its use rights are all users

25. Remote operation and File transfer
SSH [email protected]
SCP [Email Protected]:/remote/path/local/path
Scp/local/path [Email Protected]:/remote/path

26. Compiling A/C + + file
Gcc
GCC-V View GCC versions
Gcc-o Test test.c 2>errfile the error message when compiling test.c, redirect the error message to Errfile

27.chattr +i filename Prohibit deletion, chattr-i filename cancellation Forbidden
Lsattr Viewing hidden file properties

28. Automated execution
At execution time
Crontab Timing Loop Execution Program
Crontab Introduction
1 log in as root
2 # CRONTAB-E
3 Adding a row
1 /12 /usr/sbin/ntpdate pool.ntp.org
Minutes (0-59)
Hours (0-23)
Date (1-31)
Month (1-12)
Week (0-6)//0 on behalf of Sunday

29. Shutdown and restart:
Shutwond [-t number of seconds] [-RKHNCFF] time [warning message]
-T number of seconds: sets the delay time (in seconds) between warning and deleting two signals before switching to a different runlevel
-K sends a warning message, but it's not really going to shutdown
-R shutdown this after reboot
-H shutdown this after the boot
-N does not go through init, by the shutdown command itself to do the boot work (not recommended you use)
-F Restarts the fsck command without checking the file system.
-F forced to do the fsck check when re-booting.
-C will cancel the action already being shutdown
Shutdown-h now shuts down immediately, where it is equivalent to a time of 0,halt,poweroff or can be shut down, or directly init 0
Shutdown-h 20:30 system will be on tonight's 8:30 shutdown
The Shutdown-h +10 system automatically shuts down after 10 minutes.
Shutdown-t3-r now reboots immediately, but in warning and deleting processes this room,
Shutdown-k Now ' hey! Go away! Now ... " A warning message was issued, but no real shutdown was made.

Reboot
Shutdown-r now is almost identical to reboot and is not recommended for reboot execution as follows:
Shutdown-r +30 "The System Wiil reboot"
Shutdown-r +10 "hey! Go away! ' The system restarts after 10 minutes.
#sync; Sync Sync Reboot Note: Sync writes data to the hard disk
The halt command is equivalent to shutdown-h now, which means shutting down immediately.
The reboot command is equivalent to Shutown-r now, which means to restart immediately.

30. How to change the start mode runlevel
Vi/etc/inittab
Change 5 to 3, and you can turn it into a character mode after you start.
StartX or init 5 will be able to enter the graphical interface.
RunLevel display the current run level

How to switch to single-user mode
Using Telinit or init (in fact Telinit is just a synbol link to init)
Telinit 1 or Init s, of course telinit S is also possible.

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 recheck once/etc/inittab

31.TAB Smart Tab key, when you do not know the full name of the file or command is to press the TAB key consecutively.

32.clear Clear Screen

33.DMESG |more Display boot information (view hardware information at system startup)

34. Change the program execution of the excellent grade
Nice set Priority Nice-n-5 VI & Use ROOT to give a nice value of-5 for Execution VI
Renice adjustment already exists priority

35. Module-related commands
LSMOD displays the modules that have been loaded into the system
Depmod analysis of the dependencies of the load-loading system
Modinfo displaying information for kernel modules
Insmod Loading Module
modprobe automatic handling of loading modules
Rmmod Deleting a module

36.chkconfig--list shows the status of various services, and chkconfig can be used to easily manage init scripts.

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, plus-D parameter decompression
Bzcat filename.bz Viewing compressed file contents

Tar czvf aaa.tar.gz AAA compresses the directory AAA into aaa.tar.gz
Tar-n ' 2007/03/01 '-ZCVF home.tar.gz/home in/home, compared to the new files in 2007/03/01.
Tar--exclude/home/cao-zxvf myfile.tar.gz/home/*/etc to back up/home,/etc, but do not/home/cao
cd/tmp; TAR-CVF-/etc | TAR-XVF-The/etc/is packaged and unlocked directly under/TMP without generating a file.
Tar zxvf aaa.tar.gz the extract 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 Commands
Ifconfig display or set up a network device, you can view the current IP, similar to the ipconfig in Windows
Service Network restart (/etc/rc.d/init.d/network restart) Restart NIC
Ifdown eth0 turn off the NIC
Ifup eth0 Open NIC
Route-n Viewing the routing table
Route add-net 192.168.20.1 netmask 255.255.255.0 Dev eth0

Netstat View network connection status
Netstat-i Display network card operating condition
Netstat-r viewing the host's routing list

Traceroute

Hostname Display host name
HOSTNAME-I Displays the IP of the current host name.

39. System Integration Management menu.
Setup system service Management commands
NTSYSV Setting up System services

40.FDISK/MBR Delete Grub

41. Database Startup
Start MySQL:
Service mysqld Start (/etc/rc.d/init.d/mysqld start)
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 the Package
RPM Package Installation:
RPM-IVH xxx.rpm Installation RPM Package
Rpm-qa--last | Less shows installed packages based on installation date
RPM-QA |grep mysql-i Query system installs MySQL package (-I, ignoring case)
RPM-E Removing installed Packages
RPM-E mysql*--nodpes Force removal of related packages
RPM--test Test Installation
Rpm-qi Query MySQL Kit for documentation
RPM-QPL xxx.rpm See what the RPM package contains.
RPM-QC[D] Profiles and profiles
RPM-UVH Upgrade Installation
Rpmbuild--BB Specs/xxx.spec re-installed the Xxx.spec into the RPM package.
Rpmbuild--rebuild packagename.src.rpm to re-compile the. src.rpm into RPM packages.

Source code compilation installation (classic)
./configure Check System Information (./configure--help | More help information, you can see the relevant parameter settings)
Make clean clears the files left before
Make compilation
Make install Installation
Note: Source package installation, the general first unzip the file, the installation process is roughly above a few steps, the general opinion under the pressure of the catalogue (Install,reademe instructions.)

Linux common commands (2)

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.