Home >Operation and Maintenance >Linux Operation and Maintenance >Find out what subdirectories are in linux
How to find subdirectories in Linux: 1. Log in to the Linux system, open and enter the terminal; 2. Get the file path by executing the "man ls" command; 3. Enter and execute "ls -R | grep. /" command can get all subdirectories in the current directory.
#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
Linux Find out what subdirectories are there?
Find all subdirectories under the directory under LINUX
So we need to create the required file paths in advance.
The premise of this article is that the file path of the test environment already exists. This path does not exist in the new environment. At this time, you need to obtain the file path first.
When we use
man ls, a prompt will appear. When we want to find all files in the current directory, we can use the following command:
ls -Rto get the results as shown below, but Our goal is only to find paths, not subpaths and subfolders.
man grepto help with data search.
In fact, we only need to enter
ls -R | grep ./to get all subdirectories in the current directory.
find . -type fto directly obtain the path mentioned above. Then in the new environment, how to quickly create so many paths?
Copy the above results and
replace
Replace "./" with " mkdir -p ./ "
Replace " : " with "; "
mkdir -p ./xxxx ;where The existing path will no longer be created. If there is no such path, its parent path will be automatically created, so there is no need to worry about the original path file being replaced and left blank.
Just execute all the above, or you can create a xx.sh file and enter the commands in it.
Execution
sh xx.sh;What should I do if there are too many paths and cannot be copied to the editor for replacement?
The above statement first redirects to a certain file, for example:
">" is an overwrite redirection, so when redirecting, first check whether hello.sh exists, and it will be overwritten if it exists.
">>" is an additional direction
command parsing, the . here refers to all paths under the current path. Use / to get all directories under the root directory.
find . -type f > hello.sh;vi hello.sh;Enter the following command in the editor. It is best to type it by hand. If you copy it, you cannot enter the command mode.
:%s/\.\//mkdir -p /g :%s/$/;/g :wqAt this point you can get an sh script and create the file where the directory needs to be created.
sh hello.sh;recommends learning: "linux video tutorial"
The above is the detailed content of Find out what subdirectories are in linux. For more information, please follow other related articles on the PHP Chinese website!