Copy non-empty files into subdirectory

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Copy non-empty files into subdirectory
# 1  
Old 10-09-2013
Copy non-empty files into subdirectory

How to Copy non-empty files into subdirectory

I have directory A

there are bunch of files: a.txt b.txt

How can i find out the non-empty file within * and copy them into a subdirectory B?

Thank you.
# 2  
Old 10-09-2013
find . -name '*' ! -empty -type f -exec cp -vv {} otherdir/ \;

# 3  
Old 10-09-2013

One more way as follows, may help you too.

File_names=`ls -ltr | grep '^-' | grep '.txt' | awk '{print$9}'`
set -A array_Files_names ${File_names}
for i in ${array_Files_names[@]}
if [[ -s $i ]]
val=`ls -ltr | grep $i | awk '{print$9}'`
echo $val

## copying the file to your wished directory as follows
cp $val /home/King/bin/chumma/awk_programming/$val

R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Php help to copy form field if empty

I have an input form with several fields. What I would like to achieve is to auto populate or copy certain fields if they are empty when the form is submitted. I would like to use php if not then javascript but not jquery if possible - I have sort of had a go but I really have no idea... (4 Replies)
Discussion started by: barrydocks
4 Replies

2. Shell Programming and Scripting

Copying Multiple Files into a Subdirectory

Hello, I'm very new to scripting languages and I'm to use shell script to write a utility to backup files with a specific extension into a subdirectory. Here is what I have done. #!/bin/bash read -p "Enter file(s) extension: " FILE if ; then mkdir `whoami`.$FILE #To... (9 Replies)
Discussion started by: alphanoob
9 Replies

3. UNIX for Dummies Questions & Answers

How to Find files in subdirectory?

I am trying to find all DAT files in a subdirectory named IN. I do not know the entire path. For example: /stage/<?>/<?>/IN/file.DAT I am using the find command without success: find /stage -name IN -a -name '*.DAT' -print What is the correct logic and syntax? Thank you for the help. (5 Replies)
Discussion started by: TwinGT
5 Replies

4. UNIX for Dummies Questions & Answers

Listing files in subdirectory

Forgive me if there is an answer to this somewhere in the forums. I've gone through as much as I could but couldn't find a relevant answer. What I'm trying to do is use the ll command to list some files in a subdirectory that matches a certain format. I've tried ll *.*a* <subdirectory> but... (3 Replies)
Discussion started by: archaic
3 Replies

5. Filesystems, Disks and Memory

DD copy excluding empty blocks?

I'm not 100% sure if this was the right place to post in but here i go: I'm attempting to migrate a physical windows disk onto my SAN through the use of the dd copy command. I'm booting into knoppix, running dd, and then bringing the server back up into windows running on the SAN. Everything... (2 Replies)
Discussion started by: Merkilo
2 Replies

6. Solaris

How Prevent from deleting subdirectory files

Hi All, I am using the foolowing find /home/vcrd/put -name '*.z' -mtime +5 -exec rm -f {} \; in a shell script, it is deleting all file having *.z in /home/vcrd/put/appl sub directory. I donot want the files in the subdirectory are deleted. Regards Megh (2 Replies)
Discussion started by: megh
2 Replies

7. Shell Programming and Scripting

How to deleting some files under subdirectory

Hi guys, sorry if my english not very well.. i have a problem.. i have a file and the structure is : Folder/ Folder/ Folder/ Folder/ Folder/ (4 Replies)
Discussion started by: AdziE
4 Replies

8. Shell Programming and Scripting

Count files in every subdirectory

Hi if anyone could help me :) I did a lot of search and 70% of answer is "how to count files in all subdirectories". A basic problem for me is how to count files in every subdirectory separately then sort it by number of files For example: dir1 file1 file2 subdir11 dir2 dir3 ... (3 Replies)
Discussion started by: yorryk
3 Replies

9. UNIX for Dummies Questions & Answers

[Question]How to copy files to all subdirectory

I want to copy php.ini to all subdirectory. what command that should i run? (2 Replies)
Discussion started by: dzufauzan
2 Replies

10. UNIX for Dummies Questions & Answers

How can I copy files and subdirectory?

I am trying to copy some files from one location to another and I need to write a script to move all the files and the subdirectories to the new location (both unix), but excluding the temp directory. i.e., I want to avoid copying my temp subdirectories during the process of copying other files... (3 Replies)
Discussion started by: odogbolu98
3 Replies
Login or Register to Ask a Question