Linux / UNIX: Delete a file

by on January 27, 2006 · 103 comments· LAST UPDATED April 26, 2011

in , ,

How do I delete a file under Linux / UNIX / BSD / AIX / HP-UX operating system?

To remove a file or directory in Linux, FreeBSD, Solaris or Unixish oses use the rm command.

rm command syntax

rm (short for remove) is a Unix / Linux command which is used to delete files from a filesystem. Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). The syntax is as follows:

rm -f -r {file-name}

Where,

  • -f: Forcefully remove file
  • -r: Remove the contents of directories recursively

Remove or Delete a File

To remove a file called abc.txt type the following command:
$ rm abc.txt

To remove all files & subdirectories from a directory (MS-DOS deltree like command), enter:
$ rm -rf mydir

To remove empty directory use rmdir and not rm command:
$ rmdir mydirectory

Read a List of All Files To Delete From a Text File

The rm command is often used in conjunction with xargs to supply a list of files to delete. Create a file called file.txt:
$ cat file.txt
List of to delete:

file1
/tmp/file2.txt
~/data.txt

Now delete all file listed in file.txt, enter:
$ xargs rm < file.txt

Never run rm -rf / as an administrator or normal UNIX / Linux user

WARNING! These examples will delete all files on your computer if executed.

$ rm -rf /
$ rm -rf *

rm -rf (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf / variant of the command, if run by an administrator, would cause the contents of every writable mounted filesystem on the computer to be deleted. Do not try these commands.

See also:

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 103 comments… read them below or add one }

1 abdul khader Naik February 21, 2008 at 11:45 am

Will you please tell me the command(in unux/linux) which delete the content of directory without deleteing the directory itself.
other than rm -rf(it will delete directory too) that i dont want.

Reply

2 user December 7, 2011 at 5:33 am

How to delete a file named -i in UNIX ?

Reply

3 iCyOMiK December 17, 2011 at 3:56 am

rm — -i
read the f*****g manual of rm, you can got it.

Reply

4 nixCraft December 17, 2011 at 4:00 am

See how to delete with file starting with a dash:

rm -- '-i'

Reply

5 Robert Dyke December 18, 2008 at 10:24 pm

To remove all files in a directory:

