Moving files extension one by one


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Moving files extension one by one
# 1  
Old 12-16-2012
Moving files extension one by one

Hi, I'm trying to do a script that move .Gz extension (one by one) in a new repertory called old-logs and then copy what's inside old-logs to a new.log but adding a date like this (something. gz: 2012:12:09).
thanks in advance for your answers.
# 2  
Old 12-16-2012
What have you tried so far? Where are you stuck?
This User Gave Thanks to Yoda For This Post:
# 3  
Old 12-16-2012
well i'm stuck at moving files one by one i just dont know how to do it.
what i think:
Code:
for i in */.gz
do
  mv(first (i) files with .gz in old-logs)
done


Last edited by Franklin52; 12-17-2012 at 07:01 AM.. Reason: code tags
# 4  
Old 12-16-2012
To move gz files in old-logs directory to new-logs directory one-by-one:-
Code:
for in in *.gz
do
    echo "Moving file: ${i}"
    mv ${i} new-logs/
done

To move gz files in old-logs directory to new-logs directory all at once:-
Code:
mv *.gz new-logs/

This User Gave Thanks to Yoda For This Post:
# 5  
Old 12-16-2012
if i want to move the first .gz file without knowing what its is
# 6  
Old 12-16-2012
If you want to move only the first .gz file based on modification time, then you can use ls command with -t option:
Code:
for i in $( ls -t *.gz | tr " " "\n" | head -1 )
do
   echo "Moving file: ${i}"
   mv ${i} new-logs/
done

Note: I am using tr " " "\n" to convert blank space to newline and head -1 to list only first .gz file. This method will fail if you have a file name with blank spaces in it.
This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

2. Shell Programming and Scripting

Python - glob () - How to grep same files with different extension files

Hi I Have a directory and i have some files below abc.txt abc.gif gtee.txt ghod.pid umni.log unmi.tar How can use glob function to grep abc files , i have created a variable "text" and i assigned value as "abc", please suggest me how can we use glob.glob( ) to get the output as below... (2 Replies)
Discussion started by: kumar85shiv
2 Replies

3. Shell Programming and Scripting

Copy files with extension .sh

Hi all... I am trying to copy all my shell script to some directory using following command, I want to simplify it by not using awk..please some one help me.... find -name "*.sh" | awk -F"/" '{a=$NF;gsub(".sh",x,a);cmd="cp"" " $0" ""/home/akshay/MY_ALL/"a"_"++i".sh";system(cmd)}' (3 Replies)
Discussion started by: Akshay Hegde
3 Replies

4. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

5. UNIX for Dummies Questions & Answers

How to list files with no extension together with *.prog files?

Hi, I know that to list files with no extension, we can use.. ls -1 | grep -v "\." And to list .prog files, we can use.. ls -1 *.prog or ls -1 | grep '.prog$' (4 Replies)
Discussion started by: adshocker
4 Replies

6. UNIX for Dummies Questions & Answers

How to compress files without extension

Could someone please help? I'm trying to compress all the files in a directory without extension. I know for typical files with extension, the command is something like: tar -zcvf file.tar.gz *.doc What is the command for files without extension? Thanks. (4 Replies)
Discussion started by: AChan1118
4 Replies

7. Shell Programming and Scripting

gzip the files with particular extension

Is there any way to compress only the files with .xml extension within a folder which in turn has many sub folders? gzip -r9 path/name/*.xml is not working This compression is done in the Windows server using Batch script. (2 Replies)
Discussion started by: Codesearcher
2 Replies

8. Linux

copying all files except those with certain extension

Hi, I have a root directory which has a big number of other subdirectories and contains a big number of files. I want to copy all these files and directories to another folder except files with certain extension, say .txt, files - how may I do this? Thanks, faizlo (8 Replies)
Discussion started by: faizlo
8 Replies

9. HP-UX

Files without extension

I am brand new to hp unix systems. I see some files without extension on this system. If I type name of the file it shows me so many detail but does not take me back to command prompt. What are these files and how do I come back to command prompt? Please help (1 Reply)
Discussion started by: rajahindustani
1 Replies

10. UNIX for Dummies Questions & Answers

How to test for files with a particular extension.

Hi!!, Is there any way on Ksh to test the files having a particular Extension? My program looks something like: for i in *$1* do if "$i" != files with ext of .Z then compress -f $i fi done Any suggestions??? :):) (1 Reply)
Discussion started by: jyotipg
1 Replies
Login or Register to Ask a Question