Why do .sh files have an * next to them?
It means that the file is executable.
Reference: General Output Formatting
The * means that the file is executable
Related
I execute a sh file using command ./abc.sh abc_config
How do we get this done via cron ? for a single command i usually do
5 0 * * * /test/abc.sh
But for ./abc.sh abc_config I am a little confused
One option could be to store the script and it's argument in another script and run that instead?
5 0 * * * /test/run_abc.sh
Contents of run_abc.sh
./abc.sh abc_config
You should possibly include paths and a "shebang" matching whatever shell you want to use, ie:
#!/usr/bin/env bash
/path-to-dir-where-program-is/abc.sh abc_config
My question is basically the same as this previous question...
How to change all occurrences of a word in all files in a directory
...except I'm trying to change the reference to a header file.
For example,I'm trying to change [lessthan]abc/filename.h[greaterthan] to "filename.h", is this even possible using the same syntax, or should I be looking to whip myself up a quick program to do it?
Thanks
You can do it easily with sed:
sed -i -e 's,<abc/filename.h>,"filename.h",' *
I'm trying to execute a R script which has spaces in the path leading to it. It fails with path not found error. My command looks like this..
Rscript ../A/B C/test.R
I've tried
Rscript "`../A/B C/test.R`"
Rscript "../A/B C/test.R"
Doesn't work. What's going wrong here?
First let's try the obvious, escape the space:
Rscript "../A/B\ C/test.R"
If that doesn't work, cd inside the folder and try calling it from there:
cd A/B\ C/ && Rscript test.r
(Assuming you're in the parent folder)
If is still not working.. maybe is something inside the script.. What do you have in it?
R has problem sometimes managing spaces with single escape characters, so, if -let's say-, inside your script you have:
source("x.r")
And the FULL PATH of x.r has spaces in its name (like being in the same folder as the file in your example..), it can fail due to not finding the file called from inside r.
Then, change the paths INSIDE the script to have double escapes at the spaces
/A/B C/ -> /A/B\\ C/
And try again the previous options i posted.
Tell us what happens!
Make sure you are running your line of code from the Unix shell.
There may be an error in your directory name or file itself. As a test case, you may try the following:
Rscript "/directory/test A/rnorm.R"
rnorm.R being:
x <- rnorm(200, 10, 4)
print(x)
This basically should print the numbers to your Shell.
I'm trying to create a simple crontab that creates a file called log.txt every minute by populating it with a simple command's output. Right now this is what I've put into my crontab:
* * * * * (/usr/bin/ls <pathToRandomDirectory) > log.txt
By my understanding, the 5 asterisks correspond to "every minute". But when I run this the log.txt file is not being created. Is there something I'm missing here?
ALSO, if I didn't want to have an email sent to me whenever the job is created I found that I need to put the line:
>/dev/null 2>&1
Somewhere in my crontab file. Where exactly does this go? At the end of the command or on a separate line?
You have to put an absolute path for log.txt. Otherwise, it will be created in /.
Also, >/dev/null 2>&1 has to be at the end of the sentence. If you want the 2 (meaning the errors) to be dismissed, just write 2>/dev/null.
Then, your final cronjob would be like this:
* * * * * /usr/bin/ls pathToRandomDirectory > /pathToRandomDirectory/log.txt 2>/dev/null
What exactly should be in that file? This creates a new file with the text "something" in it every minute:
* * * * * echo "something" > /path/to/your/file.txt
I had some problems with crontab especially when I created a new crontab config - my problem was that I had to insert an empty line at the end of the crontab - some systems need it to work correctly. So if you do
$ crontab -l
the output should be a list of your cron jobs on each line and then an empty line at the end.
Try it if it works for you. Sorry, but I'm not sure about the email, but I dont think that you need to put lines like that to crontab, play around with the configuration - it shouldn't send you any emails by default.
I am trying to rename multiple files with extension xyz[n] to extension xyz
example :
mv *.xyz[1] to *.xyz
but the error is coming as - " *.xyz No such file or directory"
Don't know if mv can directly work using * but this would work
find ./ -name "*.xyz\[*\]" | while read line
do
mv "$line" ${line%.*}.xyz
done
Let's say we have some files as shown below.Now i want remove the part -(ab...) from those files.
> ls -1 foo*
foo-bar-(ab-4529111094).txt
foo-bar-foo-bar-(ab-189534).txt
foo-bar-foo-bar-bar-(ab-24937932201).txt
So the expected file names would be :
> ls -1 foo*
foo-bar-foo-bar-bar.txt
foo-bar-foo-bar.txt
foo-bar.txt
>
Below is a simple way to do it.
> ls -1 | nawk '/foo-bar-/{old=$0;gsub(/-\(.*\)/,"",$0);system("mv \""old"\" "$0)}'
for detailed explanation check here
Here is another way using the automated tools of StringSolver. Let us say your first file is named abc.xyz[1] a second named def.xyz[1] and a third named ghi.jpg (not the same extension as the previous two).
First, filter the files you want by giving examples (ok and notok are any words such that the first describes the accepted files):
filter abc.xyz[1] ok def.xyz[1] ok ghi.jpg notok
Then perform the move with the filter it created:
mv abc.xyz[1] abc.xyz
mv --filter --all
The second line generalizes the first transformation on all files ending with .xyz[1].
The last two lines can also be abbreviated in just one, which performs the moves and immediately generalizes it:
mv --filter --all abc.xyz[1] abc.xyz
DISCLAIMER: I am a co-author of this work for academic purposes. Other examples are available on youtube.
I think mv can't operate on multiple files directly without loop.
Use rename command instead. it uses regular expressions but easy to use once mastered and more powerful.
rename 's/^text-to-replace/new-text-you-want/' text-to-replace*
e.g to rename all .jar files in a directory to .jar_bak
rename 's/^jar/jar_bak/' jar*