Sponsored Content
Top Forums Shell Programming and Scripting Help with moving files with same names from subdirectories? Post 302521203 by ygemici on Tuesday 10th of May 2011 01:56:40 PM
Old 05-10-2011
Code:
# find /somedir/ -type f
/somedir/testx/testx1/98
/somedir/testx/testx1/5
/somedir/testx/testx1/1
/somedir/testx/testx1/2
/somedir/testx/testx1/8
/somedir/testx/testx1/3
/somedir/testx/testx1/7
/somedir/testx/5
/somedir/testx/4
/somedir/testx/1
/somedir/testx/2
/somedir/testx/3
/somedir/testx/testx2/4
/somedir/testx/testx2/1
/somedir/testx/testx2/2
/somedir/testx/testx2/3

Code:
# find /somedir -type f|while read -r a ; do if [[ ! $(ls -1|grep "^${a#${a%/*}/}_*") ]] ; then \
cp -f $a .; else cp -f $a ${a#${a%/*}/}_$(echo $(ls -1|grep "^${a#${a%/*}/}_*"|wc -l)+1|bc) ; fi ; done ; ll
-rw-r--r-- 1 root root 0 Jan 21 17:04 1
-rw-r--r-- 1 root root 0 Jan 21 17:04 1_2
-rw-r--r-- 1 root root 0 Jan 21 17:04 1_3
-rw-r--r-- 1 root root 0 Jan 21 17:04 2
-rw-r--r-- 1 root root 0 Jan 21 17:04 2_2
-rw-r--r-- 1 root root 0 Jan 21 17:04 2_3
-rw-r--r-- 1 root root 0 Jan 21 17:04 3
-rw-r--r-- 1 root root 0 Jan 21 17:04 3_2
-rw-r--r-- 1 root root 0 Jan 21 17:04 3_3
-rw-r--r-- 1 root root 0 Jan 21 17:04 4
-rw-r--r-- 1 root root 0 Jan 21 17:04 4_2
-rw-r--r-- 1 root root 0 Jan 21 17:04 5
-rw-r--r-- 1 root root 0 Jan 21 17:04 5_2
-rw-r--r-- 1 root root 0 Jan 21 17:04 7
-rw-r--r-- 1 root root 0 Jan 21 17:04 8
-rw-r--r-- 1 root root 0 Jan 21 17:04 98

regards
ygemici
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Moving files and changing names

i have many files with extention filename.ASN_ERROR~ at a path. I want to move these files to another path and change extension to .ASN There are more then 80,000 files so i cant use manual commands muneebr (5 Replies)
Discussion started by: muneebr
5 Replies

2. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

3. Shell Programming and Scripting

Moving files to their respective subdirectories

Hello, I have files like this img.txt ./Rearrange_zoca/fitted_data/WX226_05b_Ncere.jpg ./Rearrange_zoca/fitted_data/w322_03B_60_70.jpg ./Rearrange_zoca/fitted_data/wrx226_12A_50_60.jpg ./Rearrange_zoca/fitted_data/wx124_01A_50_60.jpg ./Rearrange_zoca/fitted_data/wx124_02A_50_60.jpg... (3 Replies)
Discussion started by: avatar_007
3 Replies

4. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

5. UNIX for Dummies Questions & Answers

Moving files with specific names

Hi, I have a list of names (in a text file) like this: SRR1234 SRR5678 SRR4321 SRR8876 I'd like to have a unix code to find all the files which have any of above strings in their name and move them to a specific directory. I have my files distributed in many subdirectories so it has to... (3 Replies)
Discussion started by: a_bahreini
3 Replies

6. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

7. UNIX for Dummies Questions & Answers

How to list the names of the files from all the subdirectories?

Hi, I'm currently trying to print the names of all the .txt files in the subdirectories that contain the string I'm searching. I tried with this code, but it seems that it searches for the names that matches the string instead of searching for the string in the individual files and printing the... (2 Replies)
Discussion started by: nuclearpenguin
2 Replies

8. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

9. Shell Programming and Scripting

Unzip all the files with subdirectories present and append a part of string from the main .zip files

Hi frnds, My requirement is I have a zip file with name say eg: test_ABC_UH_ccde2a_awdeaea_20150422.zip within that there are subdirectories on each directory we again have .zip files and in that we have files like mama20150422.gz and so on. Iam in need of a bash script so that it unzips... (0 Replies)
Discussion started by: Ravi Kishore
0 Replies

10. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies
SYSTEMD-VOLATILE-ROOT.SERVICE(8)                           systemd-volatile-root.service                          SYSTEMD-VOLATILE-ROOT.SERVICE(8)

NAME
systemd-volatile-root.service, systemd-volatile-root - Make the root file system volatile SYNOPSIS
systemd-volatile-root.service /lib/systemd/systemd-volatile-root DESCRIPTION
systemd-volatile-root.service is a service that replaces the root directory with a volatile memory file system ("tmpfs"), mounting the original (non-volatile) /usr inside it read-only. This way, vendor data from /usr is available as usual, but all configuration data in /etc, all state data in /var and all other resources stored directly under the root directory are reset on boot and lost at shutdown, enabling fully stateless systems. This service is only enabled if full volatile mode is selected, for example by specifying "systemd.volatile=yes" on the kernel command line. This service runs only in the initial RAM disk ("initrd"), before the system transitions to the host's root directory. Note that this service is not used if "systemd.volatile=state" is used, as in that mode the root directory is non-volatile. SEE ALSO
systemd(1), systemd-fstab-generator(8), kernel-command-line(7) systemd 237 SYSTEMD-VOLATILE-ROOT.SERVICE(8)
All times are GMT -4. The time now is 05:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy