Self-learning Linux gains a little bit every day (ongoing updates)

Source: Internet
Author: User
Tags add time clear screen set time touch command root access

Command-option parameters
If the option is a word, add 2 to the front of the option-
Modprobe-r PCSPKR in the terminal when there is a sound, you can use this command to screen the sound, need root permission

LS Displays the contents of the directory, and the dir command under Windows is quite
Ls-l (lowercase in L) is displayed in long mode
Ls-l/usr View information about the contents of the USR directory
LS-LD/USR View information for the USR folder itself
Ls-1 (number 1) The contents of the current directory are displayed in a row
Ls-a display contains hidden files, which begin with a hidden file.
Ls-s display files, and the size of the file
The ls-1as option can be superimposed
Ls-sh display the size of the file, there are units, can read

PWD Displays the directory where you are currently
Clear or crtl+l clear screen, and the CLS command under Windows is quite
Date Displays dates
Date +%Y display year
Date +%m Display month
Date +%M Display points
Date-u 101109452017 Set Time is October 11, 2017 9:45
Cal Display Calendar
Cal shows this month's sub-calendar
Cal 2016 displays all calendars for the year 2016
Cal 05 2016 displays calendar for May 2016
BC Calculator
BC can calculate after return
1/3 starts at 0 because the default is to keep the decimal point 0 bits
scale=2 set reserved 2 digits after decimal point
Quit Quit Calculator
History shows the commands we've knocked on the default display of up to 1000
!22 executes the command with the ordinal number 22 queried in the history command

CTRL + a jumps to the start of the command line
Ctrl+e jumps to the end of the command line
CTRL + LEFT ARROW One word one word to the left jump
CTRL + RIGHT ARROW one word one word to right jump
Ctrl+u Delete all characters from the current cursor to the beginning of the bank
Ctrl+k Remove all characters from the current cursor to the end of the bank
CTRL + C ends execution of the current command
Ctrl+d exit terminal, equivalent to exit command
Ctrl+shift+t open multiple terminals, can be switched off with Ctrl+d

Hold ESC and press when you let go. Arguments when referencing the last command
Touch XX Creates an xx text file
^xx^yy re-executes the last command (Touch command), and the file name created is changed to YY
Whatis ls tells me the function of the LS command, which we can use to view the commands we don't know.
Man LS Displays the section of this command, man, which can be used to view commands that you do not know.
Enter the boot word in the/boot highlight article
n View boot from top down
N view boot from bottom up
Q exit
Man-k clock to see the command with the clock keyword,-K for the keyword
Man Host.allow View the role of the Host.allow file, and how to configure

Gedit Open gedit Text editor
Gedit oo use Gedit editor to open Oo file to continue editing
Rm-f oo Delete oo files
Nano Open Nano Editor
Ctrl+o write file, without file name, you need to enter file name
Ctrl+x exit
Sync writes the data in the cache to the hard drive
Shutdown shutdown, requires root access
Shutdown-h 10 10 minutes after shutdown
Shutdown-k 10 10 minutes after the prompt shutdown, does not really shut down the computer
Shutdown-h shutdown 10:50 10:50
Poweroff shut down the machine
Poweroff-f immediately shut down the machine, fast
Reboot restart
Reboot-f, quick restart, fast

Seven operating levels in the/ETC/RC.D directory
RunLevel See which RunLevel is currently in, followed by the current number, the previous
Init 3 enters third level, requires root permission
Init 3 Enter the command interface after entering the STARTX command, will start the graphical interface of this service, but is still at 3rd level
Init 5 enters the graphical interface because the 5th run level default graphical interface starts
Init 6 Restart
Init 0 shutdown

File system
/ETC/PASSWD User's account information is placed in this folder
/etc/shadow User's password information is placed in this folder
/etc/group User's group information is placed in this folder
The system marks the user according to the UID, not according to the user name
Ln-s abc.log hh make a shortcut to the Sbc.log file, with the name HH
LS-LH Display the directory in check mode, the size of the file has units
The first column has 10 characters
First character:-: Normal file (binary file or text file); d: folder; B: Device file (files that can be used to store things)
C: Device file (character file, cannot be used to store things); L: Shortcut
The following nine characters: Represents the permissions of the file, divides the 9 characters into three groups, the first group for the file owner (user)
The second group of people in the user group, the third group for other users, each group has 3 characters
These three characters are r: Read permission, W-write permission, x: Execute permission, if which group is missing any characters,
There's no authority.
chmod change User (U), user group (g), other person (o) permissions on a file
chmod u+x,g+w,o-r Abc.log changed to: User rights to Abc.log file: Add executable permission
User group permissions to the Abc.log file: Plus Write permissions
Other people's permissions on the Abc.log file: minus Read permissions
chmod ug-rw abc.log change user and user group permissions to abc.log files: Subtract read and Write permissions
The same can be written together
X permissions if it is on a folder, the person with X permission can enter this directory, that is, you can CD over
No, you can't have CDs.
chmod ug=x Abc.log No matter what permissions the user and user groups have previously had on the Abc.log file, this command executes only: executable permissions
chmod A=RW Abc.log A means a shorthand for Ugo.
chmod +r abc.log The user or user group or other person is not indicated before the +r permission, the default is to add Read permission to the users (but I have tested the three added)
chmod +w Abc.log does not indicate a user or user group or other person before +w permissions, and adds write permissions to the user and user groups by default
chmod +x Abc.log does not indicate a user or user group or other person before the +x permission, the default is to add Execute permissions to three
We regard the R privilege as 4,w privilege as the 2,X privilege as 1
If the user's permission to a file is number 5, then there is r permission and x permission.
chmod 743 abc.log change user, user group, other people abc.log permissions, respectively rwx, R, RX permissions
chmod 000/usr Change the USR folder permission to 000, does not change the contents of the folder permissions
Chmod-r 555/usr Change the permissions of the USR folder and the contents of the folder to 555,-r means recursion
Useradd Tom Add a Tom User
Chown Tom/abc.log to change the owner (user) of Abc.log to Tom User
Chown Tom:tom Abc.log Change the owner and user group of the Abc.log file to Tom
Colon (:) can be changed to dots (.)
CHGRP Root Abc.log Change the owning group of the Abc.log file to root
Chown-r tom/usr Change the USR folder and the owner of the contents to Tom.
Chgrp-r tom/usr Change the USR folder and the contents of the group to Tom

File Abc.log to view the types of files
There are many folders under the Linux root directory
Bin: Storing binary files
Boot: Boot file for the system (kernel configuration file, etc.)
Dev: Storing device files, moving hard disks, u disks, etc.
ETC: Configuration file
Home: User's home directory
LIB: link library file
Media: Automatic mount point for the system
MNT: Manual mount point
OPT: When we use the source package installation, the general will be installed in this directory of a folder, if not named installation, the default installation in the USR directory
Proc: Specifying Kernel parameters
Root:root home directory, other user's home directory is placed in the home directory
Sbin: When we hit the command, it's all stored in this directory.
TMP: Temp file
USR: Default installation path
var: Log files, cache files, database files, occupy a large space

Tree/boot Viewing the tree structure under the boot directory
/usr/aa/bb absolute Path, start writing from the root directory
. Represents the current directory
.. Represents the upper Path
Cd.. /.. /.. /upper-level directory of the upper level of the current directory
uname View kernel, Linux
Uname-i Viewing the schema (64-bit or 32-bit)
Uanme-r kernel version
Uname-a View all information
Lsb_release-a View all information
Cat/etc/redhat-release

CD/USR switch to usr directory
CD switch to the current user's home directory, equivalent to CD ~
CD ~tom switch to the home directory of Tom Users, the home directory of the general user under home, such as the/home/tom,root user's home directory is/root
CD ~/tom switch to the current user's home directory of the Tom folder, this shows ~ there is/and no/Difference
WhoAmI See who the current user is
CD-Switch to the directory where you Last
mkdir xx Create xx directory
mkdir yy ZZ Create multiple directories at the same time
RmDir YY ZZ Delete multiple directories at the same time, RmDir cannot delete non-empty directories
Mkdir-p xx/yy Create xx directory, XX directory and then create a yy directory,-p means that the XX directory does not exist to create
Mkdir-p Rhca/{xx,yy,zz} Create a RHCA directory and create three folders in the RHCA directory
Rmdir-p rhca/xx Delete xx directory at the same time the RHCA directory also deleted, need to delete xx directory rhca is empty
RM-RF RHCA Delete the RHCA directory,-R for recursion,-F for coercion, regardless of whether there are subdirectories in the RHCA directory
echo $PATH View System command path
Gedit xx.sh Create a script
./xx.sh executing the xx.sh script under the current directory
SH xx.sh Execute xx.sh script
If we write xx.sh directly, the system defaults to path path, because we did not add this path to the system path variable,
The report cannot find the command error, if we want to directly write xx.sh can be found, we need to add this path in the system path variable, such as/home/sun
Path= "/home/sun" set the path of the system to/home/sun, if we want to change, we should first get all the previous commands,
And then add this path, here just for the convenience of writing
Ls-ld--time=atime/boot Displays the boot folder's own information in long mode, where it equals the last access time
Ls-ld--time=ctime/boot Displays information about the boot folder itself in long mode, where the time is equal to the creation
Ls-r/List The files under the root directory,-R for recursion, if there are folders underneath the folder, it will be displayed.

