Need a unix command

Hi all,
I just can't figure this out... I need a unix command that will backup any file matching a specific file extension AND the directory structure those files are in into a separate directory or volume. In other words, let's say that I have the files and directory structure below. I want to backup all of the txt files as separate files (not a tar archive) without writing the img files, without overwriting one txt file with another, and preserving the directory structure.
foo/bar/a.txt
foo/bar/b.txt
foo/bar/a.img
foo/bar/b.img
foo/me/a.txt
foo/me/b.txt
foo/me/a.img
foo/me/b.img
foo/me/you/a.txt
foo/me/you/b.txt
foo/me/you/a.img
foo/me/you/b.img
I've read the man pages for ditto and rsync... they're geared toward backing up every file in a directory, and so they're not very clear about how to backup one single file type/extension.
Everytime I try different varients of the rsync command, I either get errors "rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-24.1/rsync/main.c(717)", or file not found, or it overwrites the 'a.txt' with a different 'a.txt' without preserving the directory structure.
Can someone give me the exact syntax for backing up the .txt files in the example above to an external disk (e.g. /Volume/backup)???
Thanks!

OK... my example was oversimplified. There are tons of different types of files in my directories (*.img, *.gif, *.etc), and I only want to cp one type (e.g., .txt).
So, I started with the --include flag using the following command:
rsync -nav --include *.txt foo/ /Volumes/baz/
the result listed every file in foo (e.g., *.txt, *.img)
I thought that perhaps the \*.txt should be *.txt
rsync -nav --include *.txt foo/ /Volumes/baz/
the result listed every file in foo (e.g., *.txt, *.img)
rsync -nav --include "*.txt" foo/ /Volumes/baz/
again, the result listed every file in foo (e.g., *.txt, *.img)
Clearly, the --include flag wasn't working as I expected it to work. So, I decided to try the --exclude flag:
rsync -nav --exclude "*.img" foo/ /Volumes/baz/
Now, the results listed every file in foo except the *.img files.
I needed to exclude other files as well, so I tried:
rsync -nav --exclude "*.img *.etc" foo/ /Volumes/baz/
Now, the results listed every file in foo INCLUDING the *.img files. So, adding additional file types within quotes broke the original command.
rsync -nav --exclude *.img *.etc foo/ /Volumes/baz/
Now, I get the error "rsync: link_stat "/Volumes/HD/foo/*.etc" failed: No such file or directory (2)"; and all .etc files are still included
Now I tried:
rsync -nav --exclude *.img --exclude *.etc foo/ /Volumes/baz/
Now, this excluded both *.img and *.etc files. I have about 20 file types other than *.txt ... there has to be some other way!!!
PowerMac Dual 2.7GHz G5 Mac OS X (10.4.9) 4.5GB RAM

Similar Messages

  • Unix command sorely needed

    Hi
    Our tmp file was rammed up to 98% early this morning and I was called to deal with it.
    I needed to see the largest files then decide if we could eliminate them.
    I really need a Unix command that will list the largest files first (or last) from a given directory.
    Does this command exist? I already tried googling to meagre avail.
    Thanks.
    AIX 5.2
    9.2.0.2
    DA

    Hi Dan,
    I really need a Unix command that will list the largest files first (or last) from a given directory.Here is how I do it, using the "find" command:
    http://www.dba-oracle.com/t_unix_script_find_files_older_date.htm
    Finding large files on Linux
    The following command is very useful in cases where a Linux file system has become full. As we may know, Oracle will hang whenever Oracle must expand a tablespace and Oracle cannot extend the UNIX filesystem.
    When a UNIX file become unexpectedly full, it may be because Oracle has written a huge core or trace file into the UNIX filesystem.
    The script below will display all files that are greaten then one megabyte in size. Note that the size parameter is specified in K-bytes.
    root> find . -size +1024 –print
    ./prodsid_ora_22951.trc
    Of course, you can easily append the xargs of –exec command to automatically remove the large file:
    root> find . -size +1024 –print|xargs –i rm \;
    This find command will do a "stats" on all files in a directory structure, showing the total size of all files in the directory. You can also incorporate the "df -k" command"
    find ${START_DIR} -mtime -${DAYS} |xargs stat -c "%s"|awk '{sum += $1}END{print sum}'
    Hope this helps . . .
    Donald K. Burleson
    Oracle Press author
    Author of "Oracle Tuning: The Definitive Reference"
    http://www.rampant-books.com/book_2005_1_awr_proactive_tuning.htm

  • UNIX command to format or delete all content on Flash Drive

    Need a unix command that will allow me to quickly remove all contents or format a flash drive.
    Computers will be OS X based and I would have to batch process them.
    I'm just looking for the command itself, then my other guys can automate them
    Thanks

    Hi Mihalis,
       The second of your commands has a risk of failure because some of the directories may not be empty when the attempt is made to delete them. The problem isn't that the command won't try to delete all directories. The problem is that it tries to delete higher level directories before the directories they contain. A depth-first search will remedy that problem. Thus, I recommend the following form of the command:
    find -d /Volumes/Flash -type d -exec rmdir {} \;
    or
    find -d /Volumes/Flash -type d -delete
    Gary
    ~~~~
       A straw vote only shows which way the hot air blows.
             -- O'Henry

  • Working Code from Unix Command, needs fixing!

    /* Codes needs modification to run and display in GUI, will run and produce output in terminal, but will not display in GUI with setText and getText */
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class UnixCommand extends JFrame
    private JComboBox comboBox;
    private JTextArea displayArea;
    private JPanel mainPanel, displayPanel, comboPanel;
    private String names[] = { "Check Processes", "Check Network Connectivity",
                        "Check Remote Users", "Check Share Devices" };
    TitledBorder selectBorder, displayBorder;
    public UnixCommand()
         super( "Unix Command Tools in GUI" );
         Container container = getContentPane();
         mainPanel = new JPanel( new BorderLayout() );
         container.add( mainPanel );
         displayPanel = new JPanel();
         comboPanel = new JPanel();
              mainPanel.add( displayPanel, BorderLayout.CENTER );
              mainPanel.add( comboPanel, BorderLayout.NORTH );
                   comboBox = new JComboBox( names );
                   comboBox.setMaximumRowCount( 3 );
                   comboPanel.add( comboBox );
                        selectBorder = BorderFactory.createTitledBorder( "Select the Task to Perform" );
                        selectBorder.setTitlePosition( TitledBorder.TOP );
                        comboPanel.setBorder( selectBorder );     
                   displayArea = new JTextArea( 22, 40 );
                   displayPanel.add( displayArea );
                        displayBorder = BorderFactory.createTitledBorder( "The Command Output Selected" );
                        displayBorder.setTitlePosition( TitledBorder.BOTTOM );
                        displayPanel.setBorder( displayBorder );
    String s = null;
         displayArea.setText("\tHere is the standard output of the command:\n");
    try
                             // run the Unix "ps -ef" command
    Process p = Runtime.getRuntime().exec("ps -ef");
    BufferedReader stdInput = new BufferedReader(new
    InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new
    InputStreamReader(p.getErrorStream()));
                        // read the output from the command
    System.out.println("Here is the standard output of the command:\n");
    while ((s = stdInput.readLine()) != null)
    System.out.println(s);
                        // read any errors from the attempted command
    System.out.println("Here is the standard error of the command (if any):\n");
    while ((s = stdError.readLine()) != null)
    System.out.println(s);
    System.exit(0);
    catch (IOException e)
         System.out.println("exception happened - here's what I know: ");
         e.printStackTrace();
         System.exit(-1);
    setSize( 500, 500 );
    setVisible( true );
    public static void main( String args[] )
         UnixCommand application = new UnixCommand();
         application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    }

    All files are regenerated if changed.
    That goes for the .java and the .class files that are created. The jsp server checks to see if the current version is the latest. If it is, nothing gets changed or recompiled. If things are different, programs are recompiled.
    Youll notice that if you have a new jsp it always takes longer the first time. Or even when you change a jsp, the first time takes the longest for the page to come up in a browser. This is because of recompiling.
    Does this make any sense?
    Adam

  • What is the absolute client permission needed to receive Unix commands?

    The ARD error "This task is not authorized on (computerName)" is forcing me to allow almost all the privileges in the Remote Management section of client computer's Sharing System Preferences. I've already had to add:
    "open and quit applications"
    "change settings"
    "delete and replace items"
    "restart and shutdown" (see this Apple document's suggestion for Unix commands)
    "copy items"
    It makes no sense to my why 'Generate reports' must also be added, but clicking it off makes the error return. I'm just triggering a Unix command that goes something like "echo 1" and runs as root on the one test computer (and potentially dozens, so it wouldn't be pretty changing settings in that many) If it helps, the ARD host is 10.6.7 with ARD 3.4 (installed via the App Store a couple weeks ago) and the clients are 10.4.11 and 10.5.8.
    I'm preparing documentation for ARD and some clients installing our software will not warm to the idea of widening up the permissions footprint. Potentially dozens of computers will need to be retweaked, even if they wouldn't have to leave their seat.
    We also will need to deploy a pkg installer, so some of those may need to remain checked, but ...
    What is the absolute client permission needed to receive Unix commands?
    Thanks

    Have you tried sending it as User: Root
    To my knowledge with that setting you do not need any client permissions as a unix command used as Root overides any permission set. If this is something you need to do often I do know for a fact you can make the report task up use send as Root and tell it to save as template. After this you will be able use the templte to make things a bet quicker. I believe in oder to do this you must enable root user open Directory Utility in order to do this. Keep in mind root has full permissions and any command you enter with unix will be executed as such. This is a word around in the way that the normal client users do not need to have permissions enabled, also having root available at times is handy in stick situations.

  • SAP related UNIX commands needed.

    Dear All,
    I am new to unix environment, we have HPUX OS.
    Please provide me frequently used Unix commands related to SAP.or document please send it to me at [email protected] or paste it here.
    appreciate your early response.
    Regards,
    SM

    Hi again. The commands like ps -ef or grep is not special commands for SAP,it's commands for HP-UX, you can read
    about him on HP forums or HP documents...
    The links -->
    1) Technical documentation http://docs.hp.com/
    2) Online help - home http://www12.itrc.hp.com/service/help/onlineHelpHome.do?admit=109447627120628628184728353475
    3) Forums --> hp-ux technical documentation
    http://forums11.itrc.hp.com/service/forums/categoryhome.do?categoryId=475
    If you interest some commands only run search on the HP forum.
    Regards. Award if helpful.

  • UNIX command in ABAP code

    Hi All,
    I need to use unix command (MOVE) in ABAP code for transfering a file from one directory to another directory.
    Can any one help with how to used unix commands in ABAP?
    Thanks in advance.
    Regards,
    Hemendra

    The recommended approach always used to be to use transaction SM69 to define a "soft" command name to the operating system command so that it could be configured to work across Windows, Unix etc.  For example:
    Command name       OS         Type             OS command                                 Parameters for operating system command 
    Z_FILE_MOVE        SunOS      Customer    mv                                                 ? ?   
    You can then call function module SXPG_COMMAND_EXECUTE (quite well documented) to actually perform the command passing in the appropriate number of parameters.
    Jonathan

  • Unix commands in ABAP

    Hi,
       I need to call the following unix command in ABAP to encrypt a file on the app server .
    crypt password <org filename> new_filename
    1 But when i run it using call 'SYSTEM' .. i get message security risk , command not executed ..
    2 I also created the command in SM69 and tries to run it but same error.
    3 I also created a shell script , but i get another message when i try to run sh ...
      Please help to find out a way to make it work ..
    Kunal

    Hi kunal,
    1. probably ur basis team might be able to help u.
    2. even if we have authorisations thru sap
       to run external os command,
       the actual OS user on application server
       must have the right for it
       and access/write/read/modify
       for the files (provided thru the command)
       in question.
    3. Due to this , the systems gives the message
       of SECURITY RISK.
    regards,
    amit m.

  • Is there a way to change the VNC password thru unix command in ARD2?

    In a local network, I get access denied errors from macs that have the vnc password different than the Administrative login user password. I needed to change the Admistrator password which I did thru the Unix command in ARD2.
    Now.
    Is there a way to change the VNC password thru unix command in ARD2?
    Example:
    remote computer setup
    Panther 10.3.9
    vnc password - gopher
    user ID - testARD with admin rights
    user password - backdoor
    ARD2 Computer setup
    10.4.10
    login ID - testARD
    password - backdoor
    I get the blue icon but get an 'access denied' error.
    I change the password from backdoor to gopher.
    I get the red with dash icon but, can get access to the computer.
    What is going on? Is ARD2 using the VNC resource instead of ARDs resources?

    A quick search of Google finds this <http://www.macgeekery.com/tips/cli/settingremote_desktops_vnc_password_interminal>. I have not tested this myself.
    bill

  • Unix command in ARD to remove DNS Servers from Network prefs?

    I need to know how to send a unix command to remove DNS Servers in Network preferences. I need the DNS Servers field to be blank. Can this be done?

    Our network administrator is getting ready to change the IP address of our DNS server. This means I have over 30 Macs that will be needing changes to their DNS settings. Since each machine is setup with limited access to the system prefs, that means I have to go to each machine and log in as the admin user to make this change. In the interest of saving time, is this something I can do with Remote Desktop and how? Would I use the same commands in this post and replace dns1 with our DNS' new IP address? Will this distrupt the users access to the network when I do so?
    Thanks for any help.
    Beth

  • How to execute unix command through odi and store the result in table

    I have to reconcile  if data is loaded in table from csv file or not . I have to create a oracle data integrator package/interface/procedure to execute unix command to count number of rows in the csv files and store the count result in a table then i have to query the loaded table and count number of rows there and store in the table and have to compare is counts are same or not,  Please assist me how to make package/interface/procedure to  execute unix command and store result in oracle table.
    Thanks in Advance

    Use ODI OS command tool in the ODI package.
    create an interface in ODI using LKM File to Sql and the output file generated with the csv file's row count as a source and the db table(where the count needs to be stored) as a target

  • Execute Unix command on login

    Hello, is it possible to execute a unix command on user login?
    I want that every time a user login on a mac at my company, a unix command be executed.
    Is this case, this is the command: defaults write com.apple.mail NSPreferredMailCharset "UTF-8"
    thks in advance

    {quote}Loginwindow Scripts
    Another way to run applications at login time is to launch them using a custom shell script. Mac OS X provides two options for launching scripts when the user logs in. When creating your script file, keep the following in mind:
    * The permissions for your script file should include execute privileges for the appropriate users.
    * Scripts launched by loginwindow are run as root. Therefore, you should thoroughly test your scripts before deploying them to make sure they do not adversely affect the user's system.
    *In your script, the variable $1 returns the short name of the user who is logging in.
    * Other login actions wait until your hook finishes executing. Therefore, have your script do what it needs to do quickly and then exit. {quote}
    I want the script to be run as the current user that does the login, and not as the root. I think that if its run as root, it changes nothing in the user. Does this root issue apllies to the Zerwas method?
    It depends on how Zerwas was thinking you'd implement it. If you added it to each user's login items, it should run as the user. If you create a startup item to run it, it will run as root. I'm assuming Zerwas was suggesting the former because there would be no point in wrapping the shell script in an AppleScript if you are going to turn it into a startup item.
    What you might be able to do - at least with the loginwindow script - would be to explicitly run the command as the user by making use of the fact that the user name is passed to the loginwindow script as $1. I've never used loginwindow scripts but it seems as though it should work.
    Another possibility would be to use a LaunchAgent. These are really intended to manage background processes, though, and it seems an unnecessary use of resources to load one which will only ever be run at startup.
    Can I ask why you wish to run the script every time a user logs in? Is the concern that the default will get set to something else and needs to be reset regularly?
    - cfr

  • Using UNIX command to copy desktop files/folders

    Hello All. I need help using UNIX command(s) to copy text documents and or folders from my lab computers to my desktop at home. Since I have such a slow connection, I think this will work best. I need help with the cp command and the path mostly. Since all files would be in folders on the desktop (including documents (that "missed" the folders), I believe I could simply copy desktop contents? Thanks, J Langlois

    What you want to do is SCP (secure copy) your documents to your remote host.
    send this command to the computer with the documents
    scp ~/Desktop/FILEOR_FOLDERNAME USERNAME@REMOTE_COMPUTER:~/Desktop/
    Replace all the stuff in UPPERCASE with the correct vales for your situation.
    Mini (Intel Core Duo)   Mac OS X (10.4.8)  

  • Using Unix command lines in java code

    I was wondering if there was a way to run a unix command in java code. I know in C++ there is popen, but i don't know of a way in java. The command i need to run is the whois "domain name" command. Any help would be great!
    jarad

    try something like this:
      public static String whois(String domain) throws IOException {
        BufferedReader is = null;
        Process p = null;
        String result = "";
        p = Runtime.getRuntime().exec("whois " + domain);
        is = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while((line = is.readLine()) != null)
          result += line;
        return result;
      }

  • Unix Command to search file

    Hi
    Can anyone tell me how to get filename from server using
    UNIX command in ABAP program.I have requirement to search file in server using date criteria.
    should i use 'FIND' command to search file??
    Plz do needful..

    You need to use SM69 to define command and use it in your report.
    Regards,
    Christophe

Maybe you are looking for