Rectangle 27 74

Remove any other change and supports removing files/folders with space...

svn revert -R .
svn status --no-ignore | grep -E '(^\?)|(^\I)' | sed -e 's/^. *//' | sed -e 's/\(.*\)/"\1"/' | xargs rm -rf
svn update --force

Thanks a lot Shaize, this is the most elegant sed, ... pipe I've seen so far for this :) Especially taking care about the ignores also.

How can I remove all my changes in my SVN working directory? - Stack O...

svn
Rectangle 27 13

Update: I've also removed one | head -n following @eregon's suggestion, and added support for files with spaces in them:

# Adapted to use HEAD rather than the new commit ref
get_file_rev() {
    git rev-list -n 1 HEAD "$1"
}

# Same as Giel's answer above
update_file_timestamp() {
    file_time=`git show --pretty=format:%ai --abbrev-commit "$(get_file_rev "$1")" | head -n 1`
    sudo touch -d "$file_time" "$1"
}

# Loop through and fix timestamps on all files in our CDN directory
old_ifs=$IFS
IFS=$'\n' # Support files with spaces in them
for file in $(git ls-files | grep "$cdn_dir")
do
    update_file_timestamp "${file}"
done
IFS=$old_ifs

for reference, %ai is the "author date, ISO 8601 format"

