Active 1 year, 3 months ago. Viewed 98k times. Improve this question. Interactive Unix, wow. If you're on a really non-standard and out of date Unix rather than struggling with whatever wacky versions of shell utilities they have your best bet might be to use Perl.
It should compile it has provisions for Interactive Unix, but you might have to use an older version as I doubt anyone's done it in a while and it might already be installed. Then ask for updates. They will replace the system in a year. I have already prepared the code to run on Windows. But until then, the old system is managed, and they want to change as little as possible on the system to meet new demands from other systems — magol. That has no risk and low effort. Show 2 more comments.
Active Oldest Votes. Here's one way using find. Improve this answer. Asclepius Schwern Schwern k 22 22 gold badges silver badges bronze badges. Unfortunately, I don't think it will work reliably. If find does return a file name and that doesn't form an acceptable argument to the test builtin, shell will declare it to be an error. The only reason the solution provided by Schwern worked is because find returned an empty string which test evaluates to a non-zero exit status.
A better solution, in my opinion would be to check if find has returned an empty string or not. Find does not have a non-zero exit status if it doesn't locate a file. Schwern here you go. Sorry for the delay. The output on bash 4. The problem, as you might have guessed, is quoting. If you quote the command substitution, it works fine. Which is much, much more import than speed. For a single command like this yes, but in high number environments it's a bad habit with a costly disadvantage: waste of resources.
If you need a calculator to know how long seconds is you are making yourself dumb like using a Tom-Tom does. Leo if calculating a product of two numbers is awful waste of resources for your application, you'd better using compilable language like C for your problem, not scripting one like sh. Leo: In a high number of environments it is much more costly for code to contain magic numbers than it is to waste CPU time.
Only in a small number of cases is extreme micro optimization warranted. But even in those cases most experienced programmers would tell you the first rule of optimization. You are wasting time and resources here discussing that micro minor issue. No programmer will have a real problem understanding either. Keep your feet on the ground. Show 4 more comments. I have below restriction.
I used find. I would like to restrict doing search recursively and not to search inside directories. If you are piping the output of find into another program and there is the faintest possibility that the files which you are searching for might contain a newline, then you should seriously consider using the -print0 option instead of -print. A slightly different spin on this: find is incredibly versatile, you can specify size and time as follows:.
This finds you all the logs that are 4 months or older and bigger than 1 meg. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.
Learn more. List all files older than x days only in current directory Ask Question. Asked 6 years, 1 month ago. Active 8 months ago. Viewed 40k times. I am new to unix and couldn't get appropriate outcome in other questions. I have below restriction List only files in current folder which are older than 30 days Output shouldn't include directories and subdirectories This should list files similar as "ls" command does Output should look like file1 file2 file I'm not sure what's the best way of doing this, I've had a look at the stat command too but well..
Hi All, I want to get those the files which were created before 20 days. Say, we have two server, remote server and local server. I want to get only 20 days older files from remote server to my local server. Remove the older files.
Hi All, I need to remove some old files which the file creation date is older than a week. I've tried to use command: find. Hi Friends, i have to write a script to raise a flag if there are any files that are older than 15 minutes in the directory. The directory is supplied as the parameter to the script. Thanks in advance veera 0 Replies.
RedHat Commands. OpenSolaris Commands. Linux Commands. SunOS Commands. FreeBSD Commands. Full Man Repository. Advanced Search.
0コメント