12/26/2023 0 Comments Linux find directory by name![]() ![]() You can use these commands in every Linux distribution since they are readily available in every Linux distribution. In this article we have learnt two simple ways to easily find directory by its name in Linux. drwxrwxr-x 2 root ubuntu 4096 Dec 9 06:02 /project Now we pass the above output again to grep command, this time searching for folder name ‘/project’. Here is an example drwxrwxr-x 2 root ubuntu 4096 Dec 9 06:02 /projectĭrwxrwxr-x 2 root ubuntu 4096 Dec 9 05:03 /dataĭrwxrwxr-x 2 root ubuntu 4096 Dec 9 03:04 /files path/to/file is the directory in which you want to search for the file. Well break down the command into simple parts. You can use a variation of this command to find any file or directory on your Linux machine. This is because the permissions of directory start with ‘d’ character. Youll typically use the find command with the syntax find /path -type f -iname filename. We pass this to grep command which searches for results beginning with ‘d’ character in Linux. Ls -lR command recursively lists all files and folders of specified folder, along with their permissions. projects $ sudo ls -lR /home/ubuntu | grep '^d' | grep '/projects' In this approach, we use ls command to list all contents of search location recursively, and pass its output to grep command to look for required folder e.g. In the above command, replace /home/ubuntu with your choice of search location and ‘project’ with your choice of folder name. In the above command the find command finds all directories in /home/ubuntu folder, and passes its output to grep command, which searches for ‘projects’ in it and lists only matching records. Here is an example to find directory with name ‘projects’ in Linux in /home/ubuntu directory $ sudo find /home/ubuntu -type d | grep 'projects' In this approach, we use a combination of find and grep commands to find directory in Linux. Here are the different ways to find folder name in Linux. There are a couple of different ways to find folder name in Linux. In this article, we will look at how to find directory name in Linux. ![]() But sometimes you may need to find directory name in Linux or find folder name in Linux. Typically, we search for filenames using grep or find command in Linux. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |