I have a perl script that converts a file to json format and writes the output to a separate directory. It accepts 2 parameters, filename and output directory. The script needs to be run on multiple files that end with a particular extension such as .abc.  I want to locate every file in a particular directory with extension .abc and run my script against it.  I am trying to run from the command line  find "path to directory" -name '*.abc' -exec ./ConvertFile {} "output_directory"   The command returns find: missing argument to '-exec'  I am new to both perl and shell scripting. I could run the script on each individual file.  However, there can be tens of files in any given directory and they will need to be converted on the fly because the original files change often.  Can anyone tell me what is wrong with my command line entry? Thanks
61685
I'd like to find the files in the current directory that contain the text "chrome".  $ find . -exec grep chrome find: missing argument to `-exec'   What am I doing wrong?
67692
INPUT_FILE=`ls -rt $MY_DIR/FILE.*.xml | head -1 | xargs basename`   I wanted to execute the second command (head -1) only if the first command is successful. How do I improve this command?
8857
Does the command pwd in a shell script output the directory the shell script is in?
44386
I have a directory filled with various files, differently named (i.e. not named with a specific pattern) and with different extensions, and I want to put each file in a newly created subdirectory named after each file; what's the best way to accomplish that from the command line under Linux? This sounds a bit confusing, let me make and example: let's call a random file in the directory ./filename.ext, I'd like to put it in a subdirectory called ./filename so that effectively the new path will be ./filename/filename.ext.  I did some trials with the following steps:   I've created some test files, from file-1.txt to file-9.txt, inside a test directory with for num in {1..9}; do touch file-$num.txt; done  I've created a directory named after each filename with for name in $(eval ls | cut -b 1-6); do mkdir $name; done I've moved the source files in their respective directories with for name in $(eval ls | grep -e ".txt" | cut -b 1-6); do mv $name.txt $name/$name.txt; done   As you can see, this solution works, but its huge drawback is that it works just in this case, with files of that extact filename lenght and with that particular extension. If I have some files with different names and extensions, this would be of no use at all. The use of cut command is not the ideal solution here, I suppose, but I haven't found anything better at the moment.  As a bonus, it would be cool to find a way to create the subdirs automatically when moving/renaming the files, without having to use mkdir previously (so when I ls to actually rename, I don't have to worry about excluding the newly created directories); but in the end this is a secondary problem.
8430
I'm not well versed in shell scripting but I imagine this to be a painfully easy fix but its eluding me.  I need to copy the contents of a directory excluding a number of files. I have a command that works when I enter it into the terminal, but when its run in a shell script it fails with a syntax error or just doesn't work.   The command in question is:  cp -r path/to/!(dir1|dir2|dir3) destination   Any help would be greatly appreciated!
112793
I am writing a bash script to automate several actions:  #!/bin/bash           echo "Hello, World" NAME="${1}" PATH="${2}" echo $NAME echo $PATH eval "ls"   I am going to call ls, ffmpeg and a lot of other commands.  However running my script gives me the following error:  /var/www/html# ./life.sh test midhand.mp4 + ./life.sh test midhand.mp4 Hello, World test midhand.mp4 ./life.sh: line 9: ls: command not found   How come? why not found? Maybe I should import a directory with scripts?
112657
I know I can solve this problem several ways, but I'm wondering if there is a way to do it using only bash built-ins, and if not, what is the most efficient way to do it.  I have a file with contents like  AAA B C DDD FOO BAR   by which I only mean it has several lines and each line may or may not have spaces.  I want to run a command like  cmd AAA "B C DDD" "FOO BAR"   If I use cmd $(&lt; file) I get  cmd AAA B C DDD FOO BAR   and if I use cmd "$(&lt; file)" I get  cmd "AAA B C DDD FOO BAR"   How do I get each line treated a exactly one parameter?
48411
To create a playlist for all of the music in a folder, I am using the following command in bash:  ls &gt; list.txt   I would like to use the result of the pwd command for the name of the playlist.  Something like:  ls &gt; ${pwd}.txt   That doesn't work though - can anyone tell me what syntax I need to use to do something like this?  Edit: As mentioned in the comments pwd will end up giving an absolute path, so my playlist will end up being named .txt in some directory - d'oh! So I'll have to trim the path. Thanks for spotting that - I would probably have spent ages wondering where my files went!
34780
I want to know which files have the string $Id$.  grep \$Id\$  my_dir/mylist_of_files   returns 0 occurrences.  I discovered that I have to use  grep \$Id$ my_dir/mylist_of_files  Then I see that the $Id is colored in the output, i.e. it has been matched.  How could I match the second $ and why doesn't \$Id\$ work.  It doesn't matter if the second $ is the last character or not.  I use grep 2.9.    Before posting my question, I used google...       To search for a $ (dollar sign) in the file named test2, enter:      grep \\$ test2      The \\ (double backslash) characters are necessary in order   to force the shell to pass a \$ (single backslash, dollar sign) to the   grep command. The \ (single backslash) character tells the grep   command to treat the following character (in this example the $) as a   literal character rather than an expression character. Use the fgrep   command to avoid the necessity of using escape characters such as the   backslash.   but I don't understand why grep \$Id works and why grep \\$Id\\$ doesn't.  I'm a little bit confused...
10724
Here is my script (to find the files that contain a specified pattern):  find . -type f \     -exec awk -v vawk="$1" '/'"$vawk"'/ {c++} c&gt;0 { print ARGV[1]; exit 0 } END { if (! c) {exit 1}}' \{\} \;   I would like to use my script with an argument §:  MyScript.sh pattern   My problem is that I don't manage to put the $1 variable in awk.  When I try to debug my script  bash -x MyScript.sh pattern   Here is the output :  + find . -type f -exec awk -v vawk=pattern '// {c++} c&gt;0 {print ARGV[1] ; exit 0 } END { if (! c) {exit 1}}' '{}' ';'   The $vawk variable seems to be empty.  Any idea?
18704
I am using locate command.   I want to find all files that end with specific extension and have specific keyword in their name.  For example I want to find image such as this:          myImageFromSummer.jpg      I want to search by keyword "Summer" and extension ".jpg".  How would command look like for this task?
28159
I just asked a  related to how I can count the files of particular extension. Now I want to cp these files to a new dir.  I am trying,  cp *.prj ../prjshp/   and   cp * | grep '\.prj$' ../prjshp/   but they are giving the same error,     bash: /bin/cp: Argument list too long   How do I copy them?
72412
I have to deal with a large number of files nested inside of directories (one file per directory), resembling something like this:  fred/result.txt john/result.txt mary/result.txt ...   I am currently using the following command to process each of those files:  find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c \"cd '{}' &amp;&amp; processResult result.txt\" \;   I am looking for something I can add into the end of this command that will change the filenames to fred.txt, etc. and then later move the file into the parent directory to eliminate the extra layer of directories.  What would be the best way to do this?
111306
I want to remove certain files using find and -exec. But unlikely bash tells me, that I'm "missing" some argument.   find . -name *.png -exec rm {} /;   what do I miss?  same "missing argument" return for my attempt to rename some files:  find . -name ic_launcher.png -exec mv {} other_name.png /;   Can somebody tell me, what bash does miss, and why this command isn't successful?
72552
How do I work recursively through a directory tree and execute a specific command on each file, and output the path, filename, extension, filesize and some other specific text to a single file in bash.
119618
I'm writing script is ksh. Need to find all directory names directly under the current directory which contain only files, not subdirectories.  I know that I could use ls -alR and recursively parse output for the first letter in the first field (d for a directory). I think awk is the best way to parse and find.   For example, a simple ls -al output in the current directory:     drwxr-xr-x  22 af      staff    748 18 Mar 22:21 .    drwxr-xr-x   5 root    admin    170 17 Mar 18:03 ..    -rw-------   1 af      staff      3 17 Mar 16:37 .CFUserTextEncoding    drwxr-xr-x   5 af      staff    170 17 Mar 17:12 Public    drwxr-xr-x   9 af      staff    306 18 Mar 17:40 Sites    -rw-------   1 af      staff      3 17 Mar 16:37 textd    …   There are 2 directories in this output: Public and Sites. The directory Public doesn't contain subdirectories, but Sites does. There are 3 subdirectories in Sites. So I need to echo only the directories which don't contain directories in them. In my case, this is only Sites.
100567
This is from . It's about executing a Perl script.     Finally, if you are unfortunate enough to be on an ancient Unix system   that doesn’t support the magic #! line, or if the path to your   interpreter is longer than 32 characters (a built-in limit on many   systems), you may be able to work around it like this:   #!/bin/sh -- # perl, to stop looping eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0;   Can you explain step by step what's going on here? I'm trying to make it work or encompass, but to no avail.  At execution of just the above, I'm getting this:  /bin/sh: 0: Illegal option --