Sponsored Content
Top Forums Shell Programming and Scripting Archive different folders based on their names Post 302460923 by vilibit on Friday 8th of October 2010 02:49:42 AM
Old 10-08-2010
Bug

The final version:

Code:
cd $rootpath

ls -l|grep back_ |awk '/^d/ {print $NF}'  |while read dir
do
  cd ${rootpath}/${dir}
  ls -l |awk '/^d/ {print $NF}' |while read subdir
  do
     tar cvf - ${subdir} |gzip > ${subdir}_${dir#*_}.tar.gz   # or replace by below command, if you have gtar
#   gtar zcvf ${subdir}_${dir#*_}.tar.gz ${subdir}
     rm -rf $subdir
  done
  cd $rootpath
done
rename back_ back. back_*

All subfolders are deleted and main folders are renamed to not be procesed on next run.

Last edited by vilibit; 10-08-2010 at 05:32 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

script to archive certain folders in a hierarchy

I'm new to shell scripting and I'm having a tough time figuring out how to script something. Can anyone help? Here is my setup and what I want to do: A directory contains a list of projects by year (2000, 2001, etc) and customers (01-001) all of which have the same internal directory setup... (3 Replies)
Discussion started by: medazinol
3 Replies

2. UNIX for Dummies Questions & Answers

Copying multiple folders to local machine (don't know folder names)

Hi. I'm trying to copy multiple folders from the remote machine to the local machine. I wrote a batch file to run an ftp window. The problem I am having is that the only command to copy files is mget *, and this copies only files, not folders. For example, ftp ts555 cd ts555/test ' test... (5 Replies)
Discussion started by: leenyburger
5 Replies

3. UNIX for Dummies Questions & Answers

How to Archive Folders in T-Shell

Hi i am new to Unix Shell Programming... i m just a beginner and i m training myself in Unix.... I need a sample code to archive folders in my Windows OS using Unix commands... Can someone Help me? (1 Reply)
Discussion started by: aegan
1 Replies

4. Shell Programming and Scripting

Archive files to different target folders based on criteria

Hi All, I am creting archive script in which i need to split the source file's to different target folder's based on the input file name first character. Input1.txt -- will contains file names that are needs to be Archive. Input1.txt A1213355 B2255666 C2254555 A6655444 C5566445 ... (2 Replies)
Discussion started by: kmsekhar
2 Replies

5. Shell Programming and Scripting

Ordering Folders having Date as Names

Hi All, I have directories under /development/arun/weekly/ 20120421 20120414 . . . . I need to arrange these directories in descending order. folder name with recent date will be on top and then others. (1 Reply)
Discussion started by: Arun Mishra
1 Replies

6. OS X (Apple)

Remove leading spaces from file names and folders

Hi All, I have a vexing issue with leading spaces in file names. Basically, we're moving tons of data from our ancient afp file share to Box.com and Box forbids leading spaces in files or folders. The HFS file system seems to be perfectly fine with this, but almost all other Unix file systems... (1 Reply)
Discussion started by: prometheon123
1 Replies

7. Shell Programming and Scripting

Files with same names in different folders

Hello, I am looking for a command line that can do some operations on two files that have the same names but in different folders. for example if folder A contains files 1.txt, 2.txt, 3.txt,.. folder B contains files 1.txt, 2.txt, 3.txt,.. If I would like to concatenate the two files... (6 Replies)
Discussion started by: Mohamed EL Hadi
6 Replies

8. UNIX for Dummies Questions & Answers

Archive folders and sub folders

Hi Can i archive folder and folders in with the tar command My files are located in subfolders Eg: Folder1/Folder1_1/*.pdf Folder1/Folder1_2/*.pdf Folder1/Folder1_3/*.pdf so i would like to tar all the files in Folder1_1 and Folder1_2 only not Folder1_3 that should be done next... (2 Replies)
Discussion started by: cnrj
2 Replies

9. UNIX for Dummies Questions & Answers

Allocating names to folders based on a file

Hi everyone, I have a problem and I would be gratful if you can help. I have set of folders with files in them. e.g. data1, data2, data3 and I have a json file with info ... looking like this I want to rename my files to replace the data with their gender to some processing and back to... (8 Replies)
Discussion started by: A-V
8 Replies
Arch::Util(3pm) 					User Contributed Perl Documentation					   Arch::Util(3pm)

NAME
Arch::Util - Arch utility functions SYNOPSIS
use Arch::Util qw(run_tla load_file save_file setup_config_dir); my $abrowse_output = run_tla('abrowse --summary --date --creator'); my ($full_version) = run_tla('tree-version'); my @full_revisions = run_tla('logs', '-r', '-f'); my $cfg_dir = setup_config_dir(undef, "archipelago"); my $content = load_file("$cfg_dir/versions.cfg"); $content =~ s/^last_version = .*/last_version = $full_version/m; save_file("$cfg_dir/versions.cfg", $content); DESCRIPTION
A set of helper functions suitable for GNU Arch related projects in Perl. Higher (object oriented) levels of Arch/Perl library make use of these helper functions. FUNCTIONS
The following functions are available: run_tla, run_cmd, run_pipe_from, load_file, save_file, copy_dir, remove_dir, setup_config_dir, standardize_date, date2daysago, date2age, parse_creator_email, adjacent_revision. The system functions die on errors. is_tla_functional Verify whether the system has a working arch backend installed (and possibly configured by environment variables, like TLA or ARCH_BACKEND), needed for this perl library to function. run_tla subcommand_with_args run_tla subcommand arg ... Run the given tla subcommand with optional arguments. Return the tla output in the scalar context, and a list of chomp-ed lines in the list context. run_cmd shell_command_with_args run_cmd shell_command arg ... Run the given shell command (like wc or awk) with optional arguments. Return the command output in the scalar context, and a list of chomp-ed lines in the list context. run_tla is implemented using run_cmd. run_pipe_from shell_command_with_args run_pipe_from shell_command arg ... Run the given shell command (like ls or tar) with optional arguments in the separate process. Return the pipe (file handle) that may be used to read the command output from. run_cmd is implemented using run_pipe_from. load_file file_name load_file file_name scalar_ref load_file file_name array_ref Load the given file_name. Return the file content if the returning value is expected. As a side effect, may modify the scalar_ref or array_ref if given, in the last case all file lines are split and chomp-ed. save_file file_name content Save the given content in the given file_name. The content may be either scalar, scalar ref, or array ref (see load_file). copy_dir dir1 dir2 Copy dir1 to dir2 recursivelly, preserving as many attributes as possible. remove_dir dir .. Remove dir (or dirs) recusivelly. Please be careful. setup_config_dir setup_config_dir dir setup_config_dir dir subdir ... Create (if needed) the configuration dir that defaults to either $ARCH_MAGIC_DIR or ~/.arch-magic or /tmp/.arch-magic if $HOME is unset. If one or more consecutive subdir given, repeat the same procedure for the sub-directory (including creating and diagnostics if needed). Return a name of the existing directory (including sub-directories if any). standardize_date default_unix_date_string Try to convert the given date string to "yyyy-mm-dd HH:MM:SS TMZ". If failed, the original string is returned. date2daysago date_string Convert a date string to time difference to now in full days. In list content, return (num_days_ago, unix_time, timezone_str). date2age date_string Like date2daysago, but return a human readable string, like "5 days" or "-6 weeks" or "7 months" or "3 years". parse_creator_email my_id Try to parse the arch my-id of the patch creator. Return a list of his/her name and email. adjacent_revision full_revision offset Given the full_revision and positive or negative offset, try to guess the full name of the adjacent revision. BUGS
Awaiting for your reports. AUTHORS
Mikhael Goikhman (migo@homemail.com--Perl-GPL/arch-perl--devel). SEE ALSO
For more information, see tla, Arch. perl v5.10.1 2010-03-08 Arch::Util(3pm)
All times are GMT -4. The time now is 05:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy