1. Use PWD and CD commands to identify and switch directories
You can use the PWD command of the Linux system to display the absolute path to the current directory. Abbreviation for PWD (print working directory).
For example:
[Email protected] ~]$ Pwd/home/lyj
This is under normal user status.
You can use the SU command to switch user identities and switch to root.
<pre name= "code" class= "plain" >[[email protected] ~]# pwd
/root
This is the display of the PWD command directory under the root identity.
(1) Use absolute path. Switch to the home directory using the CD command
[Email protected] ~]# Cd/home
View the results of the command execution correctly.
[Email protected] home]# Pwd/home
You can use the LS command to view the contents of this directory.
[Email protected] home]# lscat dog lost+found
(2) Use ".." Go to the top level directory.
(3) using relative paths
(4) Use "~" or blank to switch to the user's home directory
(5) Use "-" to switch to the working directory before the user
2. Use the LS command to list the contents of the directory
ls [options] [Directories|files]
options--start with "-" options are plural, indicating that multiple options can be used at the same time
A directories|files--directory or file, which is a complex number that indicates that multiple directories or files can be used at the same time
If you want to know what file type is displayed, use the-F option in command LS, the meaning of the file type symbol:
/:--represents a directory
*:--represents an executable file
Nothing: Represents a plain text file or an ASCII code file
@:--representing Symbolic links
Ls-a can view hidden files, so-called hidden files are filenames with "." You can also use the LS--all command to start a file
Ls-a/home/dog/home/cat
This command can display all files in multiple directories, namely: two directories are/home/dog and/home/cat
3. Copy files and directories using CP command
Use the CP command to copy a file or directory from one location to another. That is, the file (which can be multiple) is copied into a specified destination file or copied to a specified target directory.
CP [-option (s)] Source (s) target
SOURCE – can be one or more files or one or more directory names
Target (destination)-can be a file or a directory
-option options:
-I (interactive interaction): Prevents accidentally overwriting a file or directory that already exists, giving a hint before overwriting
-R (Recursive recursive): the recursive assignment directory. When copying a directory, copy all of the contents of the directory, including the entire contents of the subdirectory.
-P (Preserve maintenance): Preserves some specific attributes, such as timestamps, etc.
-F (Force mandatory): If the target file already exists, the system does not ask but force replication, that is, to overwrite all the original files directly
[email protected] home]# CP cal2009 cal2038
Copy the original file cal2009 as a new file cal2038, and you can use Ls-l to view it to verify that the command was successful.
[Email protected] home]# cp-i lists cal3009
Cp:overwrite ' cal3009 '? N
Because the cal3009 file already exists, there will be a popup message, answer n, indicate not overwrite, if answer y, means overwrite.
CP Command Summary:
(1) If the specified target does not exist, a file with the same name will be created and the contents of the source file will be copied in
(2) If the specified target already exists and is a file, the system will overwrite the original target file with the specified file
(3) If the specified target already exists and is a directory, the system will place the specified file in this directory with the same name as the source file.
4. Use the MV command to move and modify file and directory names
Use the MV (move abbreviation) command to move files and directories between different directories, or to rename files and directories. The MV command does not affect the contents of a file or directory that has been moved or renamed. The format is the same as CP. Examples are as follows:
[Email protected] home]# MV lists Babydog
Move the file lists to Babydog in the home subdirectory.
[Email protected] home]# MV Babydog Boydog
Use the MV command to change the directory named Babydog to Boydog
MV Command Summary:
(1) If the specified target does not exist, the system will rename the source files and directories to the target file or directory
(2) If the specified target already exists and is a file, the system will rename the specified file to the name of the target file and overwrite the contents of the original target file.
(3) If the specified target already exists and is a directory, the system will move the specified file to this directory with the same name as the source file.
5. Create a directory using the mkdir command
MKDIR is the abbreviation for Make directory. Its syntax format is:
mkdir Directory Name
Where the directory name can be a relative path, or it can be an absolute path
[Email protected] home]# mkdir Daddog
Create a directory named Daddog
[Email protected] home]# mkdir ~/mumdog/girldog/babydog
Mkdir:cannot Create directory '/home/dog/mumdog/girldog/babydog ': No such file or directory
A system prompt indicates that the directory could not be created. is because there is no girldog subdirectory in the Mumdog directory.
For this scenario, you can use the mkdir command with the-P option.
When the-p option is added, the mkdir command creates all directories that do not exist in the specified path.
6. Create a file using the Touch command
Touch file name
[email protected] home]# Touch babydog1
You can also create multiple files at once
[email protected] home]# Touch babydog1 babaydog2 babydog3
7. Delete files using RM command
RM is the abbreviation for remove, in the following format:
RM [Options] Files|directories
- I (interactive interaction): Prevents accidentally deleting a useful file , giving a hint before deleting it
-R (Recursive recursive): a recursive delete directory. When you delete a directory, all the contents of that directory are deleted, including the entire contents of the subdirectory.
-F (Force mandatory): The system does not ask but force the deletion, that is, delete all the files directly
[Email protected] home]# RM babydog1
deleting files Babydog1
8. Delete the directory using the rmdir or RM-R command
rmdir (the Remove directory abbreviation ) command is to delete an empty directory.
Rm-r can delete directories that contain files and subdirectories
The format is as follows:
RmDir Directory Name
[Email protected] home]# rmdir Mumdog/girldog/babydog
Delete the Babydog directory under this path, this Babydog directory is empty
[Email protected] home]# rmdir Mumdog
RmDir: ' Mumdog ': Directory not empty
Tip The Mumdog directory is not empty, so it cannot be deleted unless all subdirectories under its directory are deleted
You can now use Rm-r to delete
[Email protected] home]# rm-r Mumdog
Can be deleted directly, will not pop up the prompt message