A few common concepts about Linux folders
- Path
Descriptive narrative mechanism of file location information. Refers to a path from a folder hierarchy in a tree folder to one of its files. It is divided into relative path and absolute path;
- working folder
After logging into the system. The user is always in a folder, which is the working folder. Or is called the current folder
- root Folder
Top-level folder of the Linux tree folder structure
- User "Home" folder
Also known as the user home folder, is usually located in the/S folder with the same folder as username, the user logged into the system by default in this folder
Path-related
Description: A path is a pathway from a folder to a folder or file, identified by the name of each level of folder
- Absolute Path
Path from root folder/start to end of file name
For example:/usr/local/tomcat7/logs/catalina.out
- relative Path
Path not starting from the root folder
For example: CD. /catalina.out
several special symbols
. Represents the current path
.. Represents the upper folder
~ Represents the user root folder
~user represents the root folder of user
When the system logs in, the user will voluntarily jump to their home folder, the root user's home folder is/root, and the default home folder for other users (user) is/home/user
Environment variable Path
The role of the environment variable path is to provide a possible path to the user to find the file
When a new suite is installed, it may be necessary to write the path of the executable file to the environment variable
View the Path method
Echo $PATH
File, folder Operations Command
Overview:
folder Operations Command
ls pwd cd mkdir rmdir
text File View commands
cat more less head tail
File Operations Command
file Touch CP RM MV
file Content Statistics command
WC
File Link Command
ln
1. folder operation Commands
ls mkdir
command |
function |
|
pwd |
|
CD |
|
|
rmdir |
|
- ls command
function Description:
Outputs the specified folder contents to a standard output device;
assumes that file or directory parameters are not specified. Displays the contents of the current folder
by default. The LS command displays all information in alphabetical order of the file name
when the LS command displays the folder contents, it does not display the file entry whose name begins with a. (dot). Unless you use the-a or-a flag
command format:
ls [-aadffhilrs] folder name
ls [–color={none,auto,never,always}] folder name
ls [–full-time] folder name
the frequently used option of the LS command
-A lists all entries except. (points) and: (Point-to-point)
-a lists all items in the folder, including items starting with. (points)
-l (lowercase in L) display, number of links, total people, group, size (in bytes), and each file recent change time
D This item is a folder
b This entry is a block special file
C This entry is a character special file
L This entry is a symbolic link
p This entry is a FIFO special file
s This is a local socket
-This item is a normal file
-R Reverses the sort order, sorts the appropriate alphabetically, or sorts the oldest file first
-R recursively lists all subfolders
-H to more visually display file sizes
–color=never Do not follow the file attributes with different colors
–color=always display color
–color=auto Let the system set itself to show the color
–full-time output in full time mode
–time={atime,ctime} Output access time or time to change permissions, not change time
- pwd Command
function Description:
Displays the path name of the working folder (print working directory)
command Format
pwd [-p]
The PWD command writes the full path name (absolute path) of the current folder to the standard output device; All folders are delimited with A/(slash); The first/represents the root folder. The last folder is the current folder
[-p] shows the actual path, not the path of the connection
/var/mail is a connection file for/var/spool/mail
- CD Command
function Description:
Changing the current working folder (change directory)
command format:
CD [Relative path or absolute path]
Instructions for use:
user must have permission to run in the specified folder
Assuming that no folder parameters are specified, the CD command sets the current working folder as the logon folder
Supports relative paths and absolute paths
Application Examples:
CD ~user to switch to User's primary (home) folder
. (dots) indicates the current folder
.. (dot) indicates the parent folder
CD ~ Return to the current user home folder
CD-Returns the folder where the user last located
- mkdir Command
function Description:
Create one or more new folders
command format:
mkdir [-MP] folder name
Instructions for use:
Each new folder contains standard items. (points) and. (Point-point)
-P creates the Lost intermediate path name folder; Assuming that the-p flag is not specified, the parent folder of each newly created folder must already exist
-m set permissions for newly created folders, regardless of default permissions
- rmdir Command
function Description:
Delete a folder
command format:
rmdir [-p] Folder name
Instructions for use:
Must be empty, and must have write permission to the parent folder
-P Remove all folders along the path name specified by the number of parameters
Like what. Suppose you want to remove ~/test, ~/test/test1, ~/test/test1/xyz, and use the following command, for example
rmdir –p ~/test/test1/xyz
2. File Operation commands
Command |
function |
File |
Displays the type of the specified file |
Touch |
Create a file with the specified name or update the file time |
Cp |
Copy a file or folder |
Rm |
Delete a file or folder |
Mv |
Move a file or folder, rename a file or folder |
- File Command
function Description:
Determine file type
command format:
File name
Instructions for use:
Files can be regular files, folders, FIFO (specified pipes), block special files, character special files, symbolic links, or socket types
For regular files with a length of zero. will be recognized as an empty file
For symbolic link files, this link is followed by the file referenced by the symbolic link by default
UTF, which is the abbreviation for Unicode Text format. meaning Unicode Text Format
Touch Command
function Description:
Create a new file
Update the file's access and change times
Change CTime (Use–change time)
Interview Time Atime (access)
format:
Touch [-opt] {file| Directory}
frequently used options
-A change the access time for files specified by the file variable
-C If the file does not exist, do not create it
-M Change File modification time
-T time uses the specified times instead of the current time.
The time variable is specified in decimal form [YYMMDDHHMM]
YY The following two digits for the specified year
MM Specifies which January of the year (from 01 to one)
DD specifies which day of January (from 01 to +)
hh Specifies which hour of the day (from 00 to all)
mm Specify which minute of the hour (from 00 to a)
Command Instance
RM Command
function Description:
Delete (link) a file or folder
command format:
RM [opt] File/dir
Instructions for use:
Suppose the file you want to delete is a symbolic link. The link is dropped, but the file or folder referenced by the symbolic link is still
Frequently used options
-F does not prompt before deleting a write-protected file
-I prompt before deleting each file
-R recursively deletes a folder and its contents when the target parameter is a folder
-R with-R
Command Instance
- MV Command
function Description:
Move (rename) a file or folder
MV command to overwrite existing files
command format:
MV [opt] source destination
description of the parameters:
-F: Force direct transfer without asking
-I: If the target file already exists ask whether overwrite
-U: If the source file already exists, but the source file is newer, the update
Command Instance
- CP Command
function Description:
Copy a file or folder
command format:
CP [-OPT] [Src_file|src_dir] [Dst_file|dst_dir]
frequently used options
-A is used when copying folders. Keep links, file attributes, and copy folders recursively
-D Keep Links when copying
-F assumes that the specified destination file exists. Force Override First
-I require user confirmation before overwriting the target file
-p copy file. Includes its change time and access rights
-r Copy the contents of the folder when the folder can be copied recursively
-R like-R. But special files will be created again. Rather than replication
Command Instance
Command instance diagram
3. text File View commands
cat
command |
function |
display text file contents |
tac |
from the last line to start showing. TAC and Cat alphabetical order opposite |
nl |
display, output line number |
more |
pagination display text file contents |
less |
pagination displays text file contents and facilitates repeated browsing |
head |
|
tail |
|
Cat Command (CONCATENATE)
function Description:
Display text file contents
command format:
Cat [-aentv] File name
description of the parameters
-N or –number numbering of all output lines starting from 1
-V displays non-printable characters as visual characters. In addition to jumping Geff, newline characters, and page breaks;
-e displays a $ (dollar sign) at the end of each line
-T displays the jump-^i character as a, combined with-V;-t=-vt
-A equals to-vet
function 1:
Displays the specified file from the first line continuously on the screen, which is not applicable when the file is too large
such as Cat Install.log
function 2:
To connect two or more files together
Format:
Catfile1 file2 ... >filen: Copy the contents of File1, file2, etc. to the new file Filen
Command instance
TAC Command
function Description:
Start the display from the last line. TAC and Cat alphabetical order opposite
Command Instance
- NL Command
function Description:
When displayed, the output line number
command format:
NL [-BNW] File
description of the parameters:
-B: Specify how line numbers are specified
-B A: Indicates the same line number, whether or not it is a blank line
-B T: If you have a blank line, do not list line numbers in a blank line
-N: List the representation of line numbers
-N-Ln: line number appears at the left of the field
-N RN: line number is displayed to the right of the field without adding 0
-N RZ: line number appears to the right of the field, plus 0
-W: Number of digits occupied by the line number field
- More Commands
function Description:
Pagination display of text file contents
command format:
More file names
Instructions for use:
More commands to read the file and display the content on the standard output device
This command pauses after each screen and prints the word more and the percentage of content displayed at the bottom of the screen
Enter: More command will display a line down again
SPACEBAR: The more command displays text with a screen.
- Less command
function Description:
Pagination Displays the contents of the text file. And can be easily repeated browsing
command format:
Less file name
Instructions for use:
The less command functions almost as much as the more command. It is also used to display files by page. The difference is that the less command agrees that the user can both forward and backward through the file when displaying the file
Frequent use of function keys
PageUp
PageDown
/Search Down
? Search up
- Head Command
function Description:
Show file Header content
command format:
Head [–n Num] File ...
Option Description:
The-n option specifies the number of lines to display for file
Instructions for use:
Displays the first few lines or the first few bytes of a file or multiple files
The first 10 rows are displayed by default
The input file must be a text file
- Tail Command
function Description:
Show file Trailer content
command format:
tail [-nf num] File
Option Description:
The-n option is used to specify the number of lines from the beginning of each specified file to be displayed
+num Displays the contents from the beginning of Num line to the end of the file
-num display from the end of the file to the end of the file from the beginning of the content
-F Assuming that the file content is growing, this option dynamically displays the growing content until the user ends with "CTRL + C"
Instructions for use:
We often use the tail command when we look at the log of the server.
We always use this.
-f /usr/local/tomcat/logs/catalina.out
4. File Lookup command
Command |
function |
which |
The Whereis command will find the eligible files in a specific folder; |
where |
Starting from the last line, the TAC and cat are in reverse alphabetical order |
Locate |
Pagination display of text file contents |
Find |
Display. Output line number |
- which command
function Description:
To view the path to a running file
command format:
which [-A] command
frequently used options:
-a lists all the commands that can be found, not just the first command found
Example:
pwdwhich lsattr
whereis Command
function Description:
Find "Specific Files"
The Whereis command will find the eligible files in a specific folder;
command format:
Whereis [Options] File list
frequently used options :
-B Just looking for binary files
-M just looking for a description file
-S just find the source file
-U files without Help files
Command Instance
Locate Command
function Description:
Used to find files that meet the criteria. It will go to the database where the file and folder names are saved, find the eligible files or folders
command format:
Locate file name
Instructions for use:
The database needs to be established first. And the rear can be searched
The UpdateDB command is used to generate the most recent file name database, which generates MLOCATE.DB database under folder/var/lib/mlocate/
It looks faster than find, but the process of updating the database itself can be time-consuming
- Find Command
function Description:
Searches for a file in the folder structure and runs the specified action
command format:
Find Start folder lookup condition [action]
Instructions for use:
Start folder: The folder path that the Find command looks for, such as available. To represent the current folder, with/to represent the system root folder
Search criteria: Matching mechanism, such as the ability to follow the file name, file permissions, change time, etc. for file search
Action: A specific processing method that is performed after a specified condition is found. If the found file is displayed on the screen. Or make permissions changes to it, or delete the found file, and so on.
Find Command search conditions (1)
-name ' string ' to find files according to file name
-lname ' string ' Find all symbolic link files matching the file name
-gid N Find all files belonging to the user group with ID number n
-uid N Find all files belonging to a user with ID number n
-group ' Strings ' Find all files that belong to the same user group
-user ' string ' to find all files belonging to the same user
-empty looking for files of size 0
-path ' string ' Find path name matches all files of the given string
-perm permissions to find files and folders that have the specified permissions. The representation of a permission can be as 755,644
Command Instance
Find Command search conditions (2)
-nogroup find files that do not have a valid owning group. That the group to which the file belongs does not exist in/etc/groups
-nouser find a file without a valid owner, that is, the owner of the file does not exist in the/etc/passwd
-type finding a file of a certain type
-size N [bck] finds files with a file length of n, with C indicating the length of the file in bytes
-depth when looking for a file, first find the file in the current folder, and then look in its subfolders
Command Instance
Find command search conditions (3)
Find time-based conditions
-amin +n-n Search by time. -n means less than a minute, +n means n minutes once
-atime +n-n by visiting time;-n refers to the nth day or less, +n means n days
-cmin +n-n Search by creation time
-ctime +n-n Search by creation time
-mmin +n-n Search by change time
-mtime +n-n Search by change time
-newer file lists files that are newer than
operations that can be run
-exec command {} \; Run command for eligible files
{} indicates that the number of commands is the file found
At the end of the command must end with "\;"
-ok command {} \. With-exec. However, the user is asked whether to run the command
Command Instance
/-name g.-exec-l\;
Find Command Sample
Find all file names starting with RC in the/etc folder
-name “rc*-print
Find common Files with all file lengths of 0 in the system and list their full paths
/-type-size0-exec-l\;
All files in/etc that start with passwd find out if the user is named Redhat
find /etc –name “passwd*” –execgrep “redhat” {} \;
Find all files in the current folder that end in TXT and have not been interviewed for 2 minutes
.-name “*.-amin+2-print
four different search command differences
which:
Search by the environment variable path specified path
Whereis. Locate:
Database that stores system file information
Find:
Direct Search for hard drives
5. Default permissions and hidden permissions for files and folders
umask
command |
function |
|
chattr |
|
lsattr |
|
set UID |
|
set GID |
|
sticky Bit |
|
- umask Command
Description of functional descriptions:
Mask to set new file permissions
command format:
umask [mode]
Instructions for use :
Mask value for the new file permission mode
The default permissions for folders in a Linux system are drwxrwxrwx, and the default permissions for files are-rw-rw-rw-. So. There are the following formulas:
Permissions for new folder = drwxrwxrwx-Default permission mask
Permissions for new file =-rw-rw-rw--Default permission mask
For security reasons, the Linux system does not agree that the file's default permissions have the right to run
The current default permission mask value is displayed without the Umask command, regardless of the number of parameters
Permissions for new folder = drwxrwxrwx-(d--w–w-)
= Drwxr-xr-x
Permissions for new files =-rw-rw-rw--(-–w–w-)
=-rw-r–r–
- chattr command
- Function Description:
Set hidden properties for a file
Command format:
chattr [+-=] [Asacdistu] File or folder
Description of the parameters:
A: Only data can be added. Can not be deleted, only the root ability to set
I: Able to make the file "cannot be deleted, renamed, set connection, cannot write or add data"
- lsattr Command
function Description:
Show hidden properties of a folder
command format:
lsattr [-ar] File or folder
description of the parameters:
-A: Show properties of hidden files
-R: Listed together with subfolders ' data
- Set UID command
Special Permissions
S and T: Let the average user run some programs. Ability to temporarily have permissions for the owner of the program.
- set GID command
function Description:
Assume that the permission of S is in the user group, called set GID, or Sgid
File: Assume that Sgid is set on a binary file, regardless of who the user is, when the program is run. Its effective user group will become the whole of the program user group.
Folder: Assuming that Sgid is set on the a folder, the user group for the file or folder created within the A folder will be the user group for this a folder.
- Sticky Bit Command
function Description:
Valid only for folders
In a folder with Sbit, if the user has W and x permissions under the folder, then when the user creates a file or folder under that folder, only the owner and root of the file have the right to delete it.
suid/sgid/sbit permission Settings
Suid:4
Sgid:2
Sbit:1
Format: chmod xxxx filename
Command Instance
Linux Review (iii) Linux file and folder management