How to delete the recursive directory in Solaris.
Directory Structure : SourceCode/unit_test_cases.
The command
cp -rf SourceCode/ SourceCode/unit_test_cases/ : created a recursive directory.
Directory Structure looks like below
SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/
I know "rm -rf SourceCode" is to delete recursively. But this command gives the error File Name too long. This is due to unlimited child directories recursively created.
So am not able delete the directories.
I tried this in Ubuntu, It is smart that it determines the cyclic recursion and breaks # some depth, But Solaris seems to be dumb in this case.
Can anybody help me
It is simply
rm -rf PATHS
where PATHS is one or more PATH to be removed (it's enough SourceCode if you want to remove that dir completely).
Try this
rm -r <your directory>
and be careful of what you are deleting.
Related
This might appear a noob question.
While working in bash, if we run cd ., it stays in the current folder.
I understand the functionality, however, I am not able to understand the rationale of this functionality?
What would be some practical ways to use this?
The primary use case I've seen for cd . is to test whether your file handle on the current directory is still valid.
If you're on a directory from a network share -- NFS, or the like -- it can be possible for directories to be remotely deleted, but for the local client to still believe they're accessible and in use.
cd . is a way to trigger an error if your handle on the current working directory is no longer valid.
This is the only "practical" case that came to my mind
$ cd .
cd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
when your process has a current working directory referencing a directory that has been removed by another process.
That command has no functionality. But in a POSIX-compliant environment, if you add a -P option, then it has functionality: it resolves symlinks. So for example on a Mac, if you cd to a path with a symlink:
cd /System/Library/Frameworks/AppKit.framework/Versions/Current
...then do cd -P . ... you will point to:
/System/Library/Frameworks/AppKit.framework/Versions/C
. is a special file that represents the current directory.
There are plenty of things which make use of directories and it is sometimes useful to refer to the current directory.
Changing the directory to the current directory is not one of those.
A simple example where cd . fails:
mkdir my_error
cd my_error
rm -rf ../my_error
cd .
When the rm is embedded in a difficult script or can be done by some other cleanup process, is can be an useful check.
I use a build script which removes and recreates a directory.
The old directory disappears and new appears with new inode.
If, in one of my shells my $PWD is that reappeared directory and I notice
it became unusable (and I know it was recreated), I just
$ cd .
to get the (new) directory useable again and can continue my work there.
I have large projects and some scripts to compile them. I can't add all code here, so I'll try to simplify the problem: in the cleaning part, I need to clean folder named directory which contains other directory named innerDir. I have this bash command for cleaning directory:
clean:
rm -r -f directory
When directory is a folder that I created with mkdir -p beforehand. When I clean, I get this error:
rm: cannot remove 'directory': Directory not empty
But when I try to enter directory , I see that it's empty. So for debugging, I modified my cleanning part to be:
rm -r -f directory/*
find directory
rmdir directory
(it's suppose to do the same, but here I also get the chance to see if all the content of directory was really deleted).
Now I get this error:
find: 'directory/innerDir': Permission denied
There are two things that unclear for me here:
(1). innerDir was created with makedir -p before the clening part, without any change to the permissions of it later in the code. Why don't I have permission to delete it?
(2). If I try to clean again- the cleaning succeed and I don't have any permission problem. So, if I got permission error in the first time I tried to delete it, why don't I get it in the second time?
If your permissions are valid down the directory tree, rm -fr directory ought to work.
If you don't have read access on innerDir, then is it possible/likely (depending on running processes, perhaps) that something has written to innerDir, but the file gets cleaned up after so that the directory becomes free?
Can you give examples of permissions, ownership, and some scope of the operations happening between each step?
Could you rename the parent folder while working, and/or lock it's permissions to prevent other users or processes from altering things?
I have a folder in my directory called input_files which contains the list of input files. I am trying to delete the contents of this folder using the below command but getting I'm getting an error.
find /u/users/kisri1/scripts/design_matrix/input_files* -type f -delete
Error:
/u/users/kisri1/scripts/design_matrix/input_files: Is a directory
Please help to solve this thing. I want to write a shell script which can access the folder and delete the files.
rm is perfect in your case.
rm -rf /u/users/kisri1/scripts/design_matrix/input_files/* would do the trick and delete all files in your input_files directory without discrimination.
use the lines:
cd /u/users/kisri1/scripts/design_matrix/input_files
rm *
this will delete all files in the directory
I would like to clear out my /bin folder in my project directory. How can I do this?
I tried rm -rf ~/bin but no luck
~ is a shorthand to a current user home directory. So unless it's also your project directory you are doing something wrong. Other than that, clearing a directory would be
rm -rf ~/bin/*
And if you also want to clear the hidden files
rm -rf ~/bin/* ~/bin/.[a-zA-Z0-9]*
Make sure you are not doing
rm -rf ~/bin/.*
especially as root as it will try to clear out your entire system.
UPD
Why? Since wildcard (*) is interpreted by shell as zero or more characters of any kind the .* will also match . (current directory) and .. (parent directory), which will result in going all the way up and then down, trying to remove each file in your filesystem tree.
You should say "... my bin folder", not "my /bin folder". /bin is an absolute path, bin is a relative path.
rm -rf ~/bin removes $HOME/bin, so not what you want either.
Now, it depends on where you are: if you are in your project directory when you type the command, just type rm -rf bin.
rm -rf ~/bin/{*,.[^.]*}
would delete all files and directories in ~/bin/, including hidden ones (name starts with .), but not the parent directory (i.e. ..).
The .[^.]* matches all hidden files and directories whose name starts with a dot, the second char is NOT a dot, and with or without more chars.
How do I remove certain files from a different directory than $PWD using the bash shell script.
Looking at the documentation for rm, it appears that rm only works in $PWD.
Am I forced to use this method:
oDir=$PWD
cd directorytoremovefiles
rm files
cd oDir
rm certainly does work for deleting files in another directory.
Whatever gave you that idea from the man page, I certainly hope it's not this:
rm removes each specified file. By
default, it does not remove
directories.
The documentation you refer to, talks only about having write & execute permission to the directory you are deleting from.
So you only need:
rm directorytoremovefiles/files
As pointed out by YYC,
rm $DIR/files
rm will take any path, relative or absolute. If there is no slash at the beginning of directorytoremovefiles then it is a relative path and you may need to store PWD for later. However, you can do this with pushd and popd or a cd - once you're finished. Or, if you run the cd and rm commands in parens they will run in a subshell, like this: ( cd directory; rm files) then your working shell will not change directory.