[opensuse] deleting soft links
Hello: How can I delete only soft link files from a directory using the command line? I have too many files to delete them one by one. TIA, IG ________________________________________________________ VÁSÁROLJON ONLINE! Ezzel a kártyával nem húzzák le! http://www.klikkbank.hu -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Jan 2, 2008 2:05 PM, Istvan Gabor <suseuser04@freemail.hu> wrote:
Hello:
How can I delete only soft link files from a directory using the command line? I have too many files to delete them one by one. man find and man xargs should help you.
ne... -- Registered Linux User # 125653 (http://counter.li.org) Certified: 75% bastard, 42% of which is tard. http://www.thespark.com/bastardtest Now accepting personal mail for GMail invites. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Wednesday 02 January 2008 15:05, Istvan Gabor wrote:
How can I delete only soft link files from a directory using the command line? I have too many files to delete them one by one.
find . -type l -print0 | xargs -0 rm simpler, but more dangerous if the names contain weird characters: find . -type l | xargs rm (not recommended!) In any case, try it with "echo" first instead of "rm" so you can get an idea what will happen. CU -- Stefan Hundhammer <sh@suse.de> Penguin by conviction. YaST2 Development SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) Nürnberg, Germany -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
How can I delete only soft link files from a directory using the command line? I have too many files to delete them one by one.
find . -type l -print0 | xargs -0 rm
simpler, but more dangerous if the names contain weird characters:
find . -type l | xargs rm (not recommended!)
In any case, try it with "echo" first instead of "rm" so you can get an idea what will happen.
Thank you all for the answers. I'll try this way. Thanks again, IG ________________________________________________________ VÁSÁROLJON ONLINE! Ezzel a kártyával nem húzzák le! http://www.klikkbank.hu -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Wednesday 02 January 2008 06:39, Stefan Hundhammer wrote:
On Wednesday 02 January 2008 15:05, Istvan Gabor wrote:
How can I delete only soft link files from a directory using the command line? I have too many files to delete them one by one.
I should point out (and I hope I'm not too late) that there's an ambiguity in your (Istvan's) question (and / or a discrepancy with Stefan's suggested recipe): You ask about deleting symbolic links "from a directory." Stefan's recipes will target all symlinks found anywhere within the entire directory hierarchy rooted at the first argument (all arguments to find that precede the first option are file or directory names to use as starting points for traversing the file system hierarchy.) If you want to limit the operation to a single directory, add the "-maxdepth 1" option: % find directoryName -maxdepth 1 -type l -print0 |xargs -0 rm Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Wednesday 02 January 2008 07:32, Randall R Schulz wrote:
...
If you want to limit the operation to a single directory, add the "-maxdepth 1" option:
% find directoryName -maxdepth 1 -type l -print0 |xargs -0 rm
Separately, you might want to run the command once first without the -print0 and the xargs in the pipeline just to get a list of the files that will be affected: % find . -type l You could save this to a file and inspect or save it or you could just pipe it to "less" to view it directly. If you want to see the targets of the links as well as the links, do this: % find . -type l -print0 |xargs -0 ls -l (Again, send to a file or pipe through "less.") Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
If you want to limit the operation to a single directory, add the "-maxdepth 1" option:
% find directoryName -maxdepth 1 -type l -print0 |xargs - 0 rm
Separately, you might want to run the command once first without the -print0 and the xargs in the pipeline just to get a list of the files that will be affected:
% find . -type l
You could save this to a file and inspect or save it or you could just pipe it to "less" to view it directly.
If you want to see the targets of the links as well as the links, do this:
% find . -type l -print0 |xargs -0 ls -l
(Again, send to a file or pipe through "less.")
Randall, thanks for your notes. I will be careful when I will use the command. Thanks, IG ________________________________________________________ VÁSÁROLJON ONLINE! Ezzel a kártyával nem húzzák le! http://www.klikkbank.hu -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Istvan Gabor wrote:
Hello:
How can I delete only soft link files from a directory using the command line? I have too many files to delete them one by one.
I don't know of any command that will do that, though you could build a script around find, with the type or xtype tests, to find the files to delete. -- Use OpenOffice.org <http://www.openoffice.org> -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
James Knott wrote:
Istvan Gabor wrote:
Hello:
How can I delete only soft link files from a directory using the command line? I have too many files to delete them one by one.
I don't know of any command that will do that, though you could build a script around find, with the type or xtype tests, to find the files to delete.
Jim, you need to learn the power of the pipe. (No, not *THAT* pipe...the other one...) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hi guy, You can use the command unlink .....I think. Regards Kalvin Weng AT&S (China) Co.,Ltd Tel.: +86 21 24080509 Email: k.weng@cn.ats.net Aaron Kulkis <akulkis00@hotpop .com> To opensuse <opensuse@opensuse.org> 2008-01-03 09:22 cc Subject Re: [opensuse] deleting soft links James Knott wrote:
Istvan Gabor wrote:
Hello:
How can I delete only soft link files from a directory using the command line? I have too many files to delete them one by one.
I don't know of any command that will do that, though you could build a script around find, with the type or xtype tests, to find the files to delete.
Jim, you need to learn the power of the pipe. (No, not *THAT* pipe...the other one...) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org This e-mail and any attachment may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday 03 January 2008 07:13, Kalvin Weng wrote:
You can use the command unlink .....I think.
No. That's something different. The "unlink" command provides direct access to the unlink() system call. It is what the "rm" and "rmdir" commands ultimately call, but with some safeguards on the way. The "unlink" command is not intended for general use; use "rm" or "rmdir" instead. Both the "unlink" command and the unlink() system call deal with hard links(!). They don't know anything about symlinks. To the system, each file or directory is identified with an "i-node" which has an "i-number". File names and directory paths are just there for us mere mortals who have a hard time remembering 32 bit i-numbers to identify a file or directory. ;-) http://en.wikipedia.org/wiki/Inode http://en.wikipedia.org/wiki/Hard_link http://en.wikipedia.org/wiki/Symbolic_link From "info unlink": "12.8 `unlink': Remove files via the unlink syscall ================================================== `unlink' deletes a single specified file name. It is a minimalist interface to the system-provided `unlink' function. *Note Deleting Files: (libc)Deleting Files. Synopsis: It avoids the bells and whistles of the more commonly-used `rm' command (*note rm invocation::). unlink FILENAME On some systems `unlink' can be used to delete the name of a directory. On others, it can be used that way only by a privileged user. In the GNU system `unlink' can never delete the name of a directory. ..." From "man 2 unlink": "NAME unlink - delete a name and possibly the file it refers to SYNOPSIS #include <unistd.h> int unlink(const char *pathname); DESCRIPTION unlink() deletes a name from the filesystem. If that name was the last link to a file and no processes have the file open the file is deleted and the space it was using is made available for reuse. If the name was the last link to a file but any processes still have the file open the file will remain in existence until the last file descriptor referring to it is closed. If the name referred to a symbolic link the link is removed. If the name referred to a socket, fifo or device the name for it is removed but processes which have the object open may continue to use it. ..." -- Stefan Hundhammer <sh@suse.de> Penguin by conviction. YaST2 Development SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) Nürnberg, Germany -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (7)
-
Aaron Kulkis
-
Istvan Gabor
-
James Knott
-
Kalvin Weng
-
ne...
-
Randall R Schulz
-
Stefan Hundhammer