Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

December 18, 2018

Can't delete a symbolic link to a Linux directory!!

I've come across this issue once where I wanted to delete a symbolically linked directory (named foo for this example) on a CentOS box using the "rm" command, and I got this error message:

rm: cannot remove `foo/': Is a directory

which was a little frustrating although simple enough to resolve.

The mistake that led to generating this error message is that I used the autocomplete line by using the tab key to finish off the name of the directory, which is fine for most purposes, but in this particular instance of removing a symbolic link, it introduced an undesirable factor which is the forward slash tacked to the end of the directory name.
So the typed command looked like this: rm foo/ instead of just this rm foo

Basically, the RM command in bash refused to unlink the symbolic link because it saw it as a directory with content within.

So just in case someone else comes across this same issue, all you need to do is remove the trailing slash from the end of your command and the rm command will successfully remove your symbolically linked directory without any fuss.

Another approach is to use the "unlink" command followed by the name of your symbolic link and it'll also work just fine. Just note that the "unlink" command also will generate an error if it sees a trailing slash after the directory name.

So the correct syntax for removing a symbolically linked directory is this:

rm foo

Or

unlink foo

Share:

March 07, 2013

October 05, 2011

Logout without killing running Linux jobs

To logout of your *nix bash session without killing your active jobs is simply done by using either the nohup or disown commands which allow you to leave a job or script running even after you logout.

The syntax is simple:

nohup command-name &

Then type exit or CTRL-D to logout as usual

disown [-ar] [-h] [jobspec ...]
Without options, each jobspec is removed from the table of active jobs. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used.

If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a jobspec does not specify a valid job.

Share: