ls command:
Used to display the target list, which is a high-usage command in Linux. The output information of the LS command can be colored and highlighted to partition different types of files.
Grammar:
ls [options] [filename ...]
Common options:
-A: Lists all files in the directory, including "." The hidden file at the beginning.
-D: Lists directory names like other files instead of listing their contents. (Common usage: ls-ld [directory name])
-I: File inode number (also called serial number/index number) is displayed on the left side of the file
-K: File size units, plus-M,-H, etc.
-L: Single-line display of file or directory details
-R: Recursively lists the contents of all directories
-S: Displays the size of files and directories in chunks
--color: Specifies whether to use color to differentiate file categories; default is ls= ' ls--color=auto '
File type: the
We can use the ls-l command to view, generally the first character is the type of file, the type is as follows:
-: Normal files, including plain text files, binaries, and data files
D: Catalog file
L: Link file, like a shortcut under Windows
B: Block device files, such as hard drives, optical drives, etc.
C: Character device files, such as mouse, keyboard and other serial interface devices
S:socket Data Interface File
P: Pipeline file (fifo,pipe), FIFO is also a special type of file; (p rarely seen)
Alias command:
The alias used to set the instruction. We can use this command to simplify some of the longer commands, and it's best to use alias to prevent errors. Note: The alias function is limited to this login, and if you want to permanently set it, you need to add it in the/ETC/BASHRC file.
Usage:
Alias new command = ' original command-options/Parameters '
Example: Alias ls= ' Ls-l '
Common usage:
Alias: View aliases already set by the system
Unalias: Remove alias command
Which LS: can view alias information
Absolute and relative paths:
Absolute path: The path must be written by the root directory '/', for example/usr/local/mysql this is the absolute path.
Relative path: The path is not written by the root directory '/', for example, first the user enters the/, then Cd/home enters the home, then the CD test at this time the user's path is/home/test the first CD command followed by '/home ' second CD command followed by ' Test ', there is no slash, this ' test ' is relative to the '/home ' directory, so it is called the relative path.
PWD: View current path
CD command:
Used to switch the working directory to dirname. Where dirname notation can be either an absolute path or a relative path. If the directory name is omitted, it is transformed to the user's home directory (that is, the directory where login was first). In addition, the ~ is also expressed as the meaning of home directory, which is the current directory. Indicates the current directory location of the previous level directory
Example:
CD into the user's home directory
CD ~ Go to User home directory
CD-Returns the directory where it was before entering this directory
Cd.. Return to Parent Directory
Cd.. /.. Return to the top level two directory
CD!$ Use the parameters of the previous command as CD parameters (!$ represents the parameters of the previous command)
cd/usr/local/into/usr/local directory, using absolute path/relative path
mkdir and RmDir commands:
The mkdir command is used to create a directory where you want to create multiple directories separated by spaces, such as mkdir 123/345/456/; If you want to create a multilevel directory using the parameter-p, such as Mkdir-p/root/123/456/
rmdir command to delete empty directory, this command can only delete empty directory, non-empty directory can not be deleted; Use the parameter-p to delete a multilevel empty directory, such as Rmdir-p/root/123/456/
RM command:
You can delete one or more files or directories in a directory, or you can delete a directory and all of its subordinate files and subdirectories. For linked files, just delete the entire linked file, and the original file remains unchanged
The two most commonly used options are described here for detailed help information. Can be viewed through the man RM;
-r: Delete all files in directory and directory; Rm-r can delete non-empty directories and prompt for confirmation of deletion
-F: Indicates forced deletion and does not prompt for deletion;
Two options combined, either file or directory can be deleted;
Use the RM command with extreme caution. Because once a file is deleted, it can no longer be recovered "
Environment variable Path:
View environment variables: Echo $PATH
Custom ADD environment variable: path= $PATH:/root (temporarily modified)
Permanently modify the/etc/profile file to append the last content
If you want to delete a custom variable, the value will be re-assigned.
CP Command:
Used to copy one or more source files or directories to a specified destination file or directory.
Grammar:
CP [Options] [source file] [target file]
Common options:
-I: Ask the user before overwriting the file
-r/-r: Recursive processing, the copy directory must be added with this option
-V: Verbose display of the command execution process
Example:
CP 1.txt 2.txt
Cp-r/test//tmp/test_bak/(at the end of the copy directory it is best to add/) ....
MV Command:
Used to rename a file or directory, or to move a file from one directory to another. Source represents the origin file or directory, and target represents the destination file or directory. If you move a file to a target file that already exists, the contents of the destination file will be overwritten.
Grammar:
MV [options] [source file] [target file]
1. The destination file is a directory and the directory exists: the source file will be moved to the target directory
2. The destination file is a directory but the directory does not exist: This is equivalent to directory renaming
3. The destination file is not a directory and exists: will prompt for overwrite
4. The destination file is not a directory and does not exist: equivalent to renaming the source file
Document view commands (cat, more, less, head, tail):
Cat: Commonly used to display file contents,-n Input display line number,-a display all content (line terminator $)
MORE: Used to view the contents of a file, followed by the file name, when the file content too much, a screen can not be taken up, and you use ' cat ' must not see the previous content, then use ' more ' can solve the problem. When you finish reading a screen, press SPACEBAR to continue looking at the next screen. But after reading all the content, you will exit. If you want to quit early, just press the ' Q ' button.
Less: Very similar to more, can be used to browse the content of the text file, the difference is that the less command allows users to browse the file forward or backward, and the more command can only be viewed forward. When displaying a file with the less command, use the PageUp key to page up and PAGE down with the PageDown key. To exit the less program, you should press the Q key.
Head: used to display the content at the beginning of the file. By default, the head command displays the contents of the first 10 lines of the file. The specified number of rows can be displayed using the parameter-N: Head-n5 1.txt
Tail: Used to display the end of the file, by default the last 10 lines of content, you can also use-N to specify the number of rows;-F to dynamically display the last 10 lines of the file (commonly used to view the log)
chmod command:
Permission to change a file or directory
Grammar:
chmod [options] Mode file ...
Graphic:
Example:
Chmod-r Dir1 (-R = recursive)
chmod o+x test.sh
chmod u=rwx,g=r,o=r test.sh
Chown command:
Used to change the owner of a file
Grammar:
Chown [-r] Account name: Group name File name (-R = cascade change)
Example:
Chown user1 Dir1;
Chown-r User1:group1 Dir2;
Chown:group1 Dir1
The CHGRP command is used to modify the owning group of a file, format: chgrp [group name] [FileName] = = chown: [Group name] [filename]; So chgrp is not used.
Umask
The mask used to set restrictions on new file permissions, the default value is 0022, so by default the directory permission value is 755, and the normal file permission value is 644.
The permissions for the directory are ' rwxrwxrwx '-'----w--w-' = ' rwxr-xr-x ', the normal file's permission is ' rw-rw-rw-'-'----w--w-' = ' rw-r--r--'
Umask Temporary modification: umask 002, permanent modification needs to be modified in the/ETC/BASHRC file!
"When calculating file permissions, try to use nine-bit permission value calculation, direct use of numeric calculation will be wrong"
Lsattr and Chattr commands:
Chattr: Used to change file special attributes
Syntax: chattr [+-=][ASACI] [file or directory name]
' +-= ': increase, decrease, set, respectively
' A ': When this attribute is added, the atime of the file or directory will not be modified;
' S ': When this attribute is added, data is written to disk synchronously;
' A ': After adding this attribute, can only append cannot delete, non-root user cannot set this attribute;
' C ': Automatically compress the file, the reading will be automatically extracted;
' I ': added so that the file cannot be deleted, renamed, set Link, write, new data
LSATTR: special permission to read a file or directory
Syntax: lsattr [-ar] [File/directory name]
'-a ': Similar to the-a option for LS, which is listed together with hidden files;
'-R ': listed together with subdirectories ' data
set_uid:(chmod u+s/usr/bin/ls)
This permission is for the binary executable file, which temporarily has the file owner's permission during the execution phase. For example, passwd This command has this permission. When a normal user executes the passwd command, it can temporarily gain root privileges, allowing the password to be modified.
Set_gid: (chmod g+s/usr/bin/ls)
This permission can be used on a file (binary executable file) or in a directory. As used on a file, its functionality is like Set_uid, which causes the file to have the permissions of the group to which the file belongs during the execution phase. After the directory is set for this permission, any user who creates the file in this directory has the same group as the directory
stick_bit: (chmod o+t dirname)
Can be understood as anti-delete bits. Whether a file can be deleted by a user depends largely on whether the directory in which the file resides has write access to the user. Without write permissions, all files in this directory cannot be deleted and new files cannot be added. If you want users to be able to add files but not delete files from other users in that directory, you can add that permission to the parent directory. After you set this permission, you cannot delete other users ' files, even if the user has write access to the directory.
Linked files (soft links and hard links):
LN command: used for file creation connection, divided into two kinds of hard connection and soft connection
Grammar:
ln [-S] [source file] [target file] (without S is to create a hard link, plus s is to establish a soft link)
Attention:
1. You cannot create hard links to a directory, or you cannot make hard links between different file systems
2. Hard links do not create new file space, and soft links create new files
3. The directory can be a soft link; Once the source file is deleted, the soft link file becomes invalid.
search for files under linux command :
Which command: Find an absolute path to an executable file
Whereis command: Fuzzy Lookup files, as long as the inclusion of search characters will be listed (and therefore not commonly used)
Locate command: Fuzzy find file or directory, also not suitable for precise search (also not used); Note that this command requires Yum to install and initialize the database files to search.
Find command:
See "Find command Summary"
File suffix:
In the Linux system, the file suffix name is not specific, that is, you add or not add, it does not matter. But to be easy to distinguish, we are used to adding a suffix to the file so that when the user sees the file name it will quickly think about what the file is.
Linux and window transfer files :
Yum install-y Lrzsz; support Xshell and CRT, putty not supported, and not easy to use, frequent transmission failure! Recommended use of XFTP
Linux--Windows:sz filename
Windows--linux:rz filename
Common commands for Linux files and directories