Common instructions and permission understanding
Command format:
command [-options] parameter1 parameter1
Command Options Argument 1 Argument 2
1.
command
For the command name, such as changing the directory,cd
etc.2. The square brackets
[ ]
do not actually exist in the command. The square brackets represent optional . Usually, a symbol is added in front of the option-
, such asls
orls-a
.3. Commands, options, parameters, etc. are separated by spaces. No matter how many spaces are empty, the shell will treat them as a space.
4. In Linux, uppercase and lowercase are completely different, such as
cd
andCD
.
ls command
Function : For a directory, this command lists all subdirectories and files under the directory. For files, the filename is listed along with other information.
-a List all files in the directory, including hidden files starting with . (commonly used)
-d only lists the directory itself, not the file data within the directory (commonly used)
-i Outputs index information for the i-node of the file. Such as ls -ai specified file
-k Indicates the size of the file in k bytes. ls –alk specifies the file
-l List the detailed information of the file, including data such as file attributes and permissions (commonly used)
-n Use numeric UID, GID instead of name. (introducing UID, GID)
-f List the results directly without sorting (ls will sort by file name by default)
-F appends a character to each file name to indicate the type of the file, "*" means executable ordinary file; "/" means directory; "@" means symbolic link; "|" means FIFOs; "= "Represents sockets. (directory type identification); none represent text files
-r Reverse the output of the sorting results, for example: the original file name is from small to large, and the reverse is from large to small
-t Sort by time.
-s Output the size of the file after the l filename. (Sort by size, how to find the largest file in the directory)
-R List files in all subdirectories. (recursive)
-1 Output only one file per line.
ls
It is to output the files in the current directory (excluding hidden files).
If you want to view hidden files, you can use
-a
the option to view.
First create a hidden file:
You can see ls
that you can't see the created yincang.txt
file, but if you use it ls -a
.
This will allow you to see hidden files.
If you want to view the detailed information of the file, you can use it
ls -l
, or it can be abbreviated asll
If you want to see the detailed information of hidden files, you can write as
ls -la
orls -al
both.
To specify a directory, just add the name of the directory after the command.
If I only want to view
108
the information of this directory instead of the information of the files in this directory of 108, I can use-d
the command
ls -ld
pwd command
**Function: **pwd command is mainly used to view the current directory of the user.
cd command
**Function: **Change the working directory, change the current working directory to the specified directory
cd … : return to parent directory
cd /home/litao/linux/ : absolute path
cd …/day02/ : relative path
cd ~: enter the user's home (home) directory
cd -: return to the last visited directory
You can see .
and ..
are both directory files, and the directory file can be cd
opened with , cd ..
which returns the previous line, so cd .
what is it?
It can be seen that cd .
there is no change in the directory after the input, but .
it is actually used to locate the current directory. The action scenario is generally used to locate the current directory when running a C language program.
gcc test.c
./1.out
touch command
Function : The touch command parameter can change the date and time of the document or directory, including access time and change time, or create a new file that does not exist.
-a or --time=atime or --time=access or --time=use only changes the access time.
-c or --no-create Do not create any documentation.
-d Use the specified datetime instead of the current time.
-f This parameter will be ignored and not processed, it is only responsible for solving the compatibility problem of the BSD version touch command.
-m or --time=mtime or --time=modify only change the change time.
-r Set the date and time of the specified document or directory to be the same as the date and time of the reference document or directory.
-t Use the specified datetime instead of the current time.
mkdir command
Function : Create a directory named "dirname" under the current directory
-p can be a path name. At this time, if some directories in the path do not exist yet, after adding this option, the system will automatically create them
Good for those directories that don't exist yet, that is, multiple directories can be created at a time;
mkdir –p d/d1/d2/d3/d4/d5 : 递归建立多个目录
rmdir and rm commands
rmdir is a command corresponding to mkdir. mkdir is to create a directory, and rmdir is a delete command.
The rm command can delete files or directories at the same time
-f Even if the file attribute is read-only (that is, write-protected), delete it directly
-i Ask for confirmation one by one before deleting
-r delete the directory and all files under it
If rm -r
you use delete, you will ask whether you want to delete one by one, because r
it represents recursion. If you don’t want to be prompted to confirm the deletion, you can add a parameter-f
In this way, the deletion is successful.