Sponsored Content
Top Forums Shell Programming and Scripting bash script for testing existence of files/folders and creating if neither exist Post 302494266 by Corona688 on Sunday 6th of February 2011 02:55:59 PM
Old 02-06-2011
-p is required, yes, or I wouldn't have put it there.

if you already have a file named 'boo', it will fail. delete it.
This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Testing existence of a file /directory

hey guys How can i test existence of a file /directory in a directory in a script thanks (2 Replies)
Discussion started by: ajaya
2 Replies

2. UNIX for Dummies Questions & Answers

testing if files exist

I am trying to test arguments to see if they are files in any directory. I have : but it's not working (7 Replies)
Discussion started by: skooly5
7 Replies

3. Shell Programming and Scripting

moving multiple folders/files in subversion using bash script

Hi, I'm new here an dlearning a lot from this forum. i didnt find any solution for this in the forum. I have already checked in folders in subversion named HTT01,... HTT21.. and have files in each folder like below: HTT01/HTT01_00000.hex HTT01/HTT01_00000_fb_result.hex... (2 Replies)
Discussion started by: ravishan21
2 Replies

4. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

5. Shell Programming and Scripting

Creating folders based on number of files

I have hundreds of files numbered in consecutive number in one single folder What I would like to do is to make as many subfolders as needed (dependeing on the number of individual files) and name them Folder01, Folder02, etc. Then, move file01 to folder01, file02 to folder02 so on and so... (3 Replies)
Discussion started by: Xterra
3 Replies

6. Shell Programming and Scripting

check if multiple folders exist

I want to check if some directories with common prefix exist under current directory with bash, say, I have dictories like: dirct_1 dirct_2 dirct_3 ... in the current directory. I did: if then echo " directories exist " else echo " directories not exist " fi (3 Replies)
Discussion started by: cristalp
3 Replies

7. UNIX for Advanced & Expert Users

Help with creating script to delete log files/folders

Hi I am new to Linux / scripting language. I need to improve our Linux servers at work and looking to claim some space my deleting log files/ folders on a 5 day basis. Can someone help me with creating a script to do so. Any sample script will be helpful.:b: Regards (2 Replies)
Discussion started by: sachinksl
2 Replies

8. Shell Programming and Scripting

Bash to download specific files and save in two folders

I am trying to download all files from a user authentication, password protected https site, with a particular extension (.bam). The files are ~20GB each and I am not sure if the below is the best way to do it. I am also not sure how to direct the downloaded files to a folder as well as external... (7 Replies)
Discussion started by: cmccabe
7 Replies

9. Shell Programming and Scripting

Bash to move specific files from folders in find file

I have a directory /home/cmccabe/nfs/exportedReports that contains multiple folders in it. The find writes the name of each folder to out.txt. A new directory is then created in a new location /home/cmccabe/Desktop/NGS/API, named with the date. What I am trying to do, unsuccessfully at the moment,... (7 Replies)
Discussion started by: cmccabe
7 Replies

10. Shell Programming and Scripting

Need BASH Script Help to Move Files While Creating Directories

I've got this script to loop through all folders and move files that are more than 2 years old. I'm using the install command because it creates the necessary directories on the destination path and then I remove the source. I'd like to change the script to use the mv command since it is much... (4 Replies)
Discussion started by: consultant
4 Replies
MouseX::NativeTraits::ArrayRef(3pm)			User Contributed Perl Documentation		       MouseX::NativeTraits::ArrayRef(3pm)

