I want to execute ANT delete target, so that I can delete all files in the directory that mach some criteria:
<delete quiet="true">
<fileset dir="${java.io.tmpdir}" includes="soapirp*.log*"/>
</delete>
it does not work, I think it happens because ant is trying to invoke unix rm -f command which supposed to delete file without asking me to confirm the deletion, but this does not work, i tested it by running
rm - f filename
it still prompts me for the confirmation the only way I made it work by running:
/usr/bin/rm -f filename
then eveyting works as expected , I need to tell the ant to use the different version of rm I guess but how ??
ant uses the Java File API to delete files, not rm. Your problem must be elsewhere.
(and there must be no space between - and f).
Related
Here is the step i'm trying to improve - it removes all files/directories except .git.
- name: Clear Working directory
continue-on-error: true
run: |
rm -fr . .eslintrc.json .gitignore .stylelintrc .github
The small problem here is that anytime I add a hidden .file the action would need to be updated and I would like a more permanent solution.
My attempts have used ! and () which have proven unsucessful because they are not allowed as part of a bash command even after running shopt -s extglob.
I have considered writing a bash script but that is something that would need to be commited to the repo which seems less than optimal or writing my own action which also seems unnecessary when it's something that should be doable with one line in a unix bash shell.
I have to delete a number of files with names like "test excel-27-03-2016.xls" from a directory on a Unix machine. Can you please suggest how? I tried using command
rm -f test excel-27-03-2016.xls
but it is not deleting the file.
Does the name of the file contains a space? It seems so.
If this is the case, rm -f "test excel-27-03-2016.xls" (note double quotes around the file name) ought to do it.
Running rm -f test excel-27-03-2016.xls means trying to erase two files, one named test and the other excel-27-03-2016.xls.
So if 'test excel-27-03-2016.xls' is one filename, you have to escape the space in the rm command.
rm test\ excel-27-03-2016.xls
or
rm 'test excel-27-03-2016.xls'
otherwise rm will think 'test' and 'excel-27-03-2016.xls' are two different files.
(Also you shouldn't need to use -f.)
For a single file, if the file name contains spaces, you have to protect those spaces. By default, the shell splits file names (arguments in general) at spaces. So, enclose the name in double quotes or single quotes:
rm -f "test excel-27-03-2016.xls"
or use a backslash if you prefer (but I don't prefer backslashes; I normally use quotes):
rm -f test\ excel-27-03-2016.xls
When a delete operation doesn't work, the -f option to rm becomes your enemy; it suppresses the error messages that rm would otherwise give. For example, without the -f, you might see:
$ rm test excel-27-03-2016.xls
rm: test: No such file or directory
rm: excel-27-03-2016.xls: No such file or directory
$
That tells you that rm was given two names, not one as you intended.
From a comment:
I have 20-30 files; do I have to give rm 'test excel-27-03-2016.xls" each time and provide "Yes" permission to delete file?
Time to learn wild-cards. First thing to learn — Be Careful! Do not destroy files carelessly.
Run a command such as:
ls -ld *.xls
Does that list the files you want deleted — all the files you want deleted and nothing but the files you want deleted? If it doesn't contain any extra file names (and no directory names), then you can run:
rm -f *.xls
If it doesn't contain all the file names you need deleted, but it does contain only names that you need deleted, then run the rm to reduce the size of the problem, then devise an alternative pattern to delete the others:
ls -ld *.xlsx # Semi-plausible
If it contains too many names, you have a couple of options. One is to use rm interactively:
rm -i *.xls
and respond yes to those that should be deleted and no to those that should be kept. Another is to work out a more precise wildcard, perhaps *-27-03-2016.xls.
When using wild-cards, the shell keeps file names as single arguments, so the fact that the generated names have spaces in them isn't a problem. Be aware that many shell techniques, such as capturing that list of file names in a variable, do not preserve the spaces properly — a cause of much confusion.
And, with any mass file removal, be very careful. The Unix system will not stop you doing immense damage to your files It will take you at your word — if you say 'remove everything', it will try to do so.
From another comment:
I have taken root access so I will have all permissions.
Don't run as root when you have problems working out what you are doing. Running as root means that any mistake has the potential to be dramatically more devastating than if you run as yourself.
If you are running as root, the -f option to rm really isn't needed (unless someone has attempted to protect you by creating an alias for the rm command).
When you're root, the system does what you tell it to do. root: Remove the kernel. system: Yes, sir! Right away, sir! root: Remove the complete root file system. system: Yes, sir! Right away, sir!
Be very, very careful when running as root. It is a bad idea to experiment when running as root. It is very important to know exactly what you plan to do as root, to gain root privileges and do what you plan to do, and then lose the root privileges as soon as possible. Use sudo (or su) to temporarily gain root privileges.
My problem is in two parts:
My team and I are using an Test Design Studio to write .vbs files in a Accurev Workspace. The problem is that Accurev recognize them as binaries instead text/ptext files... which causes problems when merging. Is there a setting in Accurev I can change to force it to recognize .vbs files as text/ptext?
All those binaries that are already in the stream, I need solution to convert them all into text/ptext. I've given up on the Client UI, because it means I'd have to go in the Workspace explorer and go through every single folder, one by one, and keep those binaries. Then I thought of the commands. I tried
2.1. accurev keep -c "keep ptext" -n -E ptext -R target_folder
2.2. accurev keep -c "keep ptext" -n -E ptext -R .
2.3. But I get a No Element Selected. That's because the "-n" flag is required for recursive, but it means it'll ignore non-modified files... and most of my files are backed and not modified... otherwise I can't even select the directory for keeping (I'll report "can't keep a directory"). I could create a file-list, but it would take as long as manually keeping all the files one by one. I also tried if I could work directly in the stream (since it has another empty stream above, it lists all it's files as outgoing), but I do not have the keep option in the stream. Is there an easy way to convert all files in stream/workspace as text/ptext?
Yes, you will need to enable a pre-create-trigger using the elem_type.pl script found in "accurev install dir/examples" on your server. Inside the elem_type file, you will see the directions for setting this trigger.
Yes, run the following command to generate a list of all the files in your workspace.
"accurev stat -a -ffl > list.txt"
Then run the this command to convert the files to ptext:
"accurev keep -c "ptext conversion" -E ptext -l list.txt"
Then you can promote those files.
Check the files with a hex editor to see if there are any non-ASCII characters.
If there's binary content in the file AccuRev will see those files as binary.
Overwrite the keep as jstanley suggested to change the type.
On the add use "accurev add -E ptext -c "your favorite comment" file.vbs
My Qt application for Nokia N9 stores some data in the my folder inside /home/user/.config.
I need to delete this folder with my data when application will be uninstalled.
As far as I understand this can be reached using postrm file.
I use the following file:
postrm
#!/bin/sh
rm -rf /home/user/.config/mydatafolder/
exit 0
But this code doesn't work. I assume there's not enough right to remove something in the user's folder.
So, I've tried to use
devel-su user -c "rm -rf /home/user/.config/mydatafolder/"
But it works only in developer mode and I need the app to work properly without it. The following code doesn't work too:
su user -c "rm -rf /home/user/.config/mydatafolder/"
Does anybody know how to remove this folder?
Ok, I've solved this.
You don't need to use su or su-devel in this case. All pre/post rm/install scripts are running by 'root' by default.
To make those scripts running by 'user' we simply need to add following strings to the aegis manifest file:
<request context="INSTALL">
<credential name="UID::user" />
<credential name="GID::users" />
</request>
How does one use rm to delete a file named '--help'? When I try, it just shows the help prompt.
I ended up opening a file browser to delete it.
Two approaches:
rm ./--help
rm -- --help
This latter approach is supported by many common UNIX tools (-- means "end of options" by convention, ie. that everything else will be a positional parameter), and is particularly handy in a script, when you don't know what data you'll be dealing with.
The rm command will accept '--' to tell it not to process any more options.
rm -- '--help'