Articles that make Linux technology a higher level

Source: Internet
Author: User
Tags echo display locale rar apache log

Preface: This article does not talk about very simple commands, such as cd,cp,mv,pwd and other very common commands. This is original, if you want to load, please explain the source. Some of the contents of the content for reference books, some resources of the network.

1 Laptop touchpad Open and disabled
Disable Touch-screen sudo modprobe-r psmouse
Turn on the touch screen sudo modprobe psmouse

2 wget
wget URL Download

3 mount
The Mount command mounts to a directory in a Linux file system for a file system in a physical device (for example, a CD, USB drive, hard disk), and displays the file system information that is mounted on the current Linux system when the Mount command does not use any options and parameters.
The mount command is powerful and has rich command formats. But common mount file system command format: mount–t type dev dir

Mount the specified file system-t parameter followed by the file system name. The/DEV/HDC6 on my computer is the FAT32 file system. Linux is called the FAT32 file system is VFAT.
If the mount is garbled, you can try:
Mount-o Iocharset=utf8/dev/hdc6/mnt/wine
Mount-o Iocharset=gb2312/dev/hdc6/mnt/wine

such as: Mount-t Iso9668/dev/cdrom/media/cdrom
Results: Mount:block Device/dev/cdrom is Write-protected,mounint read-only
The –t type option indicates the type of file system that needs to be mounted, and the disc file system type is: iso9660;
Dev indicates the device name on which the file system needs to be mounted, and the device name of the optical drive is/dev/cdrom;
Dir indicates the mount point, which is the path to the file directory that is mounted. The default path for the optical device in the Linux AS4 system is/media/cdrom.
Since the CD is a read-only storage medium, the Mount command will prompt the disc to mount in a read (read-only) mode when mounted, mount it using the Mount command to view the mounted file system on the last line, and then see the mount information of the device to prove that the mount was successful.
Last line display:/dev/hdc on/media/cdrom type iso9668 (RO)
Reading the contents of the disc is very simple, and when mounted with the Mount command, you can access the Mount directory to finish reading the contents of the disc.
such as: Ll/media/cdrom

Umount command
The Umount command is used to unload a file system that has already been mounted, such as the following: Umount dir device [...] Uninstalling a file system using Umount can specify the mount device file name or mount directory as a parameter that can unload the file system on the specified device or mount point directory.

For the CD-ROM file system uninstall can be used, the following two commands any one: note When uninstalling to exit the CD mount directory, otherwise prompted the file system is in use. Eject command
Use the eject command to gently eject and retract the disc in the optical drive without using the eject button of the optical drive.

How to use U disk
In a Linux system, the USB device is considered a SCSI device, and the device file is formatted as "SDA" for the first SCSI device in the "SdX" system, and the second is "SDB". My USB flash drive is recognized as "SDB" because I am using a system hard disk that is a serial drive.

USB drive device after inserting the system each time the device file name is not fixed, depending on the current system has a few SCSI devices, when unsure of the device name, we can use the "fdisk" command to list all the storage devices in the system:
Fdisk-l + Path

We can see that the current device filename is "/dev/sdb", the only primary partition device file name is "/DEV/SDB1" on the USB drive, and the file system type in the partition is fat. Knowing this, we can use the Mount command to mount the USB flash drive to the current file system. The "/mnt" directory is typically used to mount a file system that is temporarily used in the system, and the "/mnt" directory can serve as a mount point for the USB stick system. Use the "vfat" file system type to represent all the FAT file system types, including FAT16 and FAT32,NTFS, or NTFS representations.
Mount-t vfat/dev/sdb1/mnt/
Mount-t ntfs/dev/sdb1/mnt/

USB flash Drive's Uninstall

4 grep,find,which,whereis,locate
grep syntax: grep type character file grep world Ceshi.txt
GREP-NR string Path
Basic format: Find expression

1. Main parameters

[Options] Main parameters:
-C: Outputs only the count of matching rows.
-I: Case insensitive
-H: The file name is not displayed when querying multiple files.
-L: Only file names that contain matching characters are output when querying multiple files.
-N: Displays matching lines and line numbers.
-S: does not display error messages that do not exist or have no matching text.
-V: Displays all lines that do not contain matching text.

Pattern Regular Expression Main parameters:
\: Ignores the original meaning of special characters in regular expressions.
^: matches the start line of the regular expression.
$: Matches the end line of the regular expression.
\&lt: Starts from the line that matches the regular expression.
\&gt: End of line to match regular expression.
[]: A single character, such as [a], a meets the requirements.
[-]: range, such as [A-z], i.e. A, B, C to Z all meet the requirements.
.: all the individual characters.
*: There are characters, the length can be 0.
(1) grep ' test ' d* #显示所有以d开头的文件中包含 Test line
(2) grep ' Test ' AA bb cc #显示在aa, the line containing test in the BB,CC file
(3) grep ' [a-z]\{5\} ' AA #显示所有包含每行字符串至少有5个连续小写字符的字符串的行
(4) grep magic/usr/src #显示 files (without subdirectories) in the/USR/SRC directory contain magic lines
(5) Grep-r magic/usr/src #显示 files (including subdirectories) in the/USR/SRC directory containing magic lines

(6) Grep-w pattern files: matches only the entire word, not part of the string (such as matching ' magic ' instead of ' magical ')

Find Files and directories
Find/–name Ceshi
Delete SVN version information commonly used in projects: first go to the project directory and execute the command: Find. -name. svn-exec RM-RF {} \;
The find command is very slow and consumes hard drives, preferably with other commands
Basic format: Find path expression

1. Search by file name

(1) Find/-name httpd.conf #在根目录下查找文件httpd. conf, which indicates that the entire hard drive is found
(2) Find/etc-name httpd.conf #在/etc directory file httpd.conf
(3) find/etc-name ' *srm* ' #使用通配符 * (0 or any number). Find files in the/etc directory that contain the string ' SRM ' in the file name
(4) Find. -name ' srm* ' #表示当前目录下查找文件名开头是字符串 ' SRM ' files

2. Search by File feature

(1) Find/-amin-10 # Find files accessed in the last 10 minutes of the system (access time)
(2) Find/-atime-2 # Find files accessed in the last 48 hours of the system
(3) Find/-empty # finds files or folders that are empty in the system
(4) Find/-group Cat # finds files that belong to group Cat in the system
(5) Find/-mmin-5 # finds files that have been modified in the last 5 minutes of the system (modify time)
(6) Find/-mtime-1 #查找在系统中最后24小时里修改过的文件
(7) Find/-user Fred #查找在系统中属于fred这个用户的文件
(8) Find/-size +10000c #查找出大于10000000字节的文件 (c: Bytes, W: double word, K:KB,M:MB,G:GB)
(9) Find/-size-1000k #查找出小于1000KB的文件

3. Find a file using a hybrid lookup method

Parameters are:! ,-and (-a),-or (-O).

(1) find/tmp-size +10000c-and-mtime +2 #在/tmp directory to find files larger than 10000 bytes and modified in the last 2 minutes
(2) Find/-user fred-or-user George #在/directory lookup user is Fred or George's file file
(3) Find/tmp! -user Panda #在/tmp directory to find all files that are not part of panda users

which + file name
The basic function of which is to find the executable file through the environment variable path to that path, so it is used to locate the executable file. In fact, this time to think about how you can see the file is an executable file, I have introduced a method in the previous, learning is to combine the use. When we are not familiar with this system, we can first look at a directory to see if there is an executable file, and then use which authentication.

Whereis can quickly locate the file, and also provides a binary executable file, source code files, and a user manual page storage location for this file. such as: Whereis php.ini

If you know the filename, but do not know the file under that directory, we can use the Locate command to search for files, this command to search for files faster
Locate PHP.ini

Whatis what is it

5 Vim Editor
Vim command mode, YY copy the current cursor line, p paste, u undo, Ctrl+r Cancel just undo
Y5y includes the line where the cursor is located, counting down, copying 5 rows to memory. If you copy only one row, you can write no numbers.
Y3W Copy the 3 English words that follow the cursor.
P lowercase to paste the contents of the Clipboard after the cursor.
P caps, pastes the contents of the Clipboard before the cursor.

