This article mainly introduces how Linux finds subdirectories. In daily operations, I believe that many people have doubts about the method of finding subdirectories in Linux. The editor consulted various materials and organized This is a simple and easy-to-use operation method, and I hope it will be helpful for everyone to answer the doubts about how to find out the subdirectory in Linux! Next, please follow the editor to learn together!
How to find the subdirectory in linux: 1. Log in to the linux system, open and enter the terminal; 2. Obtain the file path by executing the man ls command; 3. Enter And execute the ls -R | grep ./ command to get all subdirectories under the current directory.
Many times, if some file paths are not created, it may cause an error when the program is executed.
So we need to create the required file path in advance.
The premise of this article is that there is already a file path of the test environment, but there is no such path in the new environment. At this time, the file path needs to be obtained first.
When we use
a prompt will appear, when we want to find all the files in the current directory, You can use the following command:
to get the result as shown in the figure below, but our goal is to find the path, and Not subpaths vs. subfolders.
In fact, you can use
to help with data search. In fact, we only need to enter
ls -R | grep ./
to get the current directory All subdirectories under .
This is the way of thinking more than learning. If we directly learn the find command, we can use
find . -type f
You can directly get the path mentioned above.
When it comes to the new environment, how to quickly create so many paths?
Copy the above results and replace
from " ./ " to " mkdir -p ./ "
from " : " to "; "
mkdir -p ./xxxx ;
The existing path is no longerCreate, without this path, its parent path can be automatically created, so there is no need to worry about the original path file being replaced and empty.
All the above can be executed, or you can create a xx.sh file and enter commands in it.
If there are too many paths, they cannot be copied to the editor for replacement, How to do it?
The above statement first redirects to a certain file, for example:
">" is an overlay orientation, so when redirecting, first check whether hello.sh exists, and if it exists, it will be overwritten.
>>" is an additional orientation
command analysis, the . here refers to all paths under the current path. Use / to get all directories under the root directory.
< code>find . -type f > hello.sh;vi hello.sh;
Enter the following command in the editor, it is best to type and copy by hand, and you cannot enter to command mode.
:%s/\.\//mkdir -p /g
You can get a sh script at this time, just create a file where you need to create a directory.
Copyright Description：No reproduction without permission。
Knowledge sharing community for developers。
Let more developers benefit from it。
Help developers share knowledge through the Internet。