getting a file name from a folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting getting a file name from a folder
# 1  
Old 08-14-2006
getting a file name from a folder

what is command for getting a list of file in the particular folder.

Assume X is folder where y is subfolder inside X and there is one file called abc.text.

While giving this command it would return two value ie abc.txt and y.
Code:
$cd X
$ls -lrt *.txt |cut -c55-120

I am only looking the value of abc.txt not X

Can anyone please advice what is best to capture only abc.txt.

also how this can be set into a varibale v_file in unix script.

is this correct
Code:
v_file=`echo ls -lrt *.txt |cut -c55-120'

thanks in advance
# 2  
Old 08-14-2006
Try
ls -tlr | grep -v "^d"

This will remove the direcories in the output of ls -ltr.


regards
Apoorva Kumar
# 3  
Old 08-14-2006
Quote:
Originally Posted by u263066
what is command for getting a list of file in the particular folder.

Assume X is folder where y is subfolder inside X and there is one file called abc.text.

While giving this command it would return two value ie abc.txt and y.
Code:
$cd X
$ls -lrt *.txt |cut -c55-120

I am only looking the value of abc.txt not X

Can anyone please advice what is best to capture only abc.txt.

also how this can be set into a varibale v_file in unix script.

is this correct
Code:
v_file=`echo ls -lrt *.txt |cut -c55-120'

thanks in advance
It isn't very clear what you want, dude. You do a 'cd X', and then run 'ls -rlt *.txt', then in your example, the only output that will be thrown is the abc.txt file. The directory X will never come up at all...

Would be better to just know what you want to do (you want to get the names of all .txt files inside the directory or something like that).
# 4  
Old 08-14-2006
dude,

I am trying to get the filename by putting a command and then I want to use this in variable to write in some other file.

echo ls -lrt *.txt | grep -v "^d"|cut -c55-120'

but it gives me a no such file or directory, but simply giving the above command is returning one value.

could you tell me why ...is something wrong in the command?
# 5  
Old 08-14-2006
If you just want to get a list of filenames, then why make things so complicated?

Do you just want the *.txt files? Then use something like this:
Code:
cd X
for file in *.txt; do
   #do whatever that you want with the file here
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