CTRL + ALT + T popup terminal
PgUp up one page (edit mode)
PgUp down one page (edit mode)
The VI editor has 3 modes: Command mode, input mode, and last line mode.
Command mode: VI start after the default entry is the command mode, press I or a into the input mode, press ESC to enter the command mode.
Input mode: Press I or a to enter input mode, press ESC to enter command mode.
Last-line mode: Enter ":" in the command mode to enter the mode, there are many good commands in the last line mode.
View VI version information directly enter the VI return, you can see the
The movement of the cursor
Move cursor up: K
Move Cursor Left: h
Move the cursor to the right: l
Move Cursor Down: j

Command mode-page Turn command
Ctrl+f forward full page ctrl+u forward half page
Ctrl+b Turn back full page ctrl+d back half page
Command mode-inline fast jump
^ Move to the beginning of the bank
$ move to end of bank line
Command mode-Displays line numbers and cancels line numbers (used in the last line mode)
Set NU Display line number
Set Nonu Cancel line number
Command mode-cursor movement
G cursor back to the first line of the file
Shift+g cursor back to end of file line
#G跳转到文件的 # Line

Delete operation (Command mode use)
x Delete a single character at the cursor
DD deletes the cursor in the row
DW deletes all characters from the current character to the end of the word including spaces
Undo Action
U command cancels the last operation and can be used multiple times to restore the original operation
U Cancel all operations
Ctrl+r can revert to operations that use the U command
Undo Action
U command cancels the last operation and can be used multiple times to restore the original operation
Ctrl+r can revert to operations that use the U command

Copy operation (just remember yy copy a row, others too much, do not require memory)
YY command copies the contents of the current entire line to the VI buffer
YW Copy the contents of the current cursor to the end of the word to the vi buffer, the equivalent of copying a word
y$ copy cursor position to end of line content to buffer area
y^ copy cursor position to the beginning of the content to the buffer area
#yy例如: 5yy is copying 5 rows
#yw例如: 2yw is a copy of two words
If you want to copy the contents of line m to nth row, you can enter M,ny in the last line mode for example: 3,5y copy the third line to the fifth row of contents to the buffer.
Top-down Lookup/String
To the bottom of the search? string
Replace (must master the last row mode)
: S/old/new replaces the first occurrence of the old in the row with new
: S/old/new/g replaces all occurrences of old in line with new
: #,# s/old/new/g replaces the old from line # to # # with new
:% s/old/new/g replaces the old that appears in the entire article with new

Edit mode
Enter the input mode command
I insert command a additional command o Open command C Modify command
R Replace command s replace command ESC exit command
Operation of input mode
Home cursor to beginning of line
End cursor to end of line
Page UP and PAGE Down
Delect Delete the character of the cursor position
Recover files
VI when editing a file, a temporary file is generated, which is the file. Begins and ends with a. SWP. Normal exit the file is automatically deleted, if unexpected exit such as sudden power outage, the file will not be deleted, we can choose the next edit command processing:

o read-only open without changing the contents of the file
E continue editing the file without restoring the contents of the. swp file saved
R restores the contents of the file after the last edit was not saved
Q Exit VI
D Delete the. swp file
Or use the Vi-r file name to restore unsaved content

6 rm-f
Rm-f file name to force deletion of files without prompting
RmDir Delete a single folder
RMDIR-R Delete multi-layer folders, loop Delete, until delete all

7 wildcard characters
* Any character and string
? An arbitrary character
[ABC] [] any of the characters in the [] can sometimes indicate a range such as: [A-z], such as I want to enter the Setup directory, but only remember Setu, do not remember what the last character is, then there are several ways:
1 CD Setu? (an arbitrary character)
2 CD Setu[a-z] (one in A-Z)
3 CD Setu + TAB (complete with TAB key)
4 CD SETU[BCMP] (fuzzy Remember is one of the few characters bcmp)
Have file 111.txt,112.txt,113.txt to delete 11 txt file starting at RM 11?. TXT If you want to delete all. txt files, RM *.txt