rm -f path/to/my/directory/*.*

Reply

6 Mad93 June 16, 2009 at 8:02 pm

It should be:

rm -f path/to/my/directory/*

Since in linux files doesn’t need file extension. Also, if you want to remove folders inside you have to add the -r flag.

Reply

7 Suresh June 17, 2009 at 6:52 pm

Hi,

How to remove all the files in a directory except a single file using rm command.

Reply

8 Giri April 21, 2010 at 3:49 pm

i m sure, u might have got the answer by now :)
ANS: rm !()

Reply

9 Sanjit May 15, 2013 at 11:22 am

Giri,

You mean the command should be like this
rm !(myfilename) ?? Is it correct?

Thanks.

Reply

10 ken July 29, 2009 at 7:51 pm

Hi UNIX expert,

For the command referred to, can a user with world-writeable permission uses the command to remove directories in O/S? Can a user remove a whole directory even though he/she does not have world-writeable permission to the files under the directories?

Thank you so much.

Reply

11 Ramin September 11, 2009 at 1:00 pm

How to remove all the files inside a directory but not remove directory using rm command?

Reply

12 biswajit August 27, 2010 at 11:55 am

rm -r dirname

Reply

13 Ramin September 11, 2009 at 1:05 pm

How to remove all the files and directory inside a /usr/local/www/squid/myfolder directory but not remove directory /usr/local/www/squid/ using rm command?

Reply

14 nixCraft September 11, 2009 at 1:19 pm

cd /usr/local/www/squid/myfolder
rm -rf *

Reply

15 romy September 24, 2009 at 1:44 am

how can i delete file alot of file let say 1 million files
rm -f *
Out of memory.

Reply

16 swati November 17, 2009 at 6:45 am

how to delete a file which is being generated on its own.
have deleted the source from which its generating but its still generating the file.
have tried all th commands like rm & rm -f still no effect. please help

Reply

17 poorna February 5, 2011 at 8:55 am

Try with rm -rf filename

Thanks,

Reply

18 Mimor February 27, 2010 at 1:04 pm

$ xargs rm < file.txt
returns multiple errors if there are spaces in your filenames in the file

Reply

19 DevX March 25, 2011 at 12:05 am

all filenames that have spaces must be written like this /dir/”my file”/dir… :)

Reply

20 Bill March 4, 2010 at 11:07 am

Hi,
I’m a linux user, I have a directory called “projects” in which there are number of subdirectories, my problem is that I have a directory called “CVS” in every sub-directory (within “projects”) which I want to delete using CLI (command line interface). Is it possible to use one command (or may be very few commands) to find and delete the “CVS” directory?
Thanks

Reply

21 Charles Dupin de Saint Cyr May 9, 2010 at 1:31 am

Use this:

find /var/www2/ -depth -name ‘CVS’ -exec rm -rf ‘{}’ \; -print

where /var/www2/ is the location you want to recursively go through…

Reply

22 sreenivasulu kaipu March 18, 2010 at 10:06 am

Hi
i need one help. iam having one file in ftp server after processing the file will be chaged how to write that command….

Reply

23 linda April 27, 2010 at 6:30 am

how do i delete a number of txt files from a directory al at once?

Reply

24 nixCraft April 27, 2010 at 7:37 am

rm *.txt

Reply

25 Carol Pominville May 25, 2010 at 2:44 pm

I have a folder, lets call it a. Inside of a, is another folder (b) and some files. What command would I use to delete all the files inside of the a folder, but not touch b?

I tried what I saw above, rm !() but was not sure..i put the name of the path of folder b inside the brackets. I then tried, just the letter b… all to no avail.

Thanks.

Reply

26 vf June 8, 2010 at 1:56 pm

tnx mate

Reply

27 mitesh June 14, 2010 at 12:56 pm

how to remove a read only file in unix?

Reply

28 biswajit August 27, 2010 at 11:56 am

chmod 755 filename
rm filename

Reply

29 lalith sanjaya July 13, 2010 at 1:30 pm

Thanks

it is very helpful to me..

Reply

30 marzi July 15, 2010 at 5:46 pm

How can I delete the content of the file without opening the file?
I used the “echo -n > YOURFILE” but another file with the same name created.

Reply

31 Aram Iskenderian October 23, 2010 at 8:22 pm

That should be

echo “” > filename

Reply

32 Gautam August 19, 2010 at 4:28 am

Hi,
Could someone help me in preparing a script to delete a file from a directory after the completion of a process(Informatica job)?

Thank you.

Reply

33 rick September 20, 2010 at 6:11 am

I am getting an error that says root directory is full. How do I safely remove all the contents of this directory. Do I need to do a copy backup first???
Thanks
Rick

Reply

34 Amit October 4, 2010 at 7:56 pm

I need to deleate some data from the UNIX file but am not able to do that.Can anyone please help me out on this?
Thanks
amit

Reply

35 james February 14, 2011 at 1:26 am

for deleting or writing data in files. follow this
1. type vi “yourfilename”
(now the content in your file will be disply as a word file)
2. now you can use two commands to delete data
a.place the curser in the line, press dd(d twice) to delete one line.
b.place curser in the character and press x to delete character.
nb : for moving (placeing) curser use h, j, k , l .. to go up,down, sides ..

hope this will help you … this is just a basic way
if u want to learn more command to edit files … try search for “unix vi” . there are lots of results avaible there

Reply

36 Neeraj November 22, 2010 at 8:35 pm

you can use rm *.txt

Reply

37 jestin December 17, 2010 at 5:39 am

will you help me to remove files in a directiory created from sept 1 to sept 18 ..??

Reply

38 Aram Iskenderian January 21, 2011 at 5:12 am

Warning: Test this on a NON production computer/server or in a dummy directory before you run it.

This assumes that you want to start the delete process on files that had date
stamp starting 09-10-2010 @ 12:00 AM and ending 09-18-2010 23:59
If not, modify the startdate and enddate accordingly.

#!/bin/sh

startdate=”201009010000″
enddate=”201009182359″
touch -t $startdate ./startdatefiles
touch -t $enddate ./enddatefiles
find ./ -type f -newer ./startdatefiles ! -newer ./enddatefiles -ls

Once you test the above script and find it listing the files that needed to be deleted correctly, add -exec rm “{}” \; argument to complete the task.

You can also modify it to change the startdate and enddate variables programatically and even use this in your crontab to automate the process.

Hope this helps.

Reply

39 steven January 12, 2011 at 12:52 pm

Hi,
I want to create script for the following scenario:

The requirements are as below:-

1.) Create a cash script to remove STDF files with invalid lot ID.
2.) Script to be created > /ebsxe/ebs25/users/test/script
3.) Directory of the files > /ebsxe/ebs25/users/test/STDF4

The examples of files in STDF4:
S_20101202044129_MQB021M_B11P_N.st4__ba5651-s_BTS721L1_BAT
S_20101202031130_MQB010J_Q11P_N.st4__ba5651-s_BTS721L1_BAT
S_20101213061928_2_B11P_N.st4__ba56513-s_S1098C3F_BAT

4.) If the character between 2nd underscore and 3rd underscore (eg:MQB021M, MQB010J, 2) less than 8 character, it must be delete automatically.

Kindly please help.

Reply

40 poorna February 5, 2011 at 8:52 am

Q:What is commnd to delete all the information in file’s with out deleting file in a directory.

I know only with echo command we can delete all the information in one file.
A directory contain 10 files. I need to delete all the information which is in those file and files should be there in that directory with ZERO memory Size.

Thanks & Reards,

Reply

41 nixCraft February 5, 2011 at 11:34 am

Try a shell loop. In this example, cd to /data/files directory and run the command on all .txt files:

cd /data/files
for f in *.txt
do
   >"$f"
done

Reply

42 james February 14, 2011 at 1:14 am

hi, i have a folder, where some production files are automatically creates and after a few time it will be automatically delets. what my job is, to copy down all the new files created before it been deleted … i am facing a problem sometimes i am in otherjobs so i cant copy files. i am losing files. so will anybody here please help me to write a script to copy all the files to another dictionary. which runs in every 15 min. all the files have a common extension “.ser”
thanks in advance

Reply

43 vickram March 24, 2011 at 10:39 am

Hi Experts ,

The comments are really helpful. may i know how to delete files by year?i have one dir containts 33million files. i want to delete it by year start from 2009…plz help

Reply

44 Aram Iskenderian March 25, 2011 at 8:20 am

Hi vickram,

Take a look at my response to another post here by jestin dated January 21, 2011.
All you have to do is just specify the dates.

Reply

45 vickram March 25, 2011 at 9:11 am

Hi Aram ,

U r Great…Thanx alot for ur comment…it works…appriciated

Reply

46 Aram Iskenderian March 25, 2011 at 9:12 am

Thanks for the kind words.
I am glad I was able to help. :-)

Reply

47 Phil Noutsis March 24, 2011 at 11:51 pm

How can I remove a unix file of the type #payroll.txt# ? I tried : rm #payroll.txt#, but it tells me that I have to supply more arguments. Any suggestion?
Thanks,
Phil

Reply

48 Aram Iskenderian March 25, 2011 at 8:23 am

Phil,
The reason you are getting that error is because of the #.

Try the following.
rm \#payroll.txt\# (you can force it not to prompt you by specifying -f)
If you have files with numbers in them, you can always consider ?* wildcards.

Reply

49 Somnath March 28, 2011 at 11:41 am

How can I delete bunch of text file. I want to delete file for perticular range like
xxx24mar2010.txt to xxx30mar2010.txt. Please suggest.

Reply

50 Andrej April 5, 2011 at 10:55 am

Hi,

I have created a long list (>4.000 entries) of redundant files that need to be deleted. Typing the command:
xargs rm < iTunesDeleteList

produces an error message:
xargs: unterminated quote.

I tried to replace spaces with "\ " but it didn't work. What should I do to make it work?Typical entry:
/Users/me/Music/iTunes/iTunes Media/Music/B.B. King/King Of The Blues [Disc 1]/1-23 Don't Answer The Door, Parts One And Two 1.mp3

Thanks,
Andrej

Reply

51 Naushad Farsi April 30, 2011 at 12:24 pm

write a shell program to delete all directory which has been created before a perticular date e.g. 3 rd jun 2010

Reply

52 roland May 21, 2011 at 2:11 am

how can i delete 5 user’s except admin in terminal?

Reply

53 araa June 1, 2011 at 10:13 am

Hello,
I want to display duplicate lines in a file, what command to display ?

Reply

54 Aram Iskenderian July 6, 2011 at 2:48 am

1. Make a copy of the file.
2. Run the following.

$ sort myfile.txt | uniq -uc

Reply

55 Rohit Kumar July 5, 2011 at 12:36 pm

Hi
When i am trying to delete a files using rm,rm -f,rm -rf the files still exists in the directory.. I tried deleting it by changing permissions but not done.. Any help is appreciated

Reply

56 Aram Iskenderian July 6, 2011 at 2:50 am

Try changing user or group ownership using chown for the files in question and then delete them again.

Reply

57 satheesh July 11, 2011 at 6:44 am

How to delete few different files using unix rm command. I want to delte thousands of files which are older than 6 months.
Below i gave the command which i have been using the files. But it does work.
Command:
find /My Dir -name ’1309927_sat_0407.price.xls 131011719_sat_0807.price.xls’ -mtime +180 -exec rm -f {} \;

Please help me.

Reply

58 satheesh July 11, 2011 at 6:45 am

Sry the command is not working for me…

Reply

59 Aram Iskenderian August 11, 2011 at 7:52 pm

Satheesh,

See my post @ January 21, 2011 (scroll up to see it) and modify the startdate and startdate for your usage.

Reply

60 Neelesh August 11, 2011 at 3:00 pm

Hi ,

After ls -lrt in a directory , it will give around 300 files with the most recently created/used file at the bottom. I want to delete the top 120 files from the directory. Can you please help. Thanks :)

Reply

61 Ocean November 23, 2011 at 7:29 pm

I have a problem that I need a solution to.

How can I find the largest file and remove it with naming the file in Linux/Unix?

Any help would be appreciated.

Reply

62 john January 17, 2012 at 9:47 pm

is it possible for rm command to list what files are being deleted without being in interactive mode

for example if I want to delete contents of a directory

rm /directory/*

is there a way to list which files are being deleted WHILE they’re being deleted?

Reply

63 Delete a line from a program February 28, 2012 at 9:34 am

Hi Friends,
I want to delete a particular line in a code in command mode

Reply

64 Aram Iskenderan August 16, 2012 at 4:33 am

While this article discusses deleting files, to answer your question.
Deleting line(s) matching pattern
sed ‘/pattern/d’

If you know the line number already, or you can use cat -n to display it, then delete the lines based on the line numbers.

For example to delete lines 2 and 4 from file example.txt
sed -e ’2d;4d’ example.txt

Reply

65 Total March 14, 2012 at 1:50 am

HI : I need to delete all files named .0001 on my server ? Would this work rm *.0001 ???
thanks ..

Reply

66 Aram Iskenderan August 16, 2012 at 4:41 am

Yes that should work, however, it will delete all *.0001 in the current directory.

Reply

67 koushik April 2, 2012 at 5:08 pm

If the command rm -rf couldn’t delete the file,then what is the other command????

Reply

68 Aram Iskenderan August 16, 2012 at 4:46 am

If you can’t delete a file using rm -f (r not needed unless if you are deleting directories), then sudo rm or su – root and then delete the file.
If that does not work, or if you get Operation not permitted, try unsetting the immutable attribute.
chattr -i file.txt
And then try again.

Reply

69 Shambhu mandal May 4, 2012 at 4:35 am

How to install tar.bz2 and tar.gz2
How to uninstall tar.bz2 and tar.gz2 .
please help me…

Reply

70 Subbu May 11, 2012 at 5:06 am

I want to delete a user in solaris but when trying to delete it is showing that user is already logged in how to delete that user.

Reply

71 manoj June 30, 2012 at 6:32 pm

How to remove “delete” option for file ?

What i mean to say is, even though i am a root user, the file should not have permission even for me to delete it.

Reply

72 Aram Iskenderan August 16, 2012 at 4:39 am

chattr +i myfile
Will prevent anyone including root from deleting the file.

chattr -i myfile
Will remove that restriction.

man chattr for more details.

Reply

73 singularity August 6, 2012 at 8:15 pm

I need to delete a directory with a $ symbol in front of it, using rm commands has not worked any suggestions?

Reply

74 nixCraft August 6, 2012 at 8:18 pm

Try:

rm '$filename-here'

Reply

75 Taekyong November 1, 2012 at 12:21 pm

To remove files without directory, try this.

find | xargs rm

It will remove only file not directory itself.

Reply

76 manoj November 1, 2012 at 4:20 pm

Aram Iskenderan @ Thanks a lot.. This is a new command I got to know..Thank u once again

Reply

77 Aram Iskenderian November 1, 2012 at 7:33 pm

@manoj
You’re always welcome.

Reply

78 WanB December 8, 2012 at 12:19 am

How do u delete files with a ‘r-xr-xr-x’ attribute? Tks.

Reply

79 WanB December 12, 2012 at 4:05 am

Nevermind, able to delete using Putty with root.

Reply

80 manikandan February 6, 2013 at 9:01 am

hey its works for me … thank you bro :)

Reply

81 Rick March 14, 2013 at 12:05 am

Hi,

I want to schedule a cron job with file created by specific user be deleted every night.

Any ideas please?

Reply

82 Aram Iskenderian March 14, 2013 at 1:57 am

@ Rick.
Here is a quick a dirty way to do it.
1. Get a bash script something along this.
#!/bin/sh
rm -f /path/to/file

2. Save the file as something like deletefile.sh
3. Make it executable.
chmod +x deletefile.sh

Make sure the path to file and the file name to be deleted are correct, test before you run this without the -f switch in the script. Run the script manually and see if it is working as expected.

4. Move it to a directory that only you or root has access to it.

4. Schedule it to run in Cron.
crontab -e

Add something like.
0 4 * * * /path/to/script/delefile.sh >/dev/null 2>&1

Remember, Cron syntax is as follows:
1 2 3 4 5
m h d month daypofweek
So the above means the script will run @ 4:00 AM everyday. Change the value accordingly.

Save the Cron tab fail.

Or course you can substitute the script by a oneliner in Cron, but the script gives you the ability to enhance this process and check for errors, ..etc.

Reply

83 Rick March 14, 2013 at 5:20 pm

@ Aram

Thanks for you reply

Can you please tell me what does 2>&1 signify in your cron job and like as I want only specific user files to be deleted like for example files created by user1 only

may be i was not able to get completely from this script.

Reply

84 Aram Iskenderian March 15, 2013 at 2:14 am

@Rick
No problem.
>/dev/null 2>&1 redirects both stdout and stderr to /dev/null to prevent email/tty notification. You can remove that part but expect to see an email every Cron runs the script.
Did you try running the script first before adding it to your crontab?If so, what was the output?
Any errors you see?
If not, then check under what user you added the entry in crontab. If you added it as anyone other than that specific user, then either give write permission to the directory/file (bad idea), or simply add the crontab entry for that specific user.
Either use crontab -u user1 -e And then add the entry, or su user1 and then run crontab -e to add the entry.
Either way, make sure that the script is running under a user that has write access to that file/directory.
If you see errors, please post them here.

Reply

85 Rick March 15, 2013 at 5:18 am

Aram

Thanks a lot for your help. It was tested successfully with your help!!!
I am a newbie, it was of great help to me

Reply

86 Aram Iskenderian March 15, 2013 at 6:16 am

No problem. I am glad it is working for you. If I can be of help, feel free to ask.

Reply

87 Rick March 18, 2013 at 10:50 pm

Aram,

I have another question for you. I want to set a cronjob which should be doing following:
checking a error file if generated every night in a specific directory and if there is one then sending to 5 users email id?

I think this should be done by creating a shell script and scheduling it every night.

Thanks a lot

Reply

88 Aram Iskenderian May 19, 2013 at 7:15 am

Rick,

Looks like my reply to you was held for moderation and was never released. Probably due to usage of example email addresses. I posted another answer. If you have any questions, please let me know.

Reply

89 Aram Iskenderian March 20, 2013 at 2:22 am

Let’s say that your file is named errofile.txt

Your script would look something like the following:
#!/bin/sh
$FILE=”/path/to/errofile.txt” #Change the file name here

if [ -f $FILE ];
then
echo “Error file found. Please see attached” | mutt -a $FILE -s “Error File” — recipient@domain.com recipient2@domain.com recipient3@domain.com recipient4@domain.com recipient5@domain.com
fi

Save the above script in a safe directory and make sure the user that the script will run under will have access to it, name it something like errorfile.sh

Note: To avoid email being rejected, make sure to set .muttrc for that specific user to set envelope from address.
Add the following lines to .muttrc for the user the script will run under (change address@domain.com to the email address to be used.)

set from=”address@domain.com”
set envelope_from=yes

If .muttrc under the home directory for that user does not exist, just add it.
touch .muttrc
nano .muttrc
And then add the above two lines.
Save and close.

Now in your cron, add the entry.
crontab -e

0 1 * * * /path/to/script/errorfile.sh >/dev/null 2>&1

This means that errorfile.sh will run daily at 1:00 AM. Change the time to when you want the script to run.
Save and exit.

Before you do anything, manually test.
If you have any questions, let me know.

Reply

90 Aram Iskenderian May 19, 2013 at 7:13 am

Looks like the original reply was held for moderation, not sure why it was not released. Let me try again.

Rick,

Let’s say that your file is named errofile.txt

Your script would look something like the following:
#!/bin/sh
$FILE=”/path/to/errofile.txt” #Change the file name here

if [ -f $FILE ];
then
echo “Error file found. Please see attached” | mutt -a $FILE -s “Error File” — recipient1 recipient2 recipient3 recipient4 recipient5
fi

Replace each recipient with the full email for each one.
Save the above script in a safe directory and make sure the user that the script will run under will have access to it, name it something like errorfile.sh

Note: To avoid email being rejected, make sure to set .muttrc for that specific user to set envelope from address.
Add the following lines to .muttrc for the user the script will run under (change sender to the email address to be used.)

set from=”sender”
set envelope_from=yes

If .muttrc under the home directory for that user does not exist, just add it.
touch .muttrc
nano .muttrc
And then add the above two lines.
Save and close.

Now in your cron, add the entry.
crontab -e

0 1 * * * /path/to/script/errorfile.sh >/dev/null 2>&1

This means that errorfile.sh will run daily at 1:00 AM. Change the time to when you want the script to run.
Save and exit.

Before you do anything, manually test.
If you have any questions, let me know.

Reply

91 Rick June 3, 2013 at 7:13 pm

Hey Aram,

Thanks for your reply. I am testing this. Will reply you soon with. Actually i do not have permission to install mutt on the machine. So making those things work.

Reply

92 Aram Iskenderian June 3, 2013 at 11:55 pm

Hey Rick,

If you don’t have permissions to install Mutt, then can you check if you have mail, mailx or sendmail (/var/lib/sendmail/)?
Depending on what you have installed, we can modify the script(s) to send the email.

Reply

93 Rick June 4, 2013 at 8:02 pm

Aram,

Yes I do have var/spool.mail ..

can you please let me know how to modify this script. Thanks!

Reply

94 Aram Iskenderian July 8, 2013 at 12:59 am

Hey Rick,

Please excuse this delayed response.
/var/spool/mail access is normal on multi-user system, that is where your email is spooled and processed. I was asking if you have access to any email client software, since you said you don’t have Mutt and don’t have permissions to install it.

If your admin won’t install/allow installation of Mutt, and this is still unresolved, check if you have any of the of the following.
Mail
sendmail

Depending on what you have installed, replace the line that is sending the email to the recipients with one of the following:

If you have mail installed:
Change the line above script that is:

echo “Error file found. Please see attached” | mutt -a $FILE -s “Error File” — recipient1 recipient2 recipient3 recipient4 recipient5

To
gzip -c /path/to/errofile.txt | uuencode /path/to/errofile.txt.gz | mail -s “Error File” recipient1 recipient2 recipient3 recipient4 recipient5 — -f sender@mydomain.com

If you have sendmail installed, then that line becomes.
echo -e “Subject: Error file found. Please see attached” | “(cat /path/to/errofile.txt;uuencode attach.file targ.type) | /usr/lib/sendmail -oi addr@server” -f sender@mydomain.com -t tickets@edgecast.com recipient1 recipient2 recipient3 recipient4 recipient5

Tweak the code as necessary.
Hope this helps.

Reply

95 Aram Iskenderian July 8, 2013 at 1:01 am

Hey Rick,

Please excuse this delayed response.
(Also previous comment was held for moderation, probably because of the email addresses in it)
/var/spool/mail access is normal on multi-user system, that is where your email is spooled and processed. I was asking if you have access to any email client software, since you said you don’t have Mutt and don’t have permissions to install it.

If your admin won’t install/allow installation of Mutt, and this is still unresolved, check if you have any of the of the following.
Mail
sendmail

Depending on what you have installed, replace the line that is sending the email to the recipients with one of the following:

If you have mail installed:
Change the line above script that is:

echo “Error file found. Please see attached” | mutt -a $FILE -s “Error File” — recipient1 recipient2 recipient3 recipient4 recipient5

To
gzip -c /path/to/errofile.txt | uuencode /path/to/errofile.txt.gz | mail -s “Error File” recipient1 recipient2 recipient3 recipient4 recipient5 — -f sender

If you have sendmail installed, then that line becomes.
echo -e “Subject: Error file found. Please see attached” | “(cat /path/to/errofile.txt;uuencode attach.file targ.type) | /usr/lib/sendmail -oi addr@server” -f sender -t recipient1 recipient2 recipient3 recipient4 recipient5

Tweak the code as necessary.
Hope this helps.

Reply

96 Fahad Qureshi October 30, 2013 at 5:39 pm

Thanks

it is very helpful to me..

Regrads,

Fahad Qureshi.

Reply

97 wassim January 6, 2014 at 9:58 pm

hi

plz suggest how to delet a rar file from ftp server.

i use the comand rm -f file name to delet the file but after run this command out put come like
rm: cannot remove `BAMBackup.rar’: Disk quota exceeded.

Reply

98 Rojus June 7, 2014 at 10:26 pm

Hello,

Suppose I have multiple files on a folder and I want to delete only the files that contains the word ‘hello’. How to do it ? Thank you

Reply

99 Aram Iskenderian June 7, 2014 at 11:18 pm

There are several ways to do that, the easiest way is to use find.
First make sure you see the expected files in the results here.
find -type f -exec grep -q ‘hello’ {} \; -print

If you are not seeing anything unusual, run this.

find -type f -exec grep -q ‘hello’ {} \; -delete

Reply

100 MysteryMan July 1, 2014 at 9:47 am

How do I delete my failed marriage?

MM

Reply

101 juan sabayton July 24, 2014 at 2:44 am

can i delete files under the mounted filesystem? for example

/myFS

can i delete all files under this?

# rm -rf /myFS

would it delete all files?

and also

does rm -rf / really delete all files your on your system?

Reply

102 Vincent Polisi August 11, 2014 at 4:38 pm

Thank you for the tutorial.

Worked perfectly on the SSL certs I needed to delete and replace.

Vincent Polisi

Reply

103 naveen September 6, 2014 at 2:52 am

How to delete file in linux

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: