![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pattern Matching Count Urgent | krabu | Shell Programming and Scripting | 6 | 07-31-2008 06:23 PM |
| Awk to count matching IP address | new_buddy | Shell Programming and Scripting | 3 | 05-28-2008 05:24 AM |
| removing the extension from all filenames in a folder | johnmcclintock | UNIX for Dummies Questions & Answers | 5 | 05-21-2008 08:23 AM |
| command to get count in unzipped folder | arunkumar_mca | UNIX for Dummies Questions & Answers | 4 | 10-17-2007 02:19 PM |
| finding duplicate files by size and finding pattern matching and its count | jerome Sukumar | Shell Programming and Scripting | 2 | 12-01-2006 04:20 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Count matching filenames in a folder
Hi all,
I have 4 files for example named abc01012009.txt abc02012009.txt abc03012009.txt abc04012009.txt in a folder. I would like to firstly backup the latest file available, in this case, the latest date available, abc04012009.txt to its subfolder named backup, and then rename the file to abc.txt, so that leaves me with abc01012009.txt abc02012009.txt abc03012009.txt abc.txt then, it will run the commands I will set, and once the commands are completed, it go through the list of files again, and loop my commands, until no more files named abcDDMMYYYY.txt are available.Can someone please help, thank you so much!. rgds |
|
||||
|
The fist "ls" is used to test if any files matching this criteria are found. The output of ls is "thrown away" (to /dev/null) - the point being to know if there are such files, not to list them. If files are found, the "if [ $? -eq 0 ]" will be true (the ls returned 0 meaning success - files were found). But ls will write to standard error if no files are found. You can get rid of the error by directing standard error to /dev/null too. The simplest way is to direct standard error to standard output (which you threw away to /dev/null), so...
Change: Code:
ls -1rt abc[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].txt > /dev/null Code:
ls -1rt abc[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].txt > /dev/null 2>&1 Last edited by scottn; 07-02-2009 at 07:10 PM.. |
|
||||
|
Thank you very much!. Really appreciate it!
|
| Sponsored Links | ||
|
|