4
votes
2answers
53 views

Script to loop through folders with numeric names

I am working on a bash script to compress the images in my Wordpress folders. The wordpress folder structure is as follows: > wp-content/uploads/2014/01/filename.jpg > ...
3
votes
3answers
165 views

How to move the first x files

I have this huge folder with thousands of unordered files. Is it feasible to move the first 5000s to a subfolder via the mv command? For now I move files with mv *some_pattern* ./subfolder1/ ...
3
votes
3answers
224 views

copying specific files in directory

I am trying to copy some of the files in a directory. The directory contains following files my current directory is ~/certificate/ drwxrwxr-x 2 ubuntu ubuntu 4096 Oct 16 11:58 apache -rw-rw-r-- ...
0
votes
4answers
231 views

How to rotate all images in a directory with imagemagic?

I want to rotate all the images in a directory that match a pattern. So far I have: for file in `ls /tmp/p/DSC*.JPG`; do convert $file -rotate 90 file+'_rotated'.JPG done but that gives no ...
2
votes
4answers
734 views

How do I select files in a bash script that do not have an extension?

Let's say I have files xinitrc, alphabetsoup, ieat.pie in the current directory. Need a bash script to select only xinitrc and alphabetsoup.
2
votes
4answers
572 views

Shell script to check for the presence of one or more files with a specific extension?

I want to write a script to find a file with specific extension.this much i have done: #!/bin/bash file="/home/Savio/Dsktop/check/*.csv" file1="/home/Savio/check/*.txt" if [[ -f "$file" && -f ...
2
votes
3answers
380 views

Very strange behavior with grep and IFS

I'm having trouble using grep, the returned results are "n-empty", I mean without the 'n' character... This is the script sample : OLDIFS=$IFS IFS="\\n" i=$(grep -ril $1 *) echo $i IFS=$OLDIFS ...
1
vote
3answers
256 views

Reading a directory in shell script

I want to read a numbered directory which is under a path, into a variable in shell script. The paths are something like this: .../releases/R1/... .../releases/R2/... .../releases/R3/... Each time ...
1
vote
1answer
123 views

Copy files excluding x,y,z causing error in shell script

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 ...
15
votes
3answers
663 views

What is the difference between [[ $a == z* ]] and [ $a == z* ]?

Is there is any difference between these two. [[ $a == z* ]] and [ $a == z* ] Can I have an example where they would have different outputs? Furthermore, how does the working of [[ ]] differs ...
2
votes
1answer
383 views

Extended file globbing not working with cat inside bash script

When, in my terminal, I type cat ~/my/+(a|b)/doc It reads ok from both ~/my/a/doc and ~/my/b/doc, but when I put that command in a bash script: #!/bin/bash cat ~/my/'+(a|b)'/doc I get the error: ...
2
votes
2answers
612 views

zsh: excluding files from a pattern

Say I have the following files: |-- bar `-- foo |-- type_A_1 |-- type_A_2 |-- type_B_1 |-- type_B_2 |-- type_B_xx |-- type_B_xx `-- something_else I thought the ...
-2
votes
1answer
237 views

Why does this script show all files in the directory and not just PDF files?

I wrote the script below to find the number of PDF files in a given directory. However, it instead shows all the files in the directory: #!bin/bash message="." message1="*.pdf" ls -al $message ...