2
votes
2answers
83 views

delete old log files except the last one (alphanumerically sorted)

I have a number of log files in the form: log.2014-02-19-10_24_22 I.e. log.YYYY-MM-DD-H24_MI_SS The date that's part of the log file's name is when the log file was first created. So at any given ...
2
votes
2answers
82 views

delete directory with special character in filename

I have these tricky directories that I can't figure out how to delete. If I run ls -ld * I get… drwxrwxr-x 7 user1 taskfmri 2048 Jan 22 15:26 857263 drwxrwx--- 4 user2 ...
4
votes
4answers
147 views

Keeping the number of files in the folder constant by deleting old files

I'm trying to create a script and run it in crontab every 5 min, so that the number of files in a folder always remain 50000. If there are more, I want the script to delete the old files. ...
1
vote
2answers
64 views

Keeping the latest two version and delete the remaining

I have a list of files (say xsl format below) in one directory. I want to keep the last two version of all files. (I can delete the remaing files) {A}_1.0.xsl {A}_2.0.xsl {A}_3.0.xsl {A}_4.1.xsl ...
1
vote
3answers
56 views

Preventing deletion of system/shell aliased folders

Is there a way to prevent deletion of system/shell aliased folders? I want these commands to fail. My shell is bash. Such as: $rm -rf . $rm -rf .. $rm -rf ~ $rm -rf *
2
votes
3answers
97 views

Remove all files except for last file of each month

Consider a directory with MySQL backup files with timestamps as part of the filename: -rw-rw-r-- 1 ubuntu ubuntu 35856184 Nov 16 16:00 db_2013-11-16_1600.sql -rw-rw-r-- 1 ubuntu ubuntu 35856915 Nov ...
1
vote
3answers
283 views

Remove all *.mp4 and *.zip but some files

In one of my programs I call a bash command to remove all files in the directory, but some: bash -c shopt -s extglob shopt -s nullglob rm /path/to/directory/!("file1" | "file2") Which for what I ...
1
vote
2answers
261 views

Removing specific files recursively using rm or something simple?

I have a root folder with a text file in it called pairs.txt. Within that root folder are other folders with text files called pairs.txt in them. Is there a simple way to remove them using rm? I ...
0
votes
1answer
206 views

Find and remove sub-directories without error?

I need to find a way to remove sub-directories from within a particular directory without receiving an error if no sub-directories exist. This command will successfully remove sub-directories if they ...
3
votes
1answer
3k views

Move files and delete directories with rsync?

Recently I needed to delete a large number of files (over 1 million) and I read that doing: rsync -av --delete `mktemp -d`/ ~/source && rmdir ~/source Was one of the most optimized ways to ...
1
vote
2answers
206 views

How to avoid the need to issue “y” several times when removing protected file

I'm looking for a solution to be used as a response to "rm: remove write-protected regular file [x] ?" I was thinking of issuing a character followed by carriage return for several amount of times, ...
4
votes
4answers
669 views

How to remove files which do not end with “.c”?

I have a directory which contains all the C programs. I have also compiled them at the creation time so as to check my code. There are a lot of programs nearly 100 of them. So I want a BASH script ...
5
votes
4answers
534 views

How to forbid the execution of /bin/rm -f *?

I cannot remember how many times I've listed a subdirectory and executed /bin/rm -f * in the current directory. Can anyone give suggestions to help me avoid this? What should I do if I want the system ...
0
votes
3answers
331 views

Safe Directory Delete

I alias rm to rm -i so that when I mistype file* as file * I get prompted before accidentally deleting files I didn't intend to delete. Is there an equivalent idiom for directories? In particular, ...
1
vote
2answers
233 views

Why rm command unrecognized w flag in AIX?

I have a bash script that retain the last 5 copies in AIX like this: rm `ls -lt /path/the_file_* | tail -n +6` But I get this error: rm: Not a recognized flag: w UPDATE The ls command return ...
3
votes
2answers
1k views

find flags: -exec rm -rf vs -delete

I thought the flags I mentioned in the question are the same, but I get the following message with the former, but nothing with the latter: $ find . -mindepth 1 -type d -exec rm -rf {} \; find: ...
1
vote
1answer
243 views

How to delete a file to the trash in BASH (Linux) [duplicate]

Possible Duplicate: Make `rm` move to trash I've looked everywhere for the answer, but I can't find it. Is it possible to move/delete a file to the trash folder on linux. But also having ...
10
votes
2answers
972 views

Interactively deleting files from a list

I'd like to remove a list of files and be asked for confirmation. The list is in the list.txt file. Why the following command doesn't work properly? while read i; do rm -i $i; done < list.txt ...
13
votes
2answers
317 views

Can I make `rm` interactive only when using globbing? (in either bash or zsh or both)

Whenever I rm multiple items at once with shell globbing and there's even the slightest possibility that the pattern expands to more than I expect it to, I always try to remember to add -i, but (of ...
3
votes
3answers
9k views

How can I delete all files with a particular extension in a particular folder?

If I set the current/working directory (navigating to it using cd) to some particular directory and then type: rm *.xvg What will this command do? Is it true that the above command will only delete ...
8
votes
4answers
3k views

Remove files older than 5 days in UNIX (date in file name, not timestamp)

I want to delete log files which are older than 5 days from a directory. But deletion should not be based on the timestamp of file. It should be based on the name of file. For Example todays date is ...
2
votes
1answer
2k views

How can I delete a hidden folder?

I want to delete many configuration folder in my home user folder but I can't figure out how to delete them. How can I delete a hidden folder?
4
votes
3answers
1k views

Remove many many many files from a folder

I have a folder with 137795 files in it. I need to delete all of them. When I run rm * I get -bash: /bin/rm: Argument list too long. How do I get past this error?
5
votes
2answers
194 views

Is it safe to remove a script file from within that script?

Imagine I have a script foo. It should be run once when the user logs in and isn't needed after a successful run. My question: Is it safe to remove the script file from within the script? E.g.: ...
5
votes
2answers
884 views

Why doesn't “rm *” work when there are files that begin with a hyphen?

from: http://seclists.org/fulldisclosure/2011/Sep/190 [USER@MACHINE ~] mkdir ejha [USER@MACHINE ~] cd ejha/ [USER@MACHINE ~/ejha] touch ize [USER@MACHINE ~/ejha] touch -- -f -i [USER@MACHINE ...
5
votes
2answers
7k views

giving grep output to rm

I'm trying to pipe grep output to rm, but it outputs useless stuff. Is any switch required for rm? Or can rm can be provided a regexp directly? ls | grep '^\[Daruchini'| rm rm: missing operand Try ...