ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
~/tmp $ ll *
-rw-r----- 1 fukawi1 fukawi1 0 Dec 29 02:28 1.html
-rw-r----- 1 fukawi1 fukawi1 0 Dec 29 02:28 2.html
-rw-r----- 1 fukawi1 fukawi1 25 Dec 29 02:24 3.html
-rw-r----- 1 fukawi1 fukawi1 0 Dec 29 02:24 test
-rw-r----- 1 fukawi1 fukawi1 22 Dec 29 02:24 tmp
1:
total 4.0K
-rw-r----- 1 fukawi1 fukawi1 0 Dec 29 02:27 2.html
-rw-r----- 1 fukawi1 fukawi1 25 Dec 29 02:28 3.html
2:
total 16K
-rw-r----- 1 fukawi1 fukawi1 38 Dec 26 22:51 1.html
-rw-r----- 1 fukawi1 fukawi1 25 Dec 26 22:51 2.html
-rw-r----- 1 fukawi1 fukawi1 25 Dec 26 22:51 3.html
-rw-r----- 1 fukawi1 fukawi1 0 Dec 26 22:51 test
-rw-r----- 1 fukawi1 fukawi1 22 Dec 26 22:51 tmp
~/tmp $ rm -rf 1 1.html 2.html
~/tmp $ ll *
-rw-r----- 1 fukawi1 fukawi1 25 Dec 29 02:24 3.html
-rw-r----- 1 fukawi1 fukawi1 0 Dec 29 02:24 test
-rw-r----- 1 fukawi1 fukawi1 22 Dec 29 02:24 tmp
2:
total 16K
-rw-r----- 1 fukawi1 fukawi1 38 Dec 26 22:51 1.html
-rw-r----- 1 fukawi1 fukawi1 25 Dec 26 22:51 2.html
-rw-r----- 1 fukawi1 fukawi1 25 Dec 26 22:51 3.html
-rw-r----- 1 fukawi1 fukawi1 0 Dec 26 22:51 test
-rw-r----- 1 fukawi1 fukawi1 22 Dec 26 22:51 tmp
~/tmp $
rm can be passed a list of files to be deleted, by a space delimted list. as shown above.
Where my rm command, has removed the subdirectory "1" and the files "1.html" and "2.html" but left the rest of the files in tact.
Is that what you were looking for?
What specifically are you trying to achieve?
**Edit** Keeping in mind, that -rf equates to
-r = Recursive (including all subdirectories)
-f = Force (do not ask questions)
it would be advisable to familiarise yourself with these commands, because a simple type can have disasterous results, particularly if running as root.
I in no way intend to undermine your knowledge or intelligence, but for any others who may chance upon the thread.
The difference a space can make between
Code:
rm -rf *.html
and
Code:
rm -rf * .html
^ note space here
Could have less disastrous effects on the expected results.
If you're just talking about changing the order of the input options of whatever command you're using, then no, most programs won't allow it. You almost always have to put option flags that start with "-" before the main argument list.
This is just the traditional standard practice, however. Every program actually handles its own input with its own internal programming. So you may occasionally find programs that can allow such variations. You'll also find others that are even stricter than the norm.
Remember that in the end bash is just the program launcher. It simply parses the line first according to its own shell syntax, assembles whatever it finds into a final command string, and tells the system to execute it (assuming it's an external command). What happens next is up to the program launched.
OTOH, you may actually be talking about writing a shell script with option flags. If so, bash has a built-in getopts command for handling "-o value" style short options.
If you want long-style "--option=value" options too, then you have to use the trickier-to-handle external getopt application, or write your own input parser. (I used to have a link on getopt, but I can't find it now. Google it if you're interested.)
( -a is the option, and TestFile is the target)
The target is $2, so the order can't be rearrange, or it will encounter an error, right?
Rearrange means:
This is just the traditional standard practice, however. Every program actually handles its own input with its own internal programming. So you may occasionally find programs that can allow such variations. You'll also find others that are even stricter than the norm.
I second this. One example is the ls command on Linux (but not on AIX), where you can put options also after the list of files. If you want to implement such a behavior, you could scan the complete list of arguments and build two lists: one for options and one for the real arguments and handle it appropriate this way.
Many programs also allow a to use a double dash (i.e. a “--”) to end the list of options, whether following arguments are starting with a dash or not, they are handled as plain arguments only, e.g:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.