Sponsored Content
Full Discussion: Remove symlink and target
Top Forums UNIX for Dummies Questions & Answers Remove symlink and target Post 302947064 by Don Cragun on Monday 15th of June 2015 04:35:38 AM
Old 06-15-2015
Quote:
Originally Posted by Skrynesaver
Test with the following and remove echos if it does what you require
Code:
 for i in my_directory/* ; do if [ -L $i ] ; then echo rm $(readlink $i) ; fi done; echo rm -r my_directory

Note that rm -r my_directory will remove the entire file hierarchy rooted in my_directory, but the for loop will only look for symlinks in my_directory; not for symlinks in subdirectories of my_directory.

Note also that symlinks can contain absolute pathnames or relative pathnames. If a symlink contains a relative pathname, rm "$(redline $i)" won't work unless you execute that command while your current working directory is the directory in which the symlink is located.

In the example given, all of the symlinks contain absolute pathnames and the symlinks shown only appear in the named directory; so Skrynesaver's suggestion should work fine for the given example. But, if the OP's real world conditions are different, the code will need to be more complex.
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

creating symlink

hi... I have a folder<abc> under /root folder. I want to create a symlink such that when i click on folder<abc> under root, should display my home folder (home/krish). Immediate inputs appreciated..... (1 Reply)
Discussion started by: rama.honge
1 Replies

2. Solaris

symlink on link file

Hi all, I want to create a symlink on a link file, i mean, there is a file which is actually a symlink of some version. Now i want to create one more symlink on that link file. EX: there is a file: uat -> version prod -> version Now i want to create one more link on these 'uat' and... (1 Reply)
Discussion started by: raghu.iv85
1 Replies

3. UNIX for Dummies Questions & Answers

how to copy a file without remove the contents of the target file?

Hello every body, Kindly support me to "copy a file without remove the contents of the target file" Thanks in advance. :) Ahmed Amer Cairo,Egypt (2 Replies)
Discussion started by: ahmedamer12
2 Replies

4. Shell Programming and Scripting

how to remove the target of the symbol link in a shell script

I have a target directory, there are some files and directories in "target_dir". I have a symbol link: my_link -> <target_dir> The target directory name is NOT known to the script (because it is varying), while the link name is always fixed. In a shell script, how to remove both the... (1 Reply)
Discussion started by: princelinux
1 Replies

5. Shell Programming and Scripting

ln -s creates symlink in symlink, if [ -f ... ] says file that exists doesn't exist

Hi Forums, I got a little problem, I made a few modifications to the code of the launch script of a testing server(minecraft) and now updating is broken aswell as the automatic directory creation. These Lines somehow create an endless symlink that refers to itself and I don't know how to fix... (0 Replies)
Discussion started by: Xaymar
0 Replies

6. Red Hat

how to hide the path users on the symlink.

Hello, can someone please suggest or is it possible to hide the path for the link from viewing it from remote users. for examples. as root user login #ls -l lrwxrwxrwx 1 root root 43 Oct 2 16:05 sftpdata -> /data/sftphome/sftpuser1/sftpdata/ #pwd /home/user1 # when user1 logs... (4 Replies)
Discussion started by: bobby320
4 Replies

7. Ubuntu

Creating conditional symlink

Hi All, Is there any way to create a symlink that will point to last 1000 line of a log file. My symlink will always point to "tail -1000 logfile". This can be achieved by writing a script and scheduling with high frequency, but I am looking for some other alternatives. Please let me know... (8 Replies)
Discussion started by: sussus2326
8 Replies

8. HP-UX

After adding new iscsi target port, still the session state of that target port is showing offline

Hi, I wanted to configure new iscsi port on HPUX system, i added the target port address and configured it, once done, went to array side and searched for that host iqn number , but was nt able to find the same, came to host, then when i ran "iscsiutil -pVS" command it gave me below result ... (0 Replies)
Discussion started by: Vinay Kumar D
0 Replies

9. Shell Programming and Scripting

Symlink creation

I am trying to setup my plex server to use symlinks rather than host the movie files. in my storage directory, i have both movies(some in subdirectory of the name and some just in the parent directory) and tvshows, which have subdirectories for each season, which contains the episodes i would... (3 Replies)
Discussion started by: bandion
3 Replies

10. UNIX for Beginners Questions & Answers

Symlink

I know how to create a symlink but I am getting an error message that the file already exists. Also, my symlink doesn't point from target directory to the path correctly, Here is an example of the path to my folder structure path: cd /wkspce/wff/DEV/jobs/DEL the folder structure is: ... (3 Replies)
Discussion started by: dellanicholson
3 Replies
libssh2_sftp_symlink_ex(3)					  libssh2 manual					libssh2_sftp_symlink_ex(3)

NAME
libssh2_sftp_symlink_ex - read or set a symbolic link SYNOPSIS
#include <libssh2.h> #include <libssh2_sftp.h> int libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, char *target, unsigned int target_len, int link_type); DESCRIPTION
Create a symlink or read out symlink information from the remote side. sftp - SFTP instance as returned by libssh2_sftp_init(3) path - Remote filesystem object to create a symlink from or resolve. path_len - Length of the name of the remote filesystem object to create a symlink from or resolve. target - a pointer to a buffer. The buffer has different uses depending what the link_type argument is set to. LIBSSH2_SFTP_SYMLINK: Remote filesystem object to link to. LIBSSH2_SFTP_READLINK: Pre-allocated buffer to resolve symlink target into. LIBSSH2_SFTP_REALPATH: Pre-allocated buffer to resolve realpath target into. target_len - Length of the name of the remote filesystem target object. link_type - One of the three previously mentioned constants which determines the resulting behavior of this function. These are convenience macros: libssh2_sftp_symlink(3) : Create a symbolic link between two filesystem objects. libssh2_sftp_readlink(3) : Resolve a symbolic link filesystem object to its next target. libssh2_sftp_realpath(3) : Resolve a complex, relative, or symlinked filepath to its effective target. RETURN VALUE
When using LIBSSH2_SFTP_SYMLINK, this funtion returns 0 on success or negative on failure. When using LIBSSH2_SFTP_READLINK or LIBSSH2_SFTP_REALPATH, it returns the number of bytes it copied to the target buffer (not including the terminating zero) or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. From 1.2.8, LIBSSH2_ERROR_BUFFER_TOO_SMALL is returned if the given 'target' buffer is too small to fit the requested object name. BUG
Passing in a too small buffer when receiving data only results in libssh2 1.2.7 or earlier to not copy the entire data amount, and it is not possible for the application to tell when it happens! ERRORS
LIBSSH2_ERROR_ALLOC - An internal memory allocation call failed. LIBSSH2_ERROR_SOCKET_SEND - Unable to send data on socket. LIBSSH2_ERROR_SOCKET_TIMEOUT - LIBSSH2_ERROR_SFTP_PROTOCOL - An invalid SFTP protocol response was received on the socket, or an SFTP operation caused an errorcode to be returned by the server. SEE ALSO
libssh2_sftp_init(3) libssh2 0.15 1 Jun 2007 libssh2_sftp_symlink_ex(3)
All times are GMT -4. The time now is 09:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy