I’m using find to all files in directory, so I get a list of paths. However, I need only file names. i.e. I get ./dir1/dir2/file.txt and I want to get file.txt Answer In GNU find you can use -printf parameter for that, e.g.:
Tag: shell
How do I execute javascript programs from the Linux shell?
I would like to execute my javascript programs with the Rhino shell without making the first line #!/bin/sh. ‘#’ isn’t a comment character in javascript. I also don’t want to have to have a .js extension. Is this possible? I remember reading something a long while about a method of making java programs to run without an explicit interpreter. Google
Force a shell script to fflush
I was wondering if it was possible to tell bash that all calls to echo or printf should be followed up by a subsequent call to fflush() on stdout/stderr respectively? A quick and dirty solution would be to write my own printf implementation that did this and use it in lieu of either built in, but it occurred to me
Given two directory trees, how can I find out which files differ by content? [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question
What is the difference between “source script.sh” and “./script.sh”?
What is the difference between source <script> and ./<script>? Answer source script.sh runs the script within the current process, thus all variable assignments are preserved as variables even after the script finishes (and don’t have to be explicitly export’d). ./script.sh just runs the script in a subprocess, and any variables which are assigned disappear after the script is done.
How to untar all .tar.gz with shell-script?
I tried this: If the folder has one tar, it works. If the folder has many tar, I get an error. How can I do this? I have an idea to run a loop to untar, but I don’t know how to solve this problem Answer
C system function causes error ‘sh: Syntax error: “(” unexpected ‘
I wrote a simple program in C on Linux to delete all the files in a directory except one called svn like this: But when I compile and run it, the terminal says: sh: Syntax error: “(” unexpected However, when I type and run the command in the terminal directly, all things are done correctly. Any ideas? Answer The answer
BASH: how to perform arithmetic on numbers in a pipe
I am getting a stream of numbers in a pipe, and would like to perform some operations before passing them on to the next section, but I’m a little lost about how I would go about it without breaking the pipe. for example Would you have any ideas on how to make something like this work? The actual operation I
how to find whether a script run as a nohup finished or not?
I tried running a script using nohup like, When I tried I couldn’t find it there except for the grep which is being run with that string as a parameter. Am I doing it right?. Does this mean that the process has indeed finished execution? Thanks. Answer At the beginning of your shell script, write the PID to a file
Parsing result of Diff in Shell Script
I want to compare two files and see if they are the same or not in my shell script, my way is: Basically, if they are the same ${diff_output} should contain nothing and the above test would evaluate to true. But when I run my script, it says [: too many arguments On the if [….] line. Any ideas? Answer