Home  >  Article  >  Operation and Maintenance  >  Find out what subdirectories are in linux

Find out what subdirectories are in linux

藏色散人
藏色散人Original
2023-03-28 11:08:313075browse

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.

Find out what subdirectories are in linux

#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

##Many times, if a certain Some file paths have not been created, which may cause errors when the program is executed.

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 -R
to get the results as shown below, but Our goal is only to find paths, not subpaths and subfolders.


Find out what subdirectories are in linux

In fact, you can use

man grep
to help with data search.

In fact, we only need to enter

ls -R | grep ./
to get all subdirectories in the current directory.


Find out what subdirectories are in linux

This is the method of thinking more than learning. If we directly learn the find command, we can use

find . -type f
to 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
:wq
At 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:what is linux gemNext article:what is linux gem