NAME
MouseX::NativeTraits::ArrayRef - Helper trait for ArrayRef attributes SYNOPSIS
package Stuff; use Mouse; has 'options' => ( traits => ['Array'], is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] }, handles => { all_options => 'elements', add_option => 'push', map_options => 'map', filter_options => 'grep', find_option => 'first', get_option => 'get', join_options => 'join', count_options => 'count', has_options => 'count', has_no_options => 'is_empty', sorted_options => 'sort', }, ); DESCRIPTION
This module provides an Array attribute which provides a number of array operations. PROVIDED METHODS
These methods are implemented in MouseX::NativeTraits::MethodProvider::ArrayRef. count Returns the number of elements in the array. $stuff = Stuff->new; $stuff->options(["foo", "bar", "baz", "boo"]); my $count = $stuff->count_options; print "$count "; # prints 4 is_empty Returns a boolean value that is true when the array has no elements. $stuff->has_no_options ? die "No options! " : print "Good boy. "; elements Returns all of the elements of the array. my @option = $stuff->all_options; print "@options "; # prints "foo bar baz boo" get($index) Returns an element of the array by its index. You can also use negative index numbers, just as with Perl's core array handling. my $option = $stuff->get_option(1); print "$option "; # prints "bar" pop push($value1, $value2, value3 ...) shift unshift($value1, $value2, value3 ...) splice($offset, $length, @values) These methods are all equivalent to the Perl core functions of the same name. first( sub { ... } ) This method returns the first item matching item in the array, just like List::Util's "first" function. The matching is done with a subroutine reference you pass to this method. The reference will be called against each element in the array until one matches or all elements have been checked. my $found = $stuff->find_option( sub { /^b/ } ); print "$found "; # prints "bar" any( sub { ... } ) This method returns true if any item in the array meets the criterion given through the subroutine, otherwise returns false. It sets $_ for each item in the array. grep( sub { ... } ) This method returns every element matching a given criteria, just like Perl's core "grep" function. This method requires a subroutine which implements the matching logic. my @found = $stuff->filter_options( sub { /^b/ } ); print "@found "; # prints "bar baz boo" map( sub { ... } ) This method transforms every element in the array and returns a new array, just like Perl's core "map" function. This method requires a subroutine which implements the transformation. my @mod_options = $stuff->map_options( sub { $_ . "-tag" } ); print "@mod_options "; # prints "foo-tag bar-tag baz-tag boo-tag" apply( sub { ... } ) This method also transform every element in the array and returns a new array, just like List::MoreUtils's "apply" function.his is similar to "map", but does not modify the element of the array. reduce( sub { ... } ) This method condenses an array into a single value, by passing a function the value so far and the next value in the array, just like List::Util's "reduce" function. The reducing is done with a subroutine reference you pass to this method. my $found = $stuff->reduce_options( sub { $_[0] . $_[1] } ); print "$found "; # prints "foobarbazboo" sort( &compare ) Returns the array in sorted order. You can provide an optional subroutine reference to sort with (as you can with Perl's core "sort" function). However, instead of using $a and $b, you will need to use $_[0] and $_[1] instead. # ascending ASCIIbetical my @sorted = $stuff->sort_options(); # Descending alphabetical order my @sorted_options = $stuff->sort_options( sub { lc $_[1] cmp lc $_[0] } ); print "@sorted_options "; # prints "foo boo baz bar" sort_in_place( &compare ) Sorts the array in place, modifying the value of the attribute. You can provide an optional subroutine reference to sort with (as you can with Perl's core "sort" function). However, instead of using $a and $b, you will need to use $_[0] and $_[1] instead. sort_by( &by, &compare ) Returns the array in sorted order, applying &by function to each item. This is equivalent to "sort(sub{ by($_[0]) cmp by($_[1]) })", but implemented effectively. Currently (as of Moose 0.98) this is a Mouse specific method. sort_in_place_by( &by, &compare ) Sorts the array, applying &by function to each item, modifying the value of the attribute. This is equivalent to "sort_in_place(sub{ by($_[0]) cmp by($_[1]) })", but implemented effectively. Currently (as of Moose 0.98) this is a Mouse specific method. shuffle Returns the array, with indices in random order, like "shuffle" from List::Util. uniq Returns the array, with all duplicate elements removed, like "uniq" from List::MoreUtils. join($str) Joins every element of the array using the separator given as argument, just like Perl's core "join" function. my $joined = $stuff->join_options( ':' ); print "$joined "; # prints "foo:bar:baz:boo" set($index, $value) Given an index and a value, sets the specified array element's value. delete($index) Removes the element at the given index from the array. insert($index, $value) Inserts a new element into the array at the given index. clear Empties the entire array, like "@array = ()". accessor This method provides a get/set accessor for the array, based on array indexes. If passed one argument, it returns the value at the specified index. If passed two arguments, it sets the value of the specified index. for_each(sub{ ... }) This method calls the given subroutine with each element of the array, like Perl's core "foreach" statement. Currently (as of Moose 0.98) this is a Mouse specific method. for_each_pair( sub{ ... } ) This method calls the given subroutine with each two element of the array, as if the array is a list of pairs. Currently (as of Moose 0.98) this is a Mouse specific method. METHODS
meta method_provider_class helper_type SEE ALSO
MouseX::NativeTraits perl v5.14.2 2011-12-04 MouseX::NativeTraits::ArrayRef(3pm)
All times are GMT -4. The time now is 05:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy