Most terminal commands either say "invalid option" or "command not found" - command-line

Whenever I use a command line tool, it consistently says either "invalid option" or "command not found". I'm trying to run the below command
. -type f -iname \*.png -delete
Here is the terminal response:
-bash: .: -t: invalid option
.: usage: . filename [arguments]
Don't know if this helps but when I run /bin/echo $PATH, this is what appears:
/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
Can anyone help?
Thanks
A

It looks like you missed out the actual command, find, and only had the arguments. Your command line should look like :
find . -type f -iname \*.png -delete
To find all files in the current directory with the png extension and delete them.

Related

Universal ctags with emacs

Sorry I am trying to configure ctags with emacs but I am in trouble.
I compiled global with this configure:
./configure --with-universal-ctags=/usr/local/bin/ctags
and I executed make && make install.
Then I changed the default target in the file .globalrc from native to new-ctags.
Finally I executed ggtags-create-tags within emacs.
Unfortunately I got the error
‘gtags’ non-zero exit: gtags: execvp failed.
gtags: unexpected EOF.
Can anyone help me, thanks
Using universal ctags is as simple as:
Run over a project (-R is to walk the project recursively, and -e is to use Emacs-compatible syntax):
$ ctags -eR
Alternatively if you like to only include files with certain extensions, you can use -a (append, creates a file if doesn't exist) option with find utility, like:
$ find -name "*.cpp" -print -or -name "*.h" -print -or -name "*.hxx" -print -or -name "*.cxx" -print | xargs ctags -ea
Run M-x visit-tags-table in Emacs, and navigate to the created TAGS file.

Escape the current file name "{}" of shell find -exec in the subcommand result "$()"?

I want to run something like:
find . -type files -exec echo "touch -cmd '"$(date --utc -r '{}' +"%Y-%m-%d %H:%M:%S.%N +0000")"' "$(ls --quoting-style=shell '{}')
It doesn't seem to work since "{}" doesn't seem to be expanded in the $(). How could I do to make it work right?
Simplify your problem.
Write a shell script, and then get the shell script working. Then execute your shell script using find.
find . -type files -exec myScript '{}'

Error when starting terminal: "-bash: QSTK/local.sh: No such file or directory"

"-bash: QSTK/local.sh: No such file or directory"
I've been getting this error for over a year. Any idea how I'd go about fixing it? None of the similar suggestions on SO solve this problem.
In response to Olivier's suggestion:
When I run
grep QSTK/local\.sh' /etc/* ~/.??*
I get this output:
grep: /etc/aliases.db: Permission denied
grep: /etc/kcpassword: Permission denied
grep: /etc/krb5.keytab: Permission denied
grep: /etc/master.passwd: Permission denied
grep: /etc/sudoers: Permission denied
/Users/DylanRichards/.bash_profile:source QSTK/local.sh
/Users/DylanRichards/.bash_profile.pysave:source QSTK/local.sh
/Users/DylanRichards/.profile:source QSTK/local.sh
Dylan-Richardss-MacBook-Pro:~ DylanRichards$
When I type
-type f -size -200 -print0 2>/dev/null | xargs -0 grep 'QSTK/local\.sh' /dev/null
It returns nothing. The error is still occurring at the start of my terminal.
following your answers to my questions:
to look for the script responsible, first in the shell's startup scripts:
grep 'QSTK/local\.sh' /etc/* ~/.??*
and if it is not enough:
find / -type f -size -200 -print0 2>/dev/null | xargs -0 grep 'QSTK/local\.sh' /dev/null
(just copy/paste this, while loggued as root in a terminal window, so that you can grep most files)
(the additional "/dev/null" is there to force grep to display the matching file's name even if there is only 1 parameter, which cuold happen if xargs split in a way that make the last file alone)
(I only check files of less than around 100kb [100 x 512 bytes], as anything bigger is most probably a binary and not a script...)
Note that this could fail if "QSTK" is in a variable, or is contructed...
But it could work. Try it and let us know if it's enough for you to correct the mistake, or provide additionnal informations if you don't know how to proceed.
=== update =====================
after you posted:
/Users/DylanRichards/.bash_profile:source QSTK/local.sh
/Users/DylanRichards/.bash_profile.pysave:source QSTK/local.sh
/Users/DylanRichards/.profile:source QSTK/local.sh
I'd recommend you
1) check that you have, indeed, a /Users/DylanRichards/QSTK/local.sh file.
ls -l /Users/DylanRichards/QSTK/local.sh
2) check its content and ensure you are OK to execute it each time you log-on
more /Users/DylanRichards/QSTK/local.sh
3) if it is OK to execute it (ie, if it's really something you really need/want to execute at each login) then
chmod +x /Users/DylanRichards/QSTK/local.sh
ls -al /Users/DylanRichards/QSTK/local.sh
You can, if you want, post the info of the ls -l /Users/DylanRichards/QSTK/local.sh
But as for its content, please verify it (do not post it here if it could contain important security information...). (If however you feel it's safe to show it to us, you can post the : cat /Users/DylanRichards/QSTK/local.sh (unless it's more than 20 lines...)
Finally, in case you do NOT find the file in /Users/DylanRichards/QSTK/local.sh :
find / -type f -name "local.sh" -print 2>/dev/null | grep QSTK/local.sh
will show you where it is. Once again, check its content, and if it seems fine (and needed) edit the ~/.bash_profile and ~/.profile with the correct path to the correct file.
open .bashrc file using a text editor as follows
$gedit .bashrc
In the text file look for the path .QSTK/local.sh probably in the last line you may something similar to
VIRTUAL_ENV_DISABLE_PROMPT=1 source /home/QSTK/local.sh
comment out the line adding a # in the beginning of the line and then save
Try it out

Assistance with the "find" and "grep" command

I'm looking for help with a one-liner that I can run from the Mac OS X terminal. I use MAMP for web development on my Mac. I have a lot of CakePHP projects in my "/Applications/MAMP/htdocs" directory. For the sake of simplicity, let's just say that I had two CakePHP projects and that this was the output of the find /Applications/MAMP/htdocs -type d -iname Controller* command:
/Applications/MAMP/htdocs/my_cake1.3_project/app/controllers
/Applications/MAMP/htdocs/my_cake1.3_project/app/tests/cases/controllers
/Applications/MAMP/htdocs/my_cake1.3_project/cake/console/templates/skel/controllers
/Applications/MAMP/htdocs/my_cake1.3_project/cake/console/templates/skel/tests/cases/controllers
/Applications/MAMP/htdocs/my_cake1.3_project/cake/libs/controller
/Applications/MAMP/htdocs/my_cake1.3_project/cake/tests/cases/libs/controller
/Applications/MAMP/htdocs/my_cake1.3_project/cake/tests/test_app/controllers
/Applications/MAMP/htdocs/my_cake1.3_project/cake/tests/test_app/plugins/test_plugin/controllers
/Applications/MAMP/htdocs/my_cake2_project/app/Controller
/Applications/MAMP/htdocs/my_cake2_project/app/Test/Case/Controller
/Applications/MAMP/htdocs/my_cake2_project/lib/Cake/Console/Templates/skel/Controller
/Applications/MAMP/htdocs/my_cake2_project/lib/Cake/Console/Templates/skel/Test/Case/Controller
/Applications/MAMP/htdocs/my_cake2_project/lib/Cake/Controller
/Applications/MAMP/htdocs/my_cake2_project/lib/Cake/Test/Case/Controller
/Applications/MAMP/htdocs/my_cake2_project/lib/Cake/Test/test_app/Controller
/Applications/MAMP/htdocs/my_cake2_project/lib/Cake/Test/test_app/Plugin/TestPlugin/Controller
Now, sometimes I want to find a piece of code that I know I used in one of my CakePHP projects' controllers, but I can't remember which project it was, so I want to search all of them. I don't want to waste time searching in the "app/tests/cases/controllers" folder or any of the ones within "cake/", though. The find /Applications/MAMP/htdocs -type d -iname Controller* | grep -i /app/Controller command gives me the list of folders I want to search in:
/Applications/MAMP/htdocs/my_cake1.3_project/app/controllers
/Applications/MAMP/htdocs/my_cake2_project/app/Controller
I just need to find a way to take that output, add a slash and asterisk (/*) to the end of each line, and pipe each line to the grep -il "string to search for" command. Any help would be appreciated. Thanks!
solution 1
maybe you want to check two options of find command: (i)path and regex
with them you could narrow your find result and pass found files to your grep -il "searchString" for example by |xargs . it looks like:
find /Applications/MAMP/htdocs -type f -ipath "*/app/Controller/*.php"
| xargs grep -il 'foo'
with -regex would be more flexiable.
solution 2
however if you really really want to :
find a way to take that output, add a slash and asterisk (/*) to the
end of each line, and pipe each line to the grep -il "string to search
for" command.
(btw, here "pipe" won't work.)
you could do this:
find .(your original find).. |grep -i "/app/Controller"
|sed -r 's#^(.*)$#grep -il "foo" \1/*#g'|sh
the trick was done by the sed....|sh. the sed line will pick the result of your previous grep, add grep command and options :(grep -il "foo") and append "/*" in order to construct a complete grep command. finally pipe to sh, to execute it.
Have you tried this?
find /Applications/MAMP/htdocs -type d -iname Controller*
-exec grep -il "string to search for" {} /;

Finding and opening a file with vim in a single command alias in tcsh

I want to make an alias which would work like this:
vf hello.c would execute a find command to search for hello.c and open it in the vim editor.
What is the best way to do it? I've tried the following (doesn't work):
alias vf "find -name $* -exec vi {} \;"
alias vf "vi `find -name $*`"
Can anyone help ?
I found the answer after a trial n error:
Use alias vf "find -name \!:1 -exec vi {} \;"