file name in folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting file name in folder
# 1  
Old 10-12-2006
file name in folder

here is the few commond i am doing:
Code:
$ ls -l
total 6
drwxrwxr-x   2 dv1gfp   dv1gfp      1024 Oct 12 09:57 archive
-rw-r--r--   1 odv1gfp  oradba      1805 Oct 12 09:56 Schroders.CSV
$ ls -lrt * | awk '{print $9}'|grep -v "^d"
Schroders.CSV



test.dat
SANJIT4.dat
CITI5.dat
ANAND6.dat
ANA8.dat
ANA7.dat
3.dat
2.dat
export.CSV_1
export.CSV
export.csv.orig
$

now i want to know the file name in this folder, but giving this command listing out all files within archive folder also.
Can anyone help me out, which command should I release for this.
# 2  
Old 10-12-2006
What do you want? Do you want to show file but not directory?
If yes, try this

Code:
for file in `ls -lrt * | awk '{print $9}'|grep -v "^d"`
do
    if [ -f $file ]; then
       echo $file
   fi
loop

# 3  
Old 10-12-2006
ls -lrt | grep -v "^d" | awk '{print $9}'


remove * from ls command and shift grep one step ahead... because if you put awk first, it takes only the 9 th column ( i.e file name )... then no where you can find "^d" to remove lines.
# 4  
Old 10-12-2006
hi

Code:
$ ls -lrt | grep -v "^d" | awk '{print $9}'

Sanjit.CSV

Why there is one blank line coming here

where as line
Code:
$ ls -lrt *.CSV | awk '{print $9}'|grep -v "^d"
sanjit.CSV

no blank line coming
# 5  
Old 10-12-2006
Just try... the following two commands

ls -lrt *.CSV
ls -lrt

In the second command you will find additional line something like "total 6"... this is causing the blank line...

if you want to filter this out, add

change the grep to

egrep -v "^d|^total"
# 6  
Old 10-12-2006
Quote:
Originally Posted by Tomato
What do you want? Do you want to show file but not directory?
If yes, try this

Code:
for file in `ls -lrt * | awk '{print $9}'|grep -v "^d"`
do
    if [ -f $file ]; then
       echo $file
   fi
loop

Code:
#!/bin/sh

find -type f | while IFS= read vo
do
echo `basename "$vo"`
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

3. UNIX for Beginners Questions & Answers

UNIX utility to find difference in folder, file and contents of file against a base version

Hi, I am trying to find out whether there are any Unix utilities that compares folders, files and contents within the file and provides a comprehensive report. The comparison can be against base version of a folder and file with content. Can you please let me know of such a utility? Thanks,... (6 Replies)
Discussion started by: Sripathi_ks
6 Replies

4. Shell Programming and Scripting

Checking Multiple File existance in a UNIX folder(Note: File names are all different)

HI Guys, I have some 8 files with different name and extensions. I need to check if they are present in a specific folder or not and also want that script to show me which all are not present. I can write if condition for each file but from a developer perspective , i feel that is not a good... (3 Replies)
Discussion started by: shankarpanda003
3 Replies

5. UNIX for Dummies Questions & Answers

To delete the oldest files in a file when file count in the folder exceeds 7

Hi All, I need to delete the oldest file in folder when the file count in the folder exceed 6 ( i have a process that puts the source files into this folder ) E.x : Folder : /data/opt/backup 01/01/2012 a.txt 01/02/2012 b.txt ... (1 Reply)
Discussion started by: akshay01987
1 Replies

6. Programming

how to copy downloaded file into my source file folder (putty/unix)

I need to "Ensure that when you download libchat.a from the VLE you have copied it to the same folder on ius as your source files. You then refer to the library (and the libraries it needs) with: gcc -o outputfile sourcefile.c -L. -lchat -lsocket -lnsl" But I have no idea what this means! (I... (2 Replies)
Discussion started by: fakuse
2 Replies

7. Shell Programming and Scripting

want to move set of file from one folder to another folder

Hi all, let me explain my requirments i am having 5 folder with different name for eg) abc , cdf , efd, rtg, ead each 5 folders contain 15 files i want to move 10 files to some other folder, remain 5 files should be there in the same folder. give me some suggestion on this. (6 Replies)
Discussion started by: natraj005
6 Replies

8. Shell Programming and Scripting

File Management: How do I move all JPGS in a folder structure to a single folder?

This is the file structure: DESKTOP/Root of Photo Folders/Folder1qweqwasdfsd/*jpg DESKTOP/Root of Photo Folders/Folder2asdasdasd/*jpg DESKTOP/Root of Photo Folders/Folder3asdadfhgasdf/*jpg DESKTOP/Root of Photo Folders/Folder4qwetwdfsdfg/*jpg DESKTOP/Root of Photo... (4 Replies)
Discussion started by: guptaxpn
4 Replies

9. Shell Programming and Scripting

Move the file from one folder to another folder

Hi, I have a requirement to move a file from one folder(a) to another folder(b) only when folder (b) have a write permission. Folder permission is 755 If the permission is otherthan 755 we need to come out of the loop I will appreciate your help Thanks Soll (1 Reply)
Discussion started by: sollins
1 Replies

10. Shell Programming and Scripting

Parse the .txt file for folder name and FTP to the corrsponding folder.

Oracle procedure create files on UNIX folder on a regular basis. I need to FTP files onto windows server and place the files, based on their name, in the corresponding folders. File name is as follows: ccyymmddfoldernamefile.txt; Folder Name length could be of any size; however, the prefix and... (3 Replies)
Discussion started by: MeganP
3 Replies
Login or Register to Ask a Question