Korn shell files
Connect and share knowledge within a single location that is structured and easy to search. I wonder why the below tiny script is now working. 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. Check if file exists in ksh Ask Question. I want to delete scripts in a folder from the current date back to 10 days. The scripts looks like:. Just spicing up the shell script above to delete older files but with logging and calculation of elapsed time.
Note : to test the code, just use -print instead of -print -delete. But do check your path carefully though. Additionally check file times with 'stat filename'.
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. Delete files older than 10 days using shell script in Unix [duplicate] Ask Question.
Asked 9 years, 1 month ago. Active 2 years, 3 months ago. Viewed k times. If you want the dash character to be part of a list, just list it first or last. In the original wildcard example, program. For example, [! The problem is that such ranges are not entirely portable between different types of computers.
The process of matching expressions containing wildcards to filenames is called wildcard expansion. This is just one of several steps the shell takes when reading and processing a command line; another that we have already seen is tilde expansion, where tildes are replaced with home directories where applicable.
That is, they just see a list of arguments, and they have no knowledge of how those arguments came into being. Here is another example that should help you understand why this is important.
Suppose you are a C programmer. This just means that you deal with files whose names end in. In other words, ls will see the filenames just as if they were all typed in individually-but notice that we assumed no knowledge of the actual filenames whatsoever! We let the wildcards do the work. As you gain experience with the shell, reflect on what life would be like without wildcards. Pretty miserable, we would say. The software field-really, any scientific field-tends to advance most quickly and impressively on those few occasions when someone i.
The standard input and output scheme of UNIX has to be on the short list of such ideas, along with such classic innovations as the LISP language, the relational data model, and object-oriented programming. Second, everything on the system that produces or accepts data is treated as a file; this includes hardware devices like disk drives and terminals. Older systems treated every device differently. By convention, each UNIX program has a single way of accepting input called standard input , a single way of producing output called standard output , and a single way of producing error messages called standard error output , usually shortened to standard error.
Of course, a program can have other input and output sources as well, as we will see in Chapter 7. For example, the mail utility prints messages to you on the standard output, and when you use it to send messages to other users, it accepts your input on the standard input.
This means that you view messages on your screen and type new ones in on your keyboard. When necessary, you can redirect input and output to come from or go to a file instead. You can also hook up programs into a pipeline , in which the standard output of one program feeds directly into the standard input of another; for example, you could feed mail output directly to the lp program so that messages are printed instead of shown on the screen.
This makes it possible to use UNIX utilities as building blocks for bigger programs. Many UNIX utility programs are meant to be used in this way: they each perform a specific type of filtering operation on input text. The more popular filtering utilities are listed in Table 1. You may have used some of these before and noticed that they take names of input files as arguments and produce output on standard output. You may not know, however, that all of them and most other UNIX utilities accept input from standard input if you omit the argument.
For example, the most basic utility is cat , which simply copies its input to its output. If you type cat with a filename argument, it will print out the contents of that file on your screen. But if you invoke it with no arguments, it will expect standard input and copy it to standard output. It accepts multiple filename arguments and copies them to the standard output.
As we said above, the shell lets you redirect standard input so that it comes from a file. Input and output redirectors can be combined. This would be similar to cp file1 file2. It is also possible to redirect the output of a command into the standard input of another command instead of a file. The construct that does this is called the pipe, notated as. A command line that includes two or more commands connected with pipes is called a pipeline.
Pipes are very often used with the more command, which works just like cat except that it prints its output screen by screen, pausing for the user to type SPACE next screen , RETURN next line , or other commands.
The first field of each line is the login name; fields are separated by colons :. A sample line might look like this:. To get a sorted listing of all users on the system, type:. The cut command extracts the first field -f1 , where fields are separated by colons -d: , from the input. The entire pipeline will print a list that looks like this:. If you want to send the list directly to the printer instead of your screen , you can extend the pipeline like this:. The notation is extremely terse and powerful.
Just as important, the pipe concept eliminates the need for messy temporary files to store output of commands before it is fed into other commands. For example, to do the same sort of thing as the above command line on other operating systems assuming that equivalent utilities were available After sufficient practice, you will find yourself routinely typing in powerful command pipelines that do in one line what it would take several commands and temporary files in other operating systems to accomplish.
Pipes are actually a special case of a more general feature: doing more than one thing at a time. UNIX, on the other hand, was developed in a research lab and meant for internal use, so it does relatively little to impose limits on the resources available to users on a computer-as usual, leaning towards uncluttered simplicity rather than overcomplexity.
You do this when you invoke a pipeline; you can also do it by logging on to a UNIX system as many times simultaneously as you wish. The shell also lets you run more than one command at a time during a single login session. This is called running the command in the background, and a command that runs in this way is called a background job; for contrast, a job run the normal way is called a foreground job. When you start a background job, you get your shell prompt back immediately, enabling you to enter other commands.
The most obvious use for background jobs is programs that take a long time to run, such as sort or uncompress on large files. For example, assume you just got an enormous compressed file loaded into your directory from magnetic tape. Compressed files are created by the compress utility, which packs files into smaller amounts of space; they have names of the form filename. Z , where filename is the name of the original uncompressed file.
Z , which is a compressed archive file that contains well over 10 MB of source code files. Type uncompress gcc. Right after you type the command, you will see a line like this:. Those numbers give you ways of referring to your background job; Chapter 8 explains them in detail. You can check on background jobs with the command jobs. The message changes if your background job terminated with an error; again, see Chapter 8 for details.
If a background job needs keyboard input, it will often just sit there doing nothing until you do something about it as described in Chapter 8. If a background job produces screen output, the output will just appear on your screen. Firewall fundamentals - Linux. Multiple domains on a single web server. The Author of the Apache httpd and Tomcat Course.
Linux and httpd file system layout - LAMP server. Using current exchange rates on a web page. Open Source - here to stay, or a flash in the pan?
Handling XML in Java. Overview of Ant - a Java based build tool. Korn Shell - Basics. Korn Shell Scripting - an introduction.
0コメント