Linux find all jar

How to get all jars that are residing in current dir and sub-dirs?

I need to find all jar files using ls cmd in current directory and sub-directories. For the below directory structure:

path |_to |_curr-dir |_abc.jar |_sub-dir1 |_xyz.jar |_sub-dir2 |_pks.jar ls path/to/curr-dir/**/*.jar lists sub-directories jars and omits current directory jar path/to/curr-dir/sub-dir1/xyz.jar path/to/curr-dir/sub-dir2/pks.jar 

1 Answer 1

If you don’t need to use ls and care about portability, then find is the best tool for the job. The command find . -name ‘*.jar’ will find all .jar files in the current directory and its (recursive) subdirectories.

If you need to use ls or want something easier to remember (though less portable), you can use Bash (and Ksh)’s globstar option (enabled by shopt -s globstar ), then ls **/*.jar (this is the default behavior in Zsh).

thanks! Just realized it’s not a portable solution. I’m new to globbing and was trying to understand if there’s something wrong with my globbing solution to obtain jars.

so my requirement is to pass path [path/to/curr-dir/**/*.jar] to a software that probably uses ls cmd to get all the jars. This software is run in a container where the bash returns these results, after your answer I tried it on my zsh terminal and it works! We are using GNU bash, version 4.4.18(1)-release (x86_64-unknown-linux-gnu) seems like bug with globbing in bash. Please let me know if you have any suggestions, Thank you!

Источник

Linux Java Find Command with Specified Path

To refer to the current directory, use «/». If you want to search for files using the find command, there are multiple ways to do so. For instance, you can find files by name, type, modification time, permission, and text within multiple files. Additionally, you can even find and delete a file or replace files. The find command can be used in various conditions such as permissions, users, groups, file type, date, size, and other criteria. For example, you can search for all files ending with the extension ‘.txt.’

Search or list Java classes in classpath (ncluding JARS) via command line

find -name "*.jar" -exec jar -tf <> \; | grep "/\.class\$" 
find ~/.ivy2/ -name "*.jar" -exec jar -tf <> \; | grep "/Filter\.class\$" 
javax/servlet/Filter.class javax/servlet/Filter.class javax/servlet/Filter.class org/scalatest/Filter.class org/scalatest/Filter.class org/fusesource/scalate/filter/Filter.class org/fusesource/scalate/filter/Filter.class scala/tools/scalap/scalax/rules/Filter.class org/apache/ivy/util/filter/Filter.class com/foursquare/fongo/impl/Filter.class com/foursquare/fongo/impl/Filter.class com/foursquare/fongo/impl/Filter.class shapeless/Filter.class 

This solution doesn’t personally appeal to me.

Simply apply find to explore every class file.

Linux — How to use the find command in Java, Wanted to know if there is a find functionality in Java. Like in Linux we use the below command to find a file : find / -iname or find . -iname Is there a sim Stack Overflow I need a way to obtain the absolute path of all these .java files. java linux command. Share. Follow asked Jun 22, 2015 at 7:24. Code sampleUnix4jCommandBuilder unix4j = Unix4j.builder();List testClasses = unix4j.find(«./src/test/java/», «*.java»).toStringList();for(String path: testClasses)Feedback

Читайте также:  Linux открыть cd rom

Linux find Command

The find command is useful for locating files within a directory based on specific criteria such as permissions, user ownership, modification dates and times, sizes, and other conditions. With this command, users can generate a list of files that meet their desired requirements.

The Linux system usually includes the find utility by default, so there is no requirement to install any extra package. It is among the most vital and widely utilized commands available on Linux.

The directory is specified using the symbols below.

For the name of the current directory.

Specify the root directory by using the forward slash symbol (/).

Examples of the find Command

Let’s take a look at some instances where the find command is used.

  • Find files by name
  • Find files by type
  • Find newer files
  • Find and delete a file
  • Find a directory
  • Find files by modification time
  • Find files by permission
  • Find and replace files
  • Find text within multiple files
Find files by name

To find all files with the extension ‘.txt’, use the command below for a comprehensive search.

The command mentioned above will display a list of all text files found in the present working directory. Take a look at the output presented below.

Linux Find

The find command has listed all files that have the ‘.txt’ extension in the output above.

Finding files by type

To indicate the type of the file, the parameter ‘-type’ is utilized.

The following are a few examples of file types:

  • f: regular file
  • d: directory
  • l: symbolic links
  • c: character devices
  • b: block devices

Consider the below command:

The command mentioned above retrieves a list of directories that have the ‘.bak’ extension. The output below demonstrates this.

Linux Find

The displayed output shows that by using the command «find . -type d -name «*.bak», all directories that have the extension ‘.bak’ at the end of their name are being shown.

Find newer files

The ‘-newer’ option enables the search for files that are more recent than the specified file. Take, for instance, the command below:

The command mentioned earlier will show a list of files that are more recent than ‘msg.txt’ in the current working directory. Take a look at the output displayed below.

Linux Find

According to the output shown, the ‘msg.txt’ file is older than all the other files listed.

Find and delete a file

To delete a particular file, one can utilize the ‘-delete’ option. However, it is crucial to exercise caution as there is no undo option available once the command has been executed. For instance, take a look at the following command:

find . -name Demo.txt -delete

After executing the given command, which removes the file named ‘Demo.txt’ from the present working directory, refer to the following result.

Linux Find

Find a directory

The command below demonstrates the usage of the ‘-d’ option to locate a directory.

find . type -depth -name Newdirectory

