fswatch not running script, reports as not found - xargs

I have a script in ~/bin called go_refresh. It's definitely there. I run fswatch like so:
fswatch -o /usr/local/var/www/wp_sites/test/wp-content/themes/test/style.css | xargs -n1 -I{} ~/bin/go_refresh
When I change the file, I get this error once:
xargs: /Users/my_dir/bin/go_refresh: No such file or directory
And the script doesn't run.

Related

Crontab doesn't executed script but, manually it executed. Mac os X

I have crontab file like this.
#!/bin/sh
PATH=/Users/name/.rvm/gems/ruby-2.6.3#rails-6.0.0.2/bin:/Users/name/.rvm/gems/ruby-2.6.3#global/bin:/Users/name/.rvm/rubies/ruby-2.6.3/bin:/Users/name/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/name/.rvm/bin
cd ~/Documents/mydirectory/
bash -c 'ls -1t | tail -n +7 | xargs rm -f'
ls -1t | tail -n +7 | xargs rm -f # this is not working either.
I want to delete files in the directory if number of files is more than 7.
I set to PATH as well since it's a common gotcha.
If I run the script manually it works.
What is the problem?
My Problem was. crsutil
It should be disabled.

How to pass path to xargs command in Linux

I have the following code, which removes old files in a directory based on their timestamps:
ls -tp | grep -v '/$' | tail -n +2 | xargs -I {} rm -- {}
I am trying to make an executable script out of this and I don't want to cd into the directory where the above command should be run, but rather simply pass the path e.g. /tmp/backups/ to it.
How would I do this? Attaching the path directly after each command ls, grep, tail, xargs and rm ?
Assuming that your path is the first parameter of your script, you could do a
cd "${1:-/tmp/backups}" # Use the parameter, supply default if none
# Do your cleanup here
If you have afterwards more stuff to do in the original working directory, just do a
cd - >/dev/null
# Do what ever you need to do in the original working directory
The sole purpose of the redirection of stdout into the bit bucket is, because cd - by default prints to stdout the directory it changes into.

How to copy files found with grep on OSX

I'm wanting to copy files I've found with grep on an OSX system, where the cp command doesn't have a -t option.
A previous posts' solution for doing something like this relied on the -t flag in cp. However, like that poster, I want to take the file list I receive from grep and then execute a command over it, something like:
grep -lr "foo" --include=*.txt * 2>/dev/null | xargs cp -t /path/to/targetdir
Less efficient than cp -t, but this works:
grep -lr "foo" --include=*.txt * 2>/dev/null |
xargs -I{} cp "{}" /path/to/targetdir
Explanation:
For filenames | xargs cp -t destination, xargs changes the incoming filenames into this format:
cp -t destination filename1 ... filenameN
i.e., it only runs cp once (actually, once for every few thousand filenames -- xargs breaks the command line up if it would be too long for the shell).
For filenames | xargs -I{} cp "{}" destination, on the other hand, xargs changes the incoming filenames into this format:
cp "filename1" destination
...
cp "filenameN" destination
i.e., it runs cp once for each incoming filename, which is much slower. For a large number (e.g., >10k) of very small (e.g., <10k) files, I'd guess it could even be thousands of times slower. But it does work :)
PS: Another popular technique is use find's exec function instead of xargs, e.g., https://stackoverflow.com/a/5241677/1563960
Yet another option is, if you have admin privileges or can persuade your sysadmin, to install the coreutils package as suggested here, and follow the steps but for cp rather than ls.

Use fswatch with imgcat

I am trying to automatically display an image in the terminal whenever a file is updated or added to a directory. I can manually do this with imgcat in iTerm2, and I can get fswatch to report correctly when a file is changed. But I can't get them to play together. I thought this would work but it reports xargs: imgcat: No such file or directory
fswatch *.png | xargs -n1 -I{} imgcat

Opening Solution file in Cygwin / Bash

I'm trying to set up a simple bash alias that will open a solution file in the current directory via cygstart
I'm unsuccessfully trying something like
ls | grep '.sln' | cygstart $0
I'm no expert in bash commands and was wondering what the correct command is?
You want to try:
ls *.sln | xargs cygstart
or better:
find . -iname "*.sln" -print | xargs cygstart

Resources