- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- delete everything and check whether everything is ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 03:43 PM
тАО12-18-2008 03:43 PM
How Can I delete everything from directory
( including hidden files, system files, ready only, .extension **Nothing should be there at all).
and after deleting I need to check also to make sure everything is working fine and there is nothing left. If there are something which I cant delete then I have to send mail to my email address.
I am trying so many things but nothing is completely working. I believe there is a way to do these things efficiently.
Thanks In Advance
I will appreciate any help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 04:59 PM
тАО12-18-2008 04:59 PM
Re: delete everything and check whether everything is deleted or not
Use this very carefully as root and *nothing* including the directory will be left...and there will be no need to check:
# rm -rf /path
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 06:56 PM
тАО12-18-2008 06:56 PM
Re: delete everything and check whether everything is deleted or not
If you want to keep the directory its self, you could use JRF's method then recreate the empty dir or
rm -rf /dir/*
rm -rf /dir/.* (to remove hidden files)
>>>> and after deleting I need to check also to make sure everything is working fine and there is nothing left. If there are something which I cant delete then I have to send mail to my email address.
You need to count the files or check for file left in the directory after the delete. shouldnt be too hard.
if [[ -f /dir/* ]] (or something similar)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 07:00 PM
тАО12-18-2008 07:00 PM
Re: delete everything and check whether everything is deleted or not
if [[ $path != "/" ]] Just an idea....
then
rm -rf /$path/*
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 09:59 PM
тАО12-18-2008 09:59 PM
Re: delete everything and check whether everything is deleted or not
You don't want that, that will remove the parent directory.
Better to remove the whole directory as JRF said, rather than make this mistake.
This should work: ll ..?* * .[_0-9A-z]*
But this won't find ".+", unless added above.
\ls -a /dir | fgrep -x -v -e . -e ..
Will exclude "." and "..".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 11:00 PM
тАО12-18-2008 11:00 PM
Re: delete everything and check whether everything is deleted or not
ll .[!.]* ..?* *
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-19-2008 08:04 AM
тАО12-19-2008 08:04 AM
Re: delete everything and check whether everything is deleted or not
U R right but I cant remove the directory itself. I dont have privilege to delete and make another one. Only thing I can do here is I can delete whatever is inside the directory and its must for me I have to make it empty in any case and put new files there.
Dennis,
>> ll .[!.]* ..?* * --> is this for testing whether anything is left in the directory? or have to use with rm -rf to remove everything?
that means to remove everything
rm -rf dir/*
rm -rf dir/.*
will work?
Im confused. Could U plz help me.
thanks alot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-19-2008 09:41 AM
тАО12-19-2008 09:41 AM
Re: delete everything and check whether everything is deleted or not
if you are saying you only want to delete the files within the directory that you own, as opposed to those that are there and you can access, that's something else altogether.
It would help if you clearly explained precisely what is is you need to accomplish (ie a statement of the end result rather than the actions you want to do to get there)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-19-2008 10:19 AM
тАО12-19-2008 10:19 AM
Re: delete everything and check whether everything is deleted or not
I need this coz I am trying to delete the old contains of directories and paste new version of files in it.
the script I have tried is
rm -rf ${dest_dir}/*
rm -rf ${dest_dir}/.*
if [[ ll .[!.]* ..?* * |wc -l != 0 ]]; then
echo "! Tar Error!! Scipt is not able to delete ${dest_dir} in ${DHOST} server while code push \n"|mail -x "Urget Tar Error" support@gmail.com
exit
else
echo "${dest_dir} is empty now U can proceed \n"
fi
But I am not sure about my code but I believe there is a better way to write it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-19-2008 06:40 PM
тАО12-19-2008 06:40 PM
SolutionThat may make it easier. Just "rm -rf" the directory, then only the last step will fail. Then check to see if there is anything left in it. (Make sure you try it first to see if it never starts because of the permissions.)
> ll .[!.]* ..?* * --> is this for testing whether anything is left in the directory? or have to use with rm -rf to remove everything?
Both.
>that means to remove everything
rm -rf dir/*
rm -rf dir/.*
No, exactly as I had:
rm -rf dir/* dir/.[!.]* dir/..?*
>I just want to delete the contents of the directory including (hidden files, read only, system files)
There is no such thing as system files as a file property. Hidden files are just a shell and ls(1) convention.
>I don't have permission to delete those I should send email to admin or responsible person
If the rm exit status is bad, you can send a message. But you may want to check the ls output for a more positive check. ls -R would actually list the files in question too.
>if [[ ll .[!.]* ..?* * |wc -l != 0 ]]; then
I doubt this works. You need to test this:
lines=$(ls -a ${dest_dir} | wc -l)
If there is nothing there, you may still see one line, or 3 for . and ..? If so, adjust the number below.
if [ "$lines" -gt 1 ]; then
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-20-2008 05:35 PM
тАО12-20-2008 05:35 PM
Re: delete everything and check whether everything is deleted or not
This is easy to determine before you start. You cannot delete *anything* in a directory where your userID and groupID do not have write access. Here is are the rules:
- A file's permission controls the contents of the file.
but
- The directory's permission control the existence of any files or subdirectories.
If you have write permission in a directory, then you can remove or rename anything in the directory. There may be a file in the directory that is owned by root and has permission 600 - you cannot read or write that file, but if you can write to the directory, you can remove that file. Same for directories inside that directory.
The one exception is if the directory has the "sticky" bit set. This is a special setting that is often used on 777 directories like /tmp and /var/tmp. Rather than allow a free-for-all setting where anyone can trash the contents of an open directory, the sticky bit requires that the user removing or renaming a file in that directory actually own that file or the directory with the file in it.
To see if the sticky bit is set, use this command on the directory:
ll -d /path_to_directory
A typical setting for /tmp would be drwxrwxrwx but with the sticky bit set, the permissions will be drwxrwxrwt (the "t" specifies this option).
> including hidden files, system files, ready only, .extension ...
These are PC concepts and don't apply in Unix. A hidden file is nothing more than a file or directory name that starts with a period ".". It is not really hidden -- shell and other file listing tools like ls and ll will by default, not show dot files and directories. That ends the 'special' meaning for filenames. Most sysadamins will alias ls and ll to always set the -a option to always show dot files. Note that the current (pwd) and parent directory have the names: . and .. which will show up with ll -a.
Read-only for files is not meaningful for removal, and extensions have no special meaning in HP-UX.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-20-2008 05:55 PM
тАО12-20-2008 05:55 PM
Re: delete everything and check whether everything is deleted or not
> that means to remove everything
> rm -rf dir/*
> rm -rf dir/.*
> will work?
rm -rf dir/* is OK for files without a leading dot.
rm -rf dir/.* is very bad! The ".*" pattern match will return all dot files INCLUDING the current directory *and* the ".." or parent directory. To see what .* matches, use these commands:
echo .*
ll .*
Avoid using ".*" as a pattern until you verify all the matches.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-20-2008 10:51 PM
тАО12-20-2008 10:51 PM
Re: delete everything and check whether everything is deleted or not
rm -rf is the command to delete everything
but should careful to use this command.
if u are using always u should present dir
ok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2008 01:09 PM
тАО12-21-2008 01:09 PM
Re: delete everything and check whether everything is deleted or not
> but I cant remove the directory itself. I dont have privilege to delete and make another one.
If you cannot re-create the directory, then you cannot remove it. Thus, the simplest form mentioned at the beginning:
rm -rf /path_to/my_directory
will remove everything in the directory and return an error message that it cannot delete my_directory. If my_directory is indeed removed, then you have the ablity to run mkdir my_directory and put the directory back again. As mentioned above, you cannot delete files or directories unless you can write to the parent directory. If you can't make another directory then you cannot remove it either.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2008 05:46 AM
тАО12-22-2008 05:46 AM
Re: delete everything and check whether everything is deleted or not
cd $DIR.PATH
rm -rf dir
mkdir dir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2008 05:58 AM
тАО12-22-2008 05:58 AM
Re: delete everything and check whether everything is deleted or not
#!/bin/sh
dirpath=/path/to/directory
chmod -R 666 $dirpath
rm -rf $dirpath
mkdir -p $dirpath
This will make all files recursively writeable and delete the lot then create the directory again (-p just says create the whole tree structure).
This will only work if you own the files or do this as root.
You can extend this by adding a test (like [ -d $dirpath ] after the "rm -rf") to check if the directory is really gone and then add a mail or whatever.
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2008 06:22 AM
тАО12-22-2008 06:22 AM
Re: delete everything and check whether everything is deleted or not
The -f removes them without a query. But you are correct if you don't have write permission to directories.
>chmod -R 666 $dirpath
This isn't going to help if you remove execute permission. Better to use:
chmod -R a+w $dirpath
>This will only work if you own the files or do this as root.
And for the latter, if over NFS, they must be mounted with root as root.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2008 08:14 AM
тАО12-22-2008 08:14 AM
Re: delete everything and check whether everything is deleted or not
Thanks again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2008 08:15 AM
тАО12-22-2008 08:15 AM