The command mentioned above will locate the directory named ‘Newdirectory’. Please refer to the following output as an example.

Linux Find

Find files by modification time

To locate files based on their modification, use the ‘-mtime’ parameter, which takes a specified number of days. The number can be either positive or negative, with negative values indicating a range of time less than the specified days. For instance, -1 represents the previous day, while +1 denotes any time beyond a day. For example, see the command below:

find ./Newdirectory -mtime -1

The command mentioned above searches for files that were modified in the past 24 hours. Here is an example output to consider:

Читайте также:  Linux mint source repository

Linux Find

Find files by permission

To locate files based on permissions, use the ‘-perm’ option while running the find command. Just provide the necessary value after the ‘-perm’ option. For instance, consider the following command:

The command mentioned above will display the files in the designated directory that are accessible for reading, writing, and executing by all.

Find and replace files

In order to locate and substitute files, we need to merge the find and sed commands. To execute operations on files, we can make use of the ‘exec’ option along with the find command. Take a look at the command given below:

find ./Newdirectory -type f -exec sed -i 's/find/replace/g' <> \;

The specified occurrence will be replaced as shown in the output below, resulting from the command given above.

Linux Find

Find text within multiple files

Another way to search for text in multiple files is to combine the find command with the grep command. Here is an example command:

find ./Newdirectory -type f -name "*.txt" -exec grep 'demo' <> \;

The command mentioned earlier will search for lines that contain the word ‘demo’ in all text files located within the ‘Newdirectory’ directory. Here is an example of the resulting output.

Linux Find

Based on the output provided, it is evident that the displayed lines contain the word ‘demo’.

Java file path in Linux, File homedir = new File (System.getProperty («user.home»)); File fileToRead = new File (homedir, «java/ex.txt»); Share. Improve this answer. edited Oct 18, 2018 at 14:58. answered Dec 25, 2011 at 2:47. BillRobertson42. 12.3k 4 39 56. 4. If porting to any other operating system, I suggest swapping out the «/» in the path for …

Find command in linux

This article will focus on the Linux find command, which is a crucial and extensively employed command in Unix and Linux operating systems. It enables users to locate and retrieve a list of files and directories based on specific conditions specified by the user.

The Find command enables you to search for files based on various conditions, such as permissions, users, groups, file type, date, size, and other criteria. Additionally, the Find command conducts a recursive search that includes all subdirectories.

Syntax

Let us explore the optional choices available after executing the Find command.

By typing «$ find» and hitting enter, you can view the pathnames of all files in the current directory and subdirectories. The same result can be achieved by typing «$ find .» and hitting enter.

You can also do this by using

The ‘find’ command is case sensitive by default, but if you wish to perform a case-insensitive search, you need to specify it explicitly.

The current directory will be scanned for files that correspond to variations of the name «arpit» such as «ARPIT» and «Arpit».

Searching for Files and Directories Only

One way to locate directories named arpit is by using the following method.

The search will specifically target files named «arpit» in both the current directory and its subdirectories, without considering case sensitivity.

Читайте также:  Проверить содержимое файлов linux

The find command also allows the utilization of wild cards, as an example.

The search will cover both the present directory and its subfolders to locate files that have the .txt extension.

Search based on File Permission

Using the find command enables you to target a particular permission, such as search files based.

Your current directory will show all files that have been granted permission 777.

Search for files that are modified at some specific time/day

To find files that have been modified within the past 24 hours, use mtime in your search.

To find recently modified files, simply look for those that have been changed within the past minute.

To locate files that have been modified in a timeframe of over 2 minutes but under 5 minutes, you may conduct a search.

Search based on User

To explore directories and sub-directories for arpit’s files, use this command.

Search based on File size

To find all files of size 10MB , use.

With just one command, it’s possible to locate and eliminate files that are 50MB in size.

To gain additional knowledge regarding the Find command, input $ man find into your Linux terminal.

This concludes our discussion on the Find command in Linux.

Was this post helpful?

Java command not found on Linux, In Oracle Enterprise Linux when I type java I am getting . bash: java: command not found I have installed Java 1.6 and I have the following. sudo update-alternatives —config java There are 2 programs which provide ‘java’.

Источник

grep + FIND all files that are jar files and ended with jar [closed]

Why are you using su ? What is hdfs ? Basically, why aren’t you just running ls /home/test/jt/*.jar ?

3 Answers 3

* is excessful here. In regular expressions, * is used to specify that the previous symbol can appear any number of times, including 0. Using it without a preceding symbol is pointless, so in this special case grep looks for the * symbol itself (in general case you need to precede it with \ for this purpose).

. has a special meaning of matching any symbol too, so if you want to cover the situations where there are some bogus extensions like .djar , or extensionless files ending with jar , you need to precede it with \ too.

So, in short, you need just:

su -l hdfs -c " hdfs dfs -ls /home/test/jt" | grep "\.jar$" 

If you don’t care about them, why specify them in the expression? Also, in RE, * is meaningless without a character class before it; * means «zero or more of the previous match».

. at least with GNU grep, BRE treats a leading * a literal, whereas ERE treats it as zero or more occurrences of a leading empty string (which matches everything)

@yael grep searches for a substring by default. It doesn’t care about other symbols if there is enough consequent symbols to match the given pattern. If you want it to match the whole line, the expression should both start with ^ and end with $ . In this case, if you want to make sure that file has an actual name besides of the extension, you can check it with [^/]\.jar$ , which means that any symbol except of directory separator ( / ) can appear before the dot. [^ symbol ] is an inversion operator.

Источник

Оцените статью
Adblock
detector