Getting Started with Linux
directory
One, user login
Two, terminal
Three, Shell introduction
Four, execute command
Five, simple command
Six, command line History
Seven, bash shortcut
Viii. using Ghome-ternimal
IX, file management
11,. Directory, inode table and file
12, soft/hard link
One, user login
There are two kinds of users in Linux system, one is root user, one is ordinary user,
1, root user
Root is a special management account, with all the rights of the management system, equivalent to the Super Administrator of Windows, can manage any file, can also manage other ordinary user's rights, for the management system is very convenient, (However, there is almost unlimited ability to damage the system, unless it is necessary not to log on to root)
2, ordinary (non-privileged) User
permissions are limited, and other user information and permissions can not be modified, resulting in a limited right to damage
Ii. terminal Terminal
Terminal is a type of
1, device terminal
Keyboard mouse monitor for Linux management
2, physical terminal (/dev/console)
Console console
3, virtual terminal (tty:teletypewriters,/dev /tty# #为 [1-6])
TTY can have multiple, ctrl+alt+f[1-6]
4, graphics terminal (/DEV/TTY7) Starx, xwindows
CentOS 6:ctrl+alt+f7
CentOS 7: At which terminal is started, which virtual terminal is located
5, serial terminal (/dev/ttys$)
TTYs
6, pseudo terminal (Pty:pseudo-tty,/dev/pts/#)
Pty, SHH remote connection
7, The command to view the current terminal is the TTY
three, Shell introduction
The shell is the user interface of the Linux system and provides an interface between the user and the kernel. It accepts commands entered by the user and sends it to the kernel to execute. The shell is also known as the Linux command interpreter, and the shell is a high-level programming language.
1, echo Display current
2, cat/etc/shells display all Shell
3 used by the current system, command prompt [[email protected] ~]#
Admin $ normal User
echo $PS1 显示提示符格式 PS1="\[\e[311m\][\[email protected]\h \W]\\$\[\e[0m\]" \e \033 颜色 \u 当前用户 \h 主机名简称 \H 主机名 \w 当前工作目录 \W 当前工作目录基名 \t 24小时时间格式 \T 12小时时间格式 \! 命令历史数 \# 开机后命令历史数
Iv. Execution of Orders
Enter command and return to execute command
1. The commands that can be executed in the shell are divided into two types:
Internal command: Comes with a shell and is provided in a command form
Help displays a list of all internal commands
Enable displays all the internal commands that have been activated
Enable CMD to activate an internal command that is disabled
Enable-n cmd disables an internal command
Enable-n Show all internal commands that are disabled
ENABLE-A display the desired internal command
Enable-a |wc-1 shows the number of all internal commands
Enable |WC-1 displays the number of internal commands in the activation
2, External command: The file system path under the corresponding executable program file
View path: Which-a |--skip-alias; whereis
3. The command of the difference is either an internal command or an external command:
Type cmd
4. Search order when executing a command
Alias
Internal command
External command
Hash (cache table)
Path (command to store external commands)
5, hash cache table: After the system restarts the hash table is empty, when executing an external command, the default is to look for the command from the path path, the path to the command will be recorded in the hash table, when the command is used again, the shell interpreter will first look at the hash table, the existence of the execution, If it does not exist, it will look under path. Using hash cache table can greatly increase the call rate of the command
Common uses of HASH commands
Hash shows all the hash command paths
HASH-L Displays all hash command paths, including aliases
Hash-p Path alias manually add a hash
Hash-t Name Displays the hash path of the alias (command)
hash-d alias (command) to delete a hash entry for a specified command or alias
Hash-r empty All the hash
6, alias display all the aliases information
Alias alias = ' cmd-option parameter ' to define aliases for a command
Unalias aliases Cancel an alias
Unalias-a to cancel all aliases
Save/ETC/BASHRC for aliases
If an alias has the same name as another command, you can use the following methods if you want to use which command instead of which alias:
\cmd
' cmd '
"CMD"
/path/cmd
7. Aliases defined on the command line are valid only for the current shell process and can be defined in the configuration file if you want to be permanently valid.
Profiles for the current user only: ~/.BASHRC
Valid profiles for all users:/ETC/BASHRC
The new configuration given by the edit configuration does not take effect immediately and requires a re-read of the configuration file before it takes effect
Source/path/to/config_file
V. Simple commands
1. Command execution syntax
CMD option parameter
Options: Some features for enabling or turning off commands
Parameters: The Action object of the command,
(Multiple options and multiple arguments and commands are delimited by using white space characters
Cancel command and End command: Ctrl + C, ctrl+d
Multiple commands can be used on one line; separate symbols
A command can be divided into multiple lines with \)
2. Some basic commands in Linux
1. Time
Date displays system dates and times
Clock,hwclock: Display Hardware clock
Two types of clocks for Linux,
System clock: Linux system time, no longer works after shutdown
Hardware clock: Hardware clock, still working after shutdown, powered by a button battery on the motherboard
Hwclock-s calibration of the system clock, whichever is the hardware time
Hwclock-w the hardware clock, whichever is the system time
Date
+%y Only show year
+%m Only show Month
+%d Day
When +%h
+%m min
+%s sec
+%f year-month-day
+%t hours: minutes: seconds
Set the system time with date
Date Month day year [. seconds] Date 102013112020.45
Dae-s ' year-month-day time: minutes: Seconds '
- Cal Display Calendar
Cal shows this month's calendar
Cal year displays calendar for the year
Cal Month Year
3. About the Switch machine
Poweoff shut down the machine
Reboot restart
Init 0 shutdown
Init 6 Restart
Shutdown-r restart
Shutdown-h shut down the machine
Shutdown +n N minutes after shutdown
Shutdown 20:20 20:20 shutdown (timed off)
(How to cancel the shutdown, the current terminal can be CTRL + C to cancel the shutdown, at other terminals can command shutdown-c cancel the shutdown plan)
4. About viewing the current user's information
WHOAMI display the current user name
Who am/are/is any character to display information about the current terminal
Who displays information about all terminals
W Display detailed information and operation of all terminals
5.screen command
Screen creates a session that allows two terminals in different places to share one terminal, to knock commands on one of the terminals, and to display them on the other terminal.
Screen generates the default name of the session
Screen-s Session name creates a screen of the specified name
Screen-ls View all open screens
Screen-x Session name Join the created screen
Exit exits current session
6.echo output content on the terminal
-E does not start to interpret the function, default
-N Not wrap line
-E "" Open interpretation Function ""
\a Warning Sound
\b Backspace
\c No Line break
\ nthe carriage return to newline.
\ r Enter, that is, the cursor moves to the beginning of the line, but does not wrap
\ t Insert tab
Insert
7. About the use and role of Whatis
Whatis cmd or man-f cmd can only provide a basic description of the command. Not provide usage, based on database lookup, the advantage is that the retrieval speed is fast, the disadvantage is lack of real-time.
8.pwd view the path to the current directory
Pwd-d The current directory is a soft link, its source directory is displayed
9.ls usage
Ls-a Show all directories and files, including hidden files
Ls-a Show all files, except..
Ls-l listing files and directories in long format
-rw-r--r--. 1 root root 2193 Jul 17:28 passwd
File type |owner Permissions group permissions other Permissions | Hard link number |owner|group| file size (bytes) |mtime| filename
Ls-r recursion
LS-LD display details for the specified directory
Ls-s by file size in descending order
Ls-t by modification Time (Mtime) from new to old
Ls-ut by Access Time (Atime) from new to old
Ls-u according to the order of file storage
Ls-x Sort by file suffix
Ls-i Display Inode number
(Timestamp atime access time
Mtime File Data modification time
CTime File Metadata Modification time
To view the timestamp of a file or directory: Stat file or directory path)
Vi. Command Line History
History Command Query command to display the history of the current terminal
History Query historical record
History-c clears all the current history
history-d Delete A History
History-a writes the command executed by the current terminal to the history file (the file is determined by the variable, default to the user's home directory. Bash_history
History-w/path/filename.txt Writing history to the specified file
History-n read the unread history from the file
History-r to read the desired history from the file
!! Repeat the previous command
! -N Repeats the reciprocal nth command
! N repeatedly executes nth command
! : 0 Executes the previous command (remove parameters)
! STR repeats the previous command starting with Str
!? STR repeats the previous command containing STR
! Str:p only prints the command history that begins with Str and does not perform
! $:p Print out! The contents of the last parameter of the previous command
!:p the contents of the printout (all parameters in the previous command)
Ctrl-r searching for commands in the history command
Ctrl-g exiting from the historical search mode
Esc. (Click the ESC key to release and then click the. Key)
ALT +. (Hold down the ALT key while you click.) Key
Call History parameters
Cmd! ^ parameters that use the first parameter of the previous command to do a cmd
Cmd! $ to use the last parameter of the previous command to do a cmd argument
Cmd! Parameters for cmd with all parameters of the previous command
Cmd! : N parameters that use the nth parameter of the previous command to do a cmd
Cmd! n:^ the first argument to invoke the nth command
Cmd! N:m to invoke the M parameter of the nth command
Cmd! N:invoke all parameters of the nth command
Cmd! str:^ a command from the command history that starts with Str and gets its first argument
Cmd! str:$ from the command history to search for a command that begins with STR and gets its last argument
Cmd! str:n searches the command history for a command starting with STR and obtains its nth argument
Cmd! STR:Searches the command history for a command that begins with STR and gets all its arguments
Seven, bash shortcut keys
Ctrl+l Clear Screen
Ctrl+o executes the current command and displays the command again
Ctrl+s Lock, input run any command screen is not displayed, but still execute command
CTRL+Q Unlocking
CTRL + C Force end
Ctrl+d normal termination
CTRL + Z Hang (Pause command)
CTRL + A cursor moves to the beginning of the command, equivalent to home
Ctrl+e cursor moves to the end of the command line, equivalent to end
CTRL+F cursor moves one character to the right
CTRL+B cursor moves one character to the left
CTRL+XX cursor moves between the beginning of the command line and the current position of the cursor
Ctrl+u Delete the contents before the cursor
Ctrl+k Delete the contents after the cursor
Ctrl+w to the top of the word from the cursor to the left
Ctrl+d Delete a character after the cursor
Ctrl+h Delete Cursor one character of money
Ctrl+y Paste the deleted character to the cursor
Ctrl+t swap the position of the word at the cursor and before
Alt +f Move one word to the right
Alt +b Move one word to the left
Alt +r Erase All content
Alt +d Delete right from cursor to end of word
Alt +c Change the first letter of the word from the cursor to the right
Alt +u starts at the cursor and changes the right word to uppercase
Alt +l starts at the cursor and changes the right word to lowercase
Alt +t The position of the word at the swap cursor and before
Alt +n prompts for the specified character, repeats the character n times (n indicates a specific number)
Viii. Use of Ghome-ternima
Ctrl-shift-n Creating a new window
Ctrl-shift-q Close the current window
CTRL-SHIFT-T Create a tab page
Ctrl-shift-w Close a tab page
CTRL-PAUP/PADN switch to previous/next tab page
Ctrl-shift-c Copy the selected text
Ctrl-shift-v paste the text at the current cursor
IX. Document Management
1. File system
Files and directories are organized into an inverted root tree structure.
The file system starts from the root directory,
With "/", file names are case-sensitive,
Files with a. Start are hidden files,
Path delimiter "/"
The file has two types of data,
Meta Data metadata
Data
File name up to 255 bytes, with a path that contains a maximum of 4,095 bytes
Blue-to-catalog; green----executable; red---zip file; light blue--link file; Gray--Other files
2, the role of the directory under the Linux root directory
/boot: Boot file directory, kernel files, boot loader are stored in this
/bin: Basic commands for use by all users
/sbin: Basic commands for managing classes
/lib: Basic shared library files that the program relies on at startup and kernel module files
/LIB64: storage location for secondary shared library files dedicated to x86_64 systems
/etc: Configuration file directory
/home: House directory for ordinary users
/root: Home directory for admin Root
/media: Portable mobile device mount point
/MNT: Temporary file system mount point
/dev: storage location for device files and special files
/OPT: Where to install third-party applications
/SRV: Data used by services running on the system
/tmp: Temporary file storage location
/proc: A virtual file system for outputting kernel-related process information
/sys: For outputting information about hardware devices on the current system virtual file system
/selinux:securityenhanced Linux,selinux where information such as the relevant security policy is stored
3. File types under Linux
-: Normal file
D: Catalog file
B: Block device
C: Character device
L: Symbolic Link file
P: Piping File pipe
S: Socket file socket
4. Display the current working directory
Each shell and system process has a current working directory
1.PWD displays the current working directory
-p Display True physical path
-L Display link path (default)
5. How to represent a path
Absolute path: Starting with a forward slash, reaching the destination directory starting at the root directory
Relative path: Does not start with a forward slash, reaching the destination directory starting at the current directory
6. Change the Directory
CD a single CD command switches from the current directory to the home directory of the logged-on user
CD target path: switch from current directory to target directory
7. File wildcard characters
[:d Igit:]: Any number, equivalent to 0-9
[: Lower:]: Any lowercase letter
[: Alnum:]: Any number or letter
[: Blank:]: horizontal white space character
[: Space:]: Horizontal or vertical whitespace characters
[:p UNCT:]: Punctuation
[:p rint:]: Printable characters
[: Cntrl:]: Control (nonprinting) character
[: Graph:]: Graphic character
[: Xdigit:]: hexadecimal character
8. Create empty files and Refresh time
Touch Options File path: Create a file
-A changes only atime and CTime
-M only changes mtime and CTime
-T [[CC]YY]MMDDHHMM[.SS]
Specifying timestamps for Atime and Mtime
-C If the file does not exist, it is not created
9. Copying Files or directories
CP option Original file path (SRC) destination file path (dest)
-I: Tips before overwriting
–n: Do not overwrite, note the order of the two
-R:-r: Recursively replicate directories and all internal content
-A: Archive, equivalent to-DR--preserv=all
-d:--no-dereference--preserv=links do not copy the original file, just copy the link name
-P: Equivalent--preserv=mode,ownership,timestamp
-V:--verbose shows the process of copying
-F:--force when an ordinary user has RX permissions on a directory, use-F to force overwriting of files without modify permissions. That is, delete and create
SRC is a file:
If Dest does not exist: Creates a new dest and fills the contents of SRC into dest
If dest exists:
If Dest is a file: overwrites src content to dest, based on security, it is recommended to use the-I option for the CP command
If Dest is a directory: Create a new file with the same name as SRC under dest and populate the contents of SRC with the new file
SRC is a directory: Use the option-R at this time
If Dest does not exist: creates the specified directory and copies all files in the SRC directory to dest;
If dest exists:
If Dest is a file: Error
If Dest is a directory: Copy all files or directories under the SRC directory to the dest directory at once
10. Move and rename files
MV Option SRC dest
-I: Interactive
-F: Mandatory
-R: Recursive
11. Delete Files
RM Option Destination Path
-I: Interactive
-F: Force delete
-R: Recursive
12. Tree Display Directory
-D: Show only directories
-L Level: Specifies the number of levels to display
-P Pattern: Displays only the paths that are matched by the specified pattern
13 Creating a Directory
mkdir directory path Create a directory under this directory
-P: exists in no error, and can automatically create the required directories
-V: Show more information
-M Mode: Specify permissions directly when creating a directory
14. Delete Empty Directory
Rmkdir directory path Delete this empty directory
-P: Recursive deletion of the parent empty directory
-V: Show more information
Rm-r: Recursively delete a directory tree
X. Directory, metadata, inode tables and files
People refer to a file by the directory file name, each file has a corresponding I metadata, each metadata corresponds to an inode number, directory is a directory of files and file Inode number mapping
1. Metadata includes:
File type, permissions, Uid,gid
Number of links
The file's and different sizes and different timestamps
Data block pointer to file on disk
Additional data about the file
2. Command in CP:
Allocate a free inode number to generate a new entry in the Inode table
Create a catalog entry in the directory, associating the name with the inode number
Copy data to generate a new file
3. RM command
The number of links is decremented so that the inode number released can be reused
Put data blocks in the free list
Delete a catalog entry
The data is not actually deleted immediately, but when another file uses the data block it is
Covered
4, MV and Inode
If the MV command is targeted and the source file is in the same file system as the MV command
Create a new directory entry with a new file name
Delete old directory entries for old directory names
Does not affect the Inode table (except timestamp) or data location on disk: No data is moved
If the target and source are different file systems, MV is equivalent to CP and RM
Xi. Soft/Hard Links
1. Hard Links
Creating a hard link adds additional record entries to reference the file
Corresponds to a physical file on the same file system
Each directory references the same inode number
Increase number of links at creation time
When deleting files:
RM Command decrements The count of links, file to exist, at least one link number
When the number of links is 0 o'clock, the file is deleted
Cannot span partitions
To create a hard-link syntax:
ln filename [linkname]
2. Soft link
A symbolic link points to another file
LS-L displays the name of the link and the referenced file
The content of a symbolic link is the name of the file it references
The directory can be
Can span partitions
A path to another file whose size is a pointer to a path string.
length; does not increase or decrease the reference count of the target file inode;
Grammar:
ln-s filename [linkname]
3. View File types
Files can contain more than one type of data using file to examine the type of files, and then determine the appropriate command or application to use, with the syntax rules:
File directory path for options files
-B: File name is not displayed when listing file identification results
-F filelist: List file name and file type in FileList
-F: Replace the output file name with the specified delimiter by default: Delimiter
-L: View the file type corresponding to the corresponding soft link file
--help: Show Command online Help
Getting started with LINUX and some basic operations