Cp/etc/service/home/sun Copy the service file under the ETC directory to the Home/sun folder, the name or service
CP/ETC/SERVICE/HOME/SUN/XX Copy the service file under the ETC directory to the Me/sun folder and rename it to XX
Cp-rf/etc/home/sun the ETC directory recursively, forced to copy to the Sun directory, if not add-RF,CP can not directly copy a directory
Cp-p/etc/service/home/sun Copy the service file under the ETC directory to the Home/sun folder, the name or service
If you do not add-p, you will not copy the file's attribute information, such as creation time
Cp-a/etc/mnt Copy the ETC directory to mnt,-a for all, including-r/-f/-p
Cp-u/etc/service/mnt/service Copy the service file under the ETC directory to the service file in the MNT directory
If the service in the ETC directory is newer than the service under the MNT directory, it will be copied in the past instead of the past
If you do not add-u, there will be a hint
cp xx yy copy xx file as yy file, if xx is a shortcut, actually shortcut link did not copy the past
cp-d xx yy plus-D, if XX is a shortcut, will copy the past
RM Service Delete Service file
Alias to view aliases, such as when we alias the Rm-i command to RM, when we hit RM, the actual execution rm-i
ls/boot/grub/grub.conf view grub.conf in/boot/grub/directory, results include path and file name
basename/boot/grub/grub.conf view file name, results only file name
dirname/boot/grub/grub.conf view file path, results only path


We can view the contents of a document using Cat, TAC, head, NL, tail, more, less, OD
Cat XX View the contents of the xx file, the previous show all the content, if the content is very much,
We can only see the last thing, this cat is suitable for viewing small files
Cat-n XX Add a number to each line when viewing a file
TAC XX View the contents of the file, from the back to the forward display
NL xx To view the contents of the file, each line is preceded by a line number, and the same as Cat-n xx effect
Nl-b a hosts, plus line numbers before empty lines
More xx from the back to display the contents of the file, split screen display, press Enter and then display a line, press the space to display a screen
Press Q to exit
Less XX Displays the contents of the file from the point of view, split screen display, press ENTER to display a row, press space to display a screen
Less support to look forward, looking back, PageUp forward, pagedown to turn backwards
Home turns to the first page, end to the last page
Enter/Then enter what you want to find, support find, press N to scroll down, press N to scroll forward
Press Q to exit
Head XX View the first few lines of XX file, the default is 10 lines
head-5 XX View the first 5 lines of the xx file, equivalent to-N 5
Tail xx View the end of the xx file lines, the default is 10 lines
tail-5 xx View the end of the file 5 lines, equivalent to-N 5
Tail-f xx Look at the end of the file 10 lines, but will not exit, we can monitor the log file
Tailf xx equals tail-f xx, press Crtl+c to exit
Service Network Restart Restart Network
Od-t C/BIN/LS-T indicates the display Type C indicates what to display, C for ASCII, for viewing binary files
Strings/bin/ls View the contents of text or binary files, powerful features

Touch XX If xx file does not exist, create a new file, named XX
If xx file exists, change the creation time and modification time of this file to the current time.
ll is equivalent to ls-l displaying directory contents in long mode
Touch-t 20121223152536 XX Change the file time of XX to 20121223152536
Do not add time, default current time

Umask Permissions filter pot, you can view the filter permissions, default 0002, take the back three bits
Umask 333 Set the permission filter to 333, then the view is 0333
Umask-s see which characters are retained, and umask opposite
lsattr xx View the hidden rights of XX file
Chattr +a xx Modify the hidden rights of xx file, +a means only add, cannot delete
Chattr +i XX Indicates that this file cannot be changed and cannot be deleted.
Chattr-a xx minus hidden a permission
Chattr-i xx minus hidden I permissions

chmod u+s xx on the owner permission of a command, when S is present, other users will have the owner's permission when they operate on this file
Which passwd view passwd the path of this command, the result is/usr/bin/passwd, you can also view the path of other commands
Whereis passwd View the path to the passwd command and the file that contains the passwd command
Whereis-b passwd only look at the path containing the binary file command
Whereis-m passwd Other commands other than the binary file command
Locate MMM list all filenames with the MMM field file path
Locate find the file is not through the hard disk, is found through the/VAR/LIB/MLOCATE/MLOCATE.DB database
And this database is updated every day at 0.
If we want to see the file you just created with the Locate command, just update the database to
UpdateDB Updating the database
Locate-i mmm find the file path containing MMM file name, not case-sensitive, that is, MMM can also find
Hostname Viewing host names
echo xxxxx Print out xxxxx on the screen
echo XXX ' hostname ' yyy when a command is nested in another command, it is not executed unless an inverted quote is added, or $ ()
echo xxx$ (hostname) YYY execution results same as last
chmod 4644 xx set xx file permissions, 644 for normal permissions, start is 4 to give you the location of a s permission
chmod 2644 xx set xx file permissions, 644 for normal permissions, start is 2 for the location of G plus a s permission
chmod 1644 xx set xx file permissions, 644 for normal permissions, start is 1 for O location plus a t permission

Find Directory-Property values
Find/-name XXX based on file name, look for file name xxx file path under root directory
Find/-user XXX based on user name, locate the file path for the owner XXX under the root directory
Find/-user Xxx-group xxx based on user name and owning group, find the file path of the owner xxx in the root directory, and the owning group is also xxx

Self-learning Linux gains a little bit every day (ongoing updates)

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.