filename in current directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting filename in current directory
# 1  
Old 04-15-2007
filename in current directory

I want to perform a task on all the files in the current directory but I'd like to loop through them one at a time. How do I tell it to give me the first filename?
# 2  
Old 04-15-2007
What is the criteria for the file to be the first one?.

If the criteria is change time or access time or modification time, then find or ls could be used.

Thanks
Nagarajan Ganesan
# 3  
Old 04-15-2007
Quote:
Originally Posted by calgone337
I want to perform a task on all the files in the current directory but I'd like to loop through them one at a time. How do I tell it to give me the first filename?

Code:
for file in *
do
   # do something with "$file" here, e.g.:
   n=$(( ${n:-0} + 1 ))
   printf "%5d: %s\n" "$n" "$file"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to get the current directory Path?

How to get the current directory Path in your prompt? i am getting a $ mark only in my prompt? Please help me with this (3 Replies)
Discussion started by: Abhishek0683
3 Replies

2. UNIX for Dummies Questions & Answers

Current working directory

Hi all, How do I print the name of my current working directory only to screen? Not pwd! For example, if I was in /home/work I am looking for 'work' only (4 Replies)
Discussion started by: jimjam
4 Replies

3. UNIX for Advanced & Expert Users

current directory in awk

Hello, I want to use the string with the current directory in my awk command. I tried: 'pwd=system("pwd")' but it doesn't work. can please help somebody? (2 Replies)
Discussion started by: daWonderer
2 Replies

4. UNIX for Dummies Questions & Answers

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (7 Replies)
Discussion started by: johannd
7 Replies

5. Shell Programming and Scripting

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (1 Reply)
Discussion started by: johannd
1 Replies

6. Shell Programming and Scripting

tarball of current directory

I wanna make a backup tarball. I wanna write a script that makes tarball of the current directory. There are lots of files so I cant type all files, I wanna make the tarball by excluding few files. Like there 1000 files in a directory I wanna create a tarball containing 98 files of that... (1 Reply)
Discussion started by: nishrestha
1 Replies

7. Shell Programming and Scripting

how to append current date to filename.tgz in perl

i would like to know how to append current date in a filename with .tgz extension. #!/usr/bin/perl my $date = `date + %Y%m%d`; system("sudo mv /tmp/nyucs01_config_backup.tgz /misc/nyucs01_config_backup_$date.tgz"); im getting this error message: sh: line 1: .tgz: command not found (7 Replies)
Discussion started by: linuxgeek
7 Replies

8. Shell Programming and Scripting

Finding files in current directory when 100,000's files in current directory

Hi All I was wondering what is the most efficient way to find files in the current directory(that may contain 100,000's files), that meets a certain specified file type and of a certain age. I have experimented with the find command in unix but it also searches all sub directories. I have... (2 Replies)
Discussion started by: kewong007
2 Replies

9. UNIX for Advanced & Expert Users

cannot determine current directory

Hi, when I execute some simple commands on my solaris system, I am getting the following warning message: Could anybody tell me what could be the reason Ex:- If I give the command, which ls Warning: cannot determine current directory ... (15 Replies)
Discussion started by: axes
15 Replies

10. UNIX for Dummies Questions & Answers

Append current date to filename

In C Shell programming I haven't successfully been able to append the date in the format mmddyyyy to a filename. I've tried the following: I can print out the date in the correct format: date +%x | sed ‘s/\///g I can create a variable with the filename: set newfile=changedfiles I can... (3 Replies)
Discussion started by: gigigi
3 Replies
Login or Register to Ask a Question