the --abbrev-commit is superfluous in git show command due --pretty=format:%ai being used (commit hash isn't part of output) and | head -n 1 could be replaced with using -s flag to git show

@DanielS.Sterling: %ai is author date, ISO 8601 like format, for strict iso8601 use %aI: git-scm.com/docs/git-show

What's the equivalent of use-commit-times for git? - Stack Overflow

git
Rectangle 27 9

I don't like the -L answer because it does not handle files with spaces in them which is a key function of find -print0.

echo "file with space.txt" | xargs -L 1 ls
ls: file: No such file or directory
ls: space.txt: No such file or directory
ls: with: No such file or directory

A better solution is to use tr to convert newlines to null (\0) characters, and then use the xargs -0 argument.

echo "file with space.txt" | tr '\n' '\0\ | xargs -0 ls
file with space.txt

Another problem with using -L also is that it doesn't allow multiple arguments for each xargs command call. For example, the currently accepted solution would call /bin/rm for each of the lines which is a ton of execs. By using the tr command, then the -n can be used to limit the number of lines read from the input for every invocation of the utility.

find . -name \*.java | tr '\n' '\0' | xargs -0 wc

This also allows you to filter the output of find before converting the breaks into nulls.

find . -name \*.xml | grep -v /workspace/ | tr '\n' '\0' | xargs -0 tar -cf xml.tar

Make xargs execute the command once for each line of input - Stack Ove...

xargs
Rectangle 27 2

dirfiles=(/path/of/interest/*)

And accept the admonition against parsing the output of ls!

I understand you are new to this and I'd like to help. But it isn't easy for me (us?) to provide you with an answer that would be of much help to you by the way you've stated your question.

Based on what I hear so far, you don't seem to have a basic understanding on how parameter expansions work in the shell. The following two links will be useful to you: Matching Pathnames, Parameters

find(1)

linux - storing output of ls command consisting of files with spaces i...

linux bash filenames ls
Rectangle 27 2

Say it with me: don't parse the output of ls! For more information, see this post on Unix.SE.

A better way of doing this is:

for i in *
do
    mv -- "$i" ~
done
mv -- * ~

@mklement0 Whoops, right, not sure how I missed that considering the question was specifically about filenames with spaces :) Edited.

This works if one wants to run commands on files in present directory, but I have to list all files in one directory and compare the file names with some text files....... so storing in a list might become necessary and the directory might not be current directory as well. Also if I try s=("Hello world") it takes each word as a separate entries . How to store a sentence in a list an a single entry?

This will still fail if you hava a file name starting with -. use mv -- * ~

linux - storing output of ls command consisting of files with spaces i...

linux bash filenames ls
Rectangle 27 17

This will work for some number of files. You want to include "-print0" and "xargs -0" in case any of the paths have spaces in them. This example looks for files modified in the last 7 days. To find those modified before the last 7 days, use "+7".

As this page warns, xargs can cause the tar command to be executed multiple times if there are a lot of arguments, and the "-c" flag could cause problems. In that case, you would want this:

find . -mtime -7 -print0 | xargs -0 tar -rf /foo/archive.tar

You can't update a zipped tar archive with tar, so you would have to bzip2 or gzip it in a second step.

Regarding the second point, you can use a gzip-enabled tar command, like Gnu tar's -z option, to update zipped archives, too.

Or add the 'j' option to use bzip in recent GNU tars

As I said above on Jonathan's answer, this will grab the folders which have changes causing all of their files to be imported. Add -type f to only select files. This maintains the folder structure, but only backs up the files with changes/added recently.

unix - Shell Script — Get all files modified after - Stack Over...

unix shell
Rectangle 27 63

This displays the short names generated for non-8dot3 file names. The format is that of /N with the short name inserted before the long name. If no short name is present, blanks are displayed in its place.

can you explain why "c:\PROGRA~1" means the same as "c:\Program Files"?

Can you be sure that the short name does never change, which would be important for a configuration file?

The short name might be different from your example, e.g. if you also have a folder named C:\ProgramFiles (without space) or alike you might get C:\PROGRA~2 for "C:\Program Files"

@ChrisF: If only I could downvote your comment, I would. Where do you get the idea that "Windows still uses the old 8.3 character name format"? On the contrary, file systems can be configured to not use it at all.

It's really unlikely to move, because these folders are the first ones to be created when windows is installed. However, in the case of windows being installed to a HD that already has a folder c:\programmable, this might be problematic

windows - How do I specify C:\Program Files without a space in it for ...

windows
Rectangle 27 3

Here's a different way to think about the problem:

Here's a rough outline:

use strict;
use warnings;

sub main {
    # Map the input arguments to oldname-newname pairs.
    my @renamings = 
        map { [$_, cleaned($_)] }
        map { -f $_ ? $_ : glob("$_/*")  }
        @_;

    # Sanity checks first.
    #   - New names should be unique.
    #   - New should not already exist.
    #   - ...

    # Then rename.
    for my $rnm (@renamings){
        my ($old, $new) = @$rnm;
        rename($old, $new) unless $new eq $old;
    }
}

sub cleaned {
    # Allowed characters: word characters, hyphens, periods, slashes.
    # Adjust as needed.
    my $f = shift;
    $f =~ s/[^\w\-\.\/]/-/g;
    return $f;
}

main(@ARGV);

Very nice code. Still: (1) error checking on rename sounds like a good idea. (2) I'm surprised you have backslashes but not periods as an allowed character: while a Windows filename will never include backslashes, this character is still very inconvenient to work with in bash.

recursion - Perl script to rename files with spaces in name, pushd/pop...

perl recursion rename
Rectangle 27 7

Guessing no one will ever see this buried at the back... Yet none of the answers so far gets at the problem of filenames with spaces. Additionally, all that use xargs are subject to fail if total length of paths in the tree exceeds the shell environment size limit (defaults to a few megabytes in Linux). Here is one that fixes these problems in a pretty direct manner. The subshell takes care of files with spaces. The awk totals the stream of individual file wc outputs, so ought never to run out of space. It also restricts the exec to files only (skipping directories):

find . -type f -name '*.php' -exec bash -c 'wc -l "$0"' {} \; | awk '{s+=$1} END {print s}'

bash - How to count all the lines of code in a directory recursively? ...

bash shell
Rectangle 27 1

As mentioned in comments, maybe try:

RewriteEngine On
##RewriteBase /
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com [NC]
RewriteRule \.(.*)$ - [NC,F,L]

RewriteCond %{QUERY_STRING} ^filename=(.*)$
RewriteRule ^download\.php$ %1
RewriteRule (.*) - [E=file:$1]
Header set Content-type "octet-stream"
Header set Content-disposition "attachment; filename='%{file}'" env=file

##AuthName "Restricted Access" 
##AuthType Basic
##AuthUserFile /local/home/example/example.com/downloads/.htpwd
##AuthGroupFile /dev/null 
##require valid-user

Alternately, why not set the Content Type and Disposition within your download.php file itself?

$fileStorageDirectory = '/the/folder/the/downloadable/files/are/in/';

// Check for Parameter
if( !isset( $_GET['filename'] ) || $_GET['filename']=='' ){
  header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
  die('No File Specified');
}

$fileName = trim( $_GET['filename'] );
$fileRequested = $fileStorageDirectory.$fileName;
// Check File Exists
if( !file_exists( $fileRequested ) ){
  header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
  die('File Not Found');
}
// Check File is Readable
if( !is_readable( $fileRequested ) ){
  header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
  die('File Not Accessible');
}
// Send the File
header( 'Content-Type: application/octet-stream' );
header( 'Content-Disposition: attachment; filename="'.fileName.'"' );
readfile( $fileRequested );
exit;

php - download files with spaces in their name - restriction through h...

php apache .htaccess .htpasswd
Rectangle 27 9

Here is a slight modification to the script so Windows files with spaces are taken into account as well. Also the missing.list file will be removed at the end.

I saved the following in svndel.bat in my SVN bin directory (set in my %%PATH environment) so it can be called from any folder at the command prompt.

### svndel.bat
svn status | findstr /R "^!" > missing.list
for /F "tokens=* delims=! " %%A in (missing.list) do (svn delete "%%A")
del missing.list 2>NUL

SVN command to delete all locally missing files - Stack Overflow

svn file-io
Rectangle 27 9

Here is a slight modification to the script so Windows files with spaces are taken into account as well. Also the missing.list file will be removed at the end.

I saved the following in svndel.bat in my SVN bin directory (set in my %%PATH environment) so it can be called from any folder at the command prompt.

### svndel.bat
svn status | findstr /R "^!" > missing.list
for /F "tokens=* delims=! " %%A in (missing.list) do (svn delete "%%A")
del missing.list 2>NUL

SVN command to delete all locally missing files - Stack Overflow

svn file-io
Rectangle 27 6

Guessing no one will ever see this buried at the back... Yet none of the answers so far gets at the problem of filenames with spaces. Additionally, all that use xargs are subject to fail if total length of paths in the tree exceeds the shell environment size limit (defaults to a few megabytes in Linux). Here is one that fixes these problems in a pretty direct manner. The subshell takes care of files with spaces. The awk totals the stream of individual file wc outputs, so ought never to run out of space. It also restricts the exec to files only (skipping directories):

find . -type f -name '*.php' -exec bash -c 'wc -l "$0"' {} \; | awk '{s+=$1} END {print s}'

bash - How to count all the lines of code in a directory recursively? ...

bash shell
Rectangle 27 15

Here are a few possibilities that don't parse the output of ls and that are 100% safe regarding files with spaces and funny symbols in their name. All of them will populate an array randf with a list of random files. This array is easily printed with printf '%s\n' "${randf[@]}" if needed.

a=( * )
randf=( "${a[RANDOM%${#a[@]}]"{1..42}"}" )

This feature is not very well documented.

If N is not known in advance, but you really liked the previous possibility, you can use eval. But it's evil, and you must really make sure that N doesn't come directly from user input without being thoroughly checked!

N=42
a=( * )
eval randf=( \"\${a[RANDOM%\${#a[@]}]\"\{1..$N\}\"}\" )
eval
  • The same using a more straightforward method (a loop): N=42 a=( * ) randf=() for((i=0;i<N;++i)); do randf+=( "${a[RANDOM%${#a[@]}]}" ) done
  • If you don't want to possibly have several times the same file: N=42 a=( * ) randf=() for((i=0;i<N && ${#a[@]};++i)); do ((j=RANDOM%${#a[@]})) randf+=( "${a[j]}" ) a=( "${a[@]:0:j}" "${a[@]:j+1}" ) done

Note. This is a late answer to an old post, but the accepted answer links to an external page that shows terrible bash practice, and the other answer is not much better as it also parses the output of ls. A comment to the accepted answer points to an excellent answer by Lhunath which obviously shows good practice, but doesn't exactly answer the OP.

First and second produced "bad substitution"; it didn't like the "{1..42}" part leaving a trailing "1". Also, $RANDOM is only 15 bit and the method will not work with over 32767 files to choose from.

How can I select random files from a directory in bash? - Stack Overfl...

bash random
Rectangle 27 15

Here are a few possibilities that don't parse the output of ls and that are 100% safe regarding files with spaces and funny symbols in their name. All of them will populate an array randf with a list of random files. This array is easily printed with printf '%s\n' "${randf[@]}" if needed.

a=( * )
randf=( "${a[RANDOM%${#a[@]}]"{1..42}"}" )

This feature is not very well documented.

If N is not known in advance, but you really liked the previous possibility, you can use eval. But it's evil, and you must really make sure that N doesn't come directly from user input without being thoroughly checked!

N=42
a=( * )
eval randf=( \"\${a[RANDOM%\${#a[@]}]\"\{1..$N\}\"}\" )
eval
  • The same using a more straightforward method (a loop): N=42 a=( * ) randf=() for((i=0;i<N;++i)); do randf+=( "${a[RANDOM%${#a[@]}]}" ) done
  • If you don't want to possibly have several times the same file: N=42 a=( * ) randf=() for((i=0;i<N && ${#a[@]};++i)); do ((j=RANDOM%${#a[@]})) randf+=( "${a[j]}" ) a=( "${a[@]:0:j}" "${a[@]:j+1}" ) done

Note. This is a late answer to an old post, but the accepted answer links to an external page that shows terrible bash practice, and the other answer is not much better as it also parses the output of ls. A comment to the accepted answer points to an excellent answer by Lhunath which obviously shows good practice, but doesn't exactly answer the OP.

First and second produced "bad substitution"; it didn't like the "{1..42}" part leaving a trailing "1". Also, $RANDOM is only 15 bit and the method will not work with over 32767 files to choose from.

How can I select random files from a directory in bash? - Stack Overfl...

bash random
Rectangle 27 2

If you want to map CSV header with different name, you can create a hash map and use this for your internal implementation, e.g. you can map "First Name" with "firstName" and populate your bean based on your internal names..

That sounds like what I'm looking for. Can you help me through it a bit? I'm really unfamiliar with this. Thanks! :)

I hope you got the solution as suggested by maxwellb..

Super CSV (Java) - Read Files with Spaces in Column Names - Stack Over...

java csv supercsv
Rectangle 27 2

You notice this line in the samples you link to:

final String[] header = inFile.getCSVHeader(true);

I think I understand your question now. The String[] argument passed to the read function takes the property names of the class you want to read into. It is positional, so it doesn't have to be named anything like the headers. So, for example, you can have String[] header = inFile.getCSVHeader(), but then have a mapping of headerName->propertyName, so, if your header fields were:

First Name, Last Name, Age

but your class was

getFirstName(), setFirstName(...);
getLastName(), setLastName(...);
getYears(), setYears();
(String[]) {"First Name", "Last Name", "Age"}
read
(String[]) {"FirstName", "LastName", "Years"}

Look at the UserBean class, though. Doesn't the column name have to correspond to the variables? I'm a little confused what happens at the while loop.

What I'm saying is, notice how he uses the headers "username", "password", etc. These directly correspond to the variables username and password. I have "First Name" as a header and can't have First Name as a variable (spaces aren't allowed + poor formatting).

I was thinking about that, but if I define my own header, wouldn't it consider my headers that are already in place as data? I'll try it out and get back to you. Might take a sec with so many variables.

No, according to the JavaDoc, everything in the read methods only correspond the position of the String[] to the position of the field. This is easily seen if you use a CsvListReader instead of a CsvBeanReader, as there are no name mappings of field names to speak of. You only care about position with CsvListReader. With CsvBeanReader, String[] {FName,LName} says "read the first field into the FName property, and the second field into the LName property". After the header, Csv*Reader doesn't care what you name the fields. It's 1st field, 2nd field, 3rd field, etc.

Super CSV (Java) - Read Files with Spaces in Column Names - Stack Over...

java csv supercsv
Rectangle 27 118

  • Check the "user header paths" are correct (Add "" to paths for spaces, both in your project and dependencies)
  • Create a group call "Indexing headers" in your project and drag the headers to this group, DO NOT add to any targets when prompted. This includes any headers inside your .xcdatamodeld, you'll need to right-click and view package contents to find them.
  • Moving any "Public" headers in Build Phases to "Project"
$(LOCAL_APPS_DIR)
  • Change the target build setting "scan all source files for includes" to YES. (link)
  • With newer versions of Xcode (> 4.2) you might want to read this question related to workspaces.

The very last suggestion is all I needed to fix this issue. Close & re-open Xcode.

Yup, same thing for me, just had to restart Xcode. It happened after I renamed & moved files around in the project.

Note to Three20 users migrating old projects from xcode3 to xcode4 : you (may) have to change xcode Preference / locations / advanced / ->Locations specified by target. See stackoverflow.com/questions/5261447/ for more

objective c - Compile, Build or Archive problems with Xcode 4 (and dep...

objective-c compiler-construction xcode4 clang c-preprocessor
Rectangle 27 118

  • Check the "user header paths" are correct (Add "" to paths for spaces, both in your project and dependencies)
  • Create a group call "Indexing headers" in your project and drag the headers to this group, DO NOT add to any targets when prompted. This includes any headers inside your .xcdatamodeld, you'll need to right-click and view package contents to find them.
  • Moving any "Public" headers in Build Phases to "Project"
$(LOCAL_APPS_DIR)
  • Change the target build setting "scan all source files for includes" to YES. (link)
  • With newer versions of Xcode (> 4.2) you might want to read this question related to workspaces.

The very last suggestion is all I needed to fix this issue. Close & re-open Xcode.

Yup, same thing for me, just had to restart Xcode. It happened after I renamed & moved files around in the project.

Note to Three20 users migrating old projects from xcode3 to xcode4 : you (may) have to change xcode Preference / locations / advanced / ->Locations specified by target. See stackoverflow.com/questions/5261447/ for more

objective c - Compile, Build or Archive problems with Xcode 4 (and dep...

objective-c compiler-construction xcode4 clang c-preprocessor
Rectangle 27 118

  • Check the "user header paths" are correct (Add "" to paths for spaces, both in your project and dependencies)
  • Create a group call "Indexing headers" in your project and drag the headers to this group, DO NOT add to any targets when prompted. This includes any headers inside your .xcdatamodeld, you'll need to right-click and view package contents to find them.
  • Moving any "Public" headers in Build Phases to "Project"
$(LOCAL_APPS_DIR)
  • Change the target build setting "scan all source files for includes" to YES. (link)
  • With newer versions of Xcode (> 4.2) you might want to read this question related to workspaces.

The very last suggestion is all I needed to fix this issue. Close & re-open Xcode.

Yup, same thing for me, just had to restart Xcode. It happened after I renamed & moved files around in the project.

Note to Three20 users migrating old projects from xcode3 to xcode4 : you (may) have to change xcode Preference / locations / advanced / ->Locations specified by target. See stackoverflow.com/questions/5261447/ for more

objective c - Compile, Build or Archive problems with Xcode 4 (and dep...

objective-c compiler-construction xcode4 clang c-preprocessor