Linux Shell CentOS write a command to display the directory structure, quickly find the directory structure

Linux Shell CentOS write a command to display the directory structure, quickly find the directory structure


1. Code

#!/usr/bin/env bash



# 本命令用于显示指定路径或者当前路径的文件结构,支持搜索

# tf 显示当前目录的文件结构
# tf 接关键词  搜索当前目录
# tf 目录 关键词 搜索指定目录







# 本命令依赖于 tree 命令

DIR=
KEYWORD=

# 不传路径 默认为搜索
if [ $# -eq 1 ]; then
  KEYWORD=$1
fi


# 指定路径搜索
if [ $# -eq 2 ]; then
  DIR=$1
  KEYWORD=$2
fi


if [ -n "$DIR" ]; then
   cd "$DIR" || exit 1
fi


pwd

tree -C -f | grep "$KEYWORD"

2. Use effect

Current path

tf

Insert picture description here

search for

tf 关键词

// 比如
tf lib

Insert picture description here

Specify search path

tf /usr/local/ lib

Insert picture description here

3. Color meaning

1. Blue represents the directory
2. Green represents the executable file
3. Red represents the compressed file
4. Light blue represents the linked file
5. Gray represents other files
6. The red flashing represents the link file has a problem
7. Yellow represents the device file
8. White represents general files, such as text files, configuration files, source code files, etc.

Guess you like

Origin blog.csdn.net/qq_15071263/article/details/109332343