8 System groups and users
Group Management: Groupadd Groupdel
Create Group Admin:groupadd Admin
See the group information under/etc/group
Groupdel Deleting a group
In a Linux system, I use the Groupdel command to delete a user group, Groupdel admin
Groups shows the group where the current user is located

User management: Useradd passwd Userdel
A user in a Linux system must belong to a group, so if you create a new user without specifying a group command, you will create a group that is exactly the same as the user name and put the new user in. If a group is specified when a new user is created, the user belongs to the specified group. Only the root user can increase the user, the added user may change the password for themselves, but cannot change the root secret
Add Group: admin such as: Groupadd admin
Next, we create a user jams and assign it to the admin group
Useradd-g Admin Jams

-L can modify user name
-g< Group > Modify the group to which the user belongs
-L LOCKS the user password to invalidate the password.
-U unlocks the password.

New users can be seen under/home
Change Password: passwd such as: passwd jams first verify the old password, and then press the prompt to enter the new 2 times password
Delete User: Userdel: Userdel Jams

9 Displaying file contents
Cat file name: Show All information
TAC file Name:
More file name: Same as the cat command. The difference is that a number of lines are displayed after pausing to display
Less file name: Same as more but can look back
Head file name: View the beginning of the file
Tail FileName: Viewing the end of a file

10 Viewing version information
System Information: uname-a
See Ubuntu version: Cat/etc/issue

[Email protected]:~/soft$
Jams Current User
THINKPAD-E550 Computer Name
~ Current user's Homestay directory
/soft Current Path
$ normal User, root is #, so you can distinguish the current user identity according to these 2 symbols

Ls–a lists all files, including hidden files, and also looks at the "/" under directory as an example:
Ls–l details such as the permissions of the file under the directory, the owner file size, etc., you can simply enter "LL"
LS–F lists the file names and their directory types in the directory to view/etc files
We found that there is a file after the *, some files have a @, there is a/end, they represent the executable file, symbolic link, and directory name.

CD ~ Return to user host Directory

View File types
The file command recognizes the majority of files in a Linux system and recognizes text files. Binary executables, compressed files, and so on.
such as: File Ceshi.txt
Result: Ceshi.txt:ASCII text

15 Changing the root password
After the new installation, did not see where to set the root password, only set the normal user password, then how to change the root password?
(After testing, I use the normal user to modify the root password, it is normal users can not change the root password, this problem remains to be deep)
sudo passwd root
Follow the prompts to enter the normal user password, and then enter the root password 2 times, then the root password is set to succeed, with the SU root password to enter the root, switch to root

Date and Cal
View System Time Date
Set the current system time to May 8, 2015 19:48 0 seconds date-s "2016-5-22 19:48:00" Date–set "2016-5-22 19:48:00"
Cal View Calendar

17 common compression and decompression commands (both tested by me)
Tar command
Package only, do not compress TAR-CVF Ceshi.tar Ceshi result to see a Ceshi.tar package
Unpacking: TAR-XVF Ceshi1.tar

Zip command
Compression: Zip Ceshi
Decompression: Unzip
Zipinfo List Compressed file information

RAR command
Installing RAR and Unrar:sudo apt-get install RAR first; sudo apt-get install unrar;
Compression: rar a ceshi.rar Ceshi (Ceshi compressed into a Ceshi.rar package) decompression: Unrar e Ceshi.rar (decompression Ceshi.rar package)

Compression: Tar–czf ceshi.tar.gz Ceshi//package directory Ceshi into Ceshi.tar and compress it with gzip to generate a gzip compressed package named ceshi.tar.gz
Decompression: TAR-ZXVF ceshi.tar.gz

TAR.BZ2 (same as decompression)
Compression: TAR–JCVF ceshi.tar.bz2 Ceshi//pack the directory Ceshi into Ceshi.tar and compress it with bzip2 to generate a bzip2 compressed package named ceshi.tar.bz2
Decompression: TAR-JXVF ceshi.tar.bz2

