I have arraylist of filenames (java) and I want to delete these files using rm but it is time consuming can I do batching using xargs or something else which can help to delete files faster. Answer Don’t use rm. Use Java. As others have pointed out, spawning a process is much slower than doing it in your program. Also,
Tag: bash
Program to find from where the program is called
The requirement is very simple, I want to write a simple hello world program or anything so the program knows about its execution parent. For eg. Since I am from a Java background I will give a Java example. I want to write a jar that runs and outputs the following: Running from command line: but when running from myscript.sh:
Passing shell arguments to java
I want to pass input to java in a Bash shell: This is my Java code: The result is: Answer This is more of a shell programming problem. You need to write: This will convert the output of echo to parameters. This will work as along as the output of your program is simple (e.g., a short list of words).
Inconsisent S3 parameter validation error when running bash script in Ubuntu WSL
I’m experimenting with AWS Lambda by following along with the instructions here: https://github.com/awsdocs/aws-lambda-developer-guide/tree/main/sample-apps/java-basic. Part of the setup instructions require running this script (2-deploy.sh): When I run the script in WSL I get a parameter validation error: However, when I manually run the last two lines of the file with the debug output it works correctly: Why does this fail when
Unix shells: How to ensure command works against most common shells?
I have some java code which uses jsch to connect to our unix servers and run below command. ls -lt /tempdirectory/ grep -v ‘^do | grep “$”(date ‘+%b %e’)” | head -1 | awk ‘{print %9}’ …
Exit java program to linux command
I’m making a little tool that handles a sort of exotic device, with lots of options to manage it etc. One of them would be to scan for tty ports, find the right one then throw the user to “minicom” with some parameters for example. How can I make java completely exit while running a specific command, under certain condition,
How to run async bash command in java?
I’m trying to run an async bash command from a java file and wait for it to finish before I continue the java code execution. At this moment I’ve tried using Callable like so: and I call it like so: Thanks!!! Answer An easier way is to use Java 9+ .onExit(): If you want to block anyway, use .waitFor().
Double backslash under Linux bash
In the Linux bash to identify a Windows folder I have to use double backslash for example “java -jar myjar.jar C:\Users\username” while in the Windows command prompt does not need, just “java -jar myjar.jar C:Usersusername”, is it normal? Answer Yes, the backslash is used for newlines and special characters in bash. But since Windows uses backslashes in file paths, it
Concatenate list of paths in bash-script, with colon as separator
I have the following difficult to read script consisting of a single command: As slight readability improvement I would like to list all the paths after the -classpath in a separate variable, each aligned after the other: This way I can easier add and remove the paths, and sort them in Vim. My question is: how to join them back
How to run sed command from java code
I’m probably missing something, but I’m trying to run commandline from a java The code is as following: I’m getting the following error: The fils is exists. I’m doing ll on this file and it is exists. I’m just looking for a way to make it work from java. What am I doing wrong? Answer Pass the command as an