TAR.BZ command
Compression: TAR-JCVF Ceshi
Decompression: TAR-JXVF

Apache Log directory:/var/log/apache2/, program development troubleshooting often used, see Apache Log

DF and Du
View the size occupied by all partitions in the current system df-h
See what kind of file system the partition is DF-T
Merge the above 2 commands df-th
Using the-x parameter may display partitions other than a certain type of partition such as:
File system type capacity used% mount point available
/DEV/SDA1 ext4 451G 27G 401G 7%/
Udev Devtmpfs 3.8G 4.0K 3.8G 1%/dev
Tmpfs tmpfs 773M 912K 772M 1%/run
None Tmpfs 5.0M 0 5.0M 0%/run/lock
None Tmpfs 3.8G 160K 3.8G 1%/RUN/SHM
Then I don't want to see the EXT4 type can be used: Df-th-x EXT4 results show:
Udev Devtmpfs 3.8G 4.0K 3.8G 1%/dev
Tmpfs tmpfs 773M 912K 772M 1%/run
None Tmpfs 5.0M 0 5.0M 0%/run/lock
None Tmpfs 3.8G 160K 3.8G 1%/RUN/SHM
As a result, the EXTR4 type is filtered out.

DF-The Directory-H command can display all partitions in the current Linux system
View the size of each directory using du/* du/home-h

Ping Check Network
To view the DNS client configuration file using more/etc/resolv.conf

Locale Lang
Locale View Language environment
Locale-a Viewing the language information supported by the system
Set the system language: lang=zh_cn.gb2312 (Chinese gb2312 encoding) lang=zh_cn. UTF-8 (Chinese UTF8 Code) lang=en_us.utf-8 (English)

RM [Directory Name]
Example: Rm/var/ftp
Recursively deletes all the files in a directory and the directory itself.
rm-r [directory Name]

Wc-l opt.php See how many lines a file has
Wc-c opt.php See how many bytes a file has

24 Installing the RPM software
Example: RPM-UVH kdevelope-3.1-1.i386.rpm
uninstalling RPM Software
Example: Rpm-e kdevelope

25 Compiling the installation
Configure, compile, install, and uninstall source-published packages.
./configure Configuration
Make compilation
Make install Installation

Make clean simply clears the previously compiled executable and configuration files
Make uninstall Uninstall the source release package
./configure--enable-gui--prefix=/opt/mplayer-1.0pre7try2--with-win32libdir=/opt/mplayer-1.0pre7try2/win32-- With-codecsdir=/opt/mplayer-1.0pre7try2/codecs.
--enable-gui (can use graphical interface)
--prefix=/opt/mplayer-1.0pre7try2 (destination path for software installation =/opt/mplayer-1.0pre7try2)
--with-codecsdir=/opt/mplayer-1.0pre7try2/codecs (Path =/opt/mplayer-1.0pre7try2/codecs of the decoding library)

+ SSH Remote Shell
If the server workman is jams, then there are 3 ways to log in
Ssh-l Jams
SSH [email protected]
rsh [email protected]

SFTP is an interactive file transfer program. It is similar to FTP, but it is encrypted and has higher security than FTP. Below is a brief introduction of how to connect the host remotely, file upload and download, and some related operations.
For example, if the remote host IP is or domain name, the user name is Fyt, in the command line mode: SFTP [email protected] or [email protected]. Enter prompt for password. Enter the prompt
If you log on to the remote machine not to upload the download file, but to modify some files on the remote host. OK
SSH [email protected] (in fact, SFTP is an SSH program.) )
Sftp> get/var/www/fuyatao/index.php/home/fuyatao/
This statement will download the index.php to the local/home/fuyatao/directory from the/var/www/fuyatao/directory of the remote host.
Sftp> put/home/fuyatao/downloads/linuxgl.pdf/var/www/fuyatao/
This statement uploads the Linuxgl.pdf file under the local/home/fuyatao/downloads/directory to the remote host/var/www/fuyatao/directory.
If you do not know what the remote host directory is, the PWD command can help you query the current path of the remote host. Query native current working directory lpwd.
Change the path can be used CD, change the local path can be used LCD;
LS RM rmdir mkdir These commands are available. The same call native is add L, that is, Lls LRM.
To leave SFTP, use Exit or quit, bye. The man sftp can be consulted in detail.
If you find it inconvenient in command line mode, sudo apt-get install gftp. It's much easier to operate in a graphical interface.

28.rename Collective renaming
If there is a directory work, the following files: Aa.txt bb.jpg
Now you need to change the file name AA to BB rename AA. Bb. aa* (change the letters to those letters to change the file example)

The top command displays the system process press Q to exit Kill a process Kill + PID

CAL displays this month's calendar
Cal year displays all months of the year, such as Cal 2016
Make a view of the month of the year Cal 9 2016

Clear clear the terminal

echo Display text ECHO-E string

Type view command path
Example: type pwd result: PWD is shell embedded
Type Wine-qqintl Result: Wine-qqintl is/usr/bin/wine-qqintl wine-qqintl is my own installed international version of QQ, with type can see, I this command source.
Type Opera opera result: Hashed (/usr/bin/opera) Oepra is the browser I installed

34 File Directory Permissions issues
1= execution Right 2= writing right 4= reading right 1+2=3 execution and writing right
Chmod-r 777 Ceshi The first 7 belongs to the current user, 2nd 7 belongs to the group, 3rd 7 belongs to other uses, in Linux is not recommended all set to 777, then lost the security features of Linux

CHQRP and Chown
CHGRP change the owning group syntax for a file or directory: Chgrp belongs to the group file or directory name, change the time to enter/etc/group see what Group
Chown change the user syntax of the file or directory: Chown belongs to the user file or directory name, change the time to enter/home this file to see what users.

The last time the user's current and previous login times are displayed.
LASTB lists user-related information about the login system failure.

Panax Notoginseng Ctrl+s
As a surprise, sometimes you press the Ctrl+s key combination and the shell is frozen. Try using the CTRL+Q key combination to see if you can get back to normal.

38 emptying the Recycle Bin
sudo rm-fr $HOME/.local/share/trash/files/*

Enter the history command to list all running commands, and then find the corresponding number and enter "! Corresponding command "can be. To clear the history command: history-c

Who sees who is logged into the system

WHOAMI display its own user name

A CMP compares two files for differences.
CMP Ceshi.txt Ceshi1.txt
Ceshi.txt ceshi1.txt Different: 5th Byte, line 3rd

Badblocks check for damaged chunks in the disk device

Free Display memory status

ID Displays the ID of the user and the ID of the owning group

The shell of the remote login of RSH
rsh [email protected] can log on to the server

Pstree Display the program in a tree-like chart

Common shortcut keys for Linux terminals
CTRL + ALT + L lock screen effect is equivalent to: gnome-screensaver-command-l
Ctrl + a cursor back to command line start
Ctrl + e cursor back to the end of the command line
Ctrl + L Clears the contents of the screen, the effect is the same as clear
Ctrl + U clears the contents before the cut cursor
Ctrl + y Pastes the characters that you just used to cut ctrl+u. First CTRL + U cut, then Ctrl + Y paste.
Ctrl + R is found in the history command (this is very easy to use, enter the keyword to recall the previous command)
Ctrl + C Abort command
Ctrl + Alt + T start terminal
Ctrl + D exit the terminal, the effect is the same as Exit X-window exit terminal with exit, Shell window with logout exit terminal, cannot exit terminal with exit.
!! Repeat the last command as I used the PWD command, I need to use this command again (no other command during this time), then you can use two exclamation points + carriage return, execute the PWD command
On the X-windown desktop, using:
SHIFT + CTRL +n new folder
Click on the folder right mouse button +v Delete files/folders (put to Recycle Bin)
Mouse click File/folder Alt + Enter to view the properties of the selected file/folder, instead of right-click to select Properties

Articles that make Linux technology a higher level

Related Article

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: 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.