Tag Info

New answers tagged

1

With zsh, to remove the regular files other than the .bmp, .png, .wav (case insensitively) ones: setopt extendedglob # best in ~/.zshrc rm -- *.^(#i)(png|bmp|wav)(D.) (remove the D above if you want to preserve hidden files regardless of their extension).


1

What you can do is try to copy the .txt file to the documents directory. Then you can go ahead and delete the sub-directory. That would be 100X easier.


1

You have to do that in two steps: mv /Users/admin/Documents/Folder1/file1.txt /Users/admin/Documents/file1.txt rm -R /Users/admin/Documents/Folder1 With bash you can do the following shorter version: mv /Users/admin/Documents/{Folder1/,}file1.txt rm -R /Users/admin/Documents/Folder1


-2

Originally I had suggested this: cd /Users/admin/Documents/Folder1 mv $(ls -A) .. # the -A will find hidden items, but not return "." or ".." cd .. rmdir Folder1 But from the comments, I see that is not safe.


-1

rm -i * Then press y at the appropriate time.


12

Try this in-order to remove the file: rm -- --append


1

UPDATE: Given that find is the source of the data, I would use an array instead: readarray -t to_remove < <(find ...) number_of_files=${#toremove[@]} rm -i "${to_remove[@]}" If you are a pre-4 version of bash, use this loop to fill the array. while IFS= read -r fname; do to_remove+=("$fname") done < <(find ...) None of these work with ...


0

I figured it out. IFS=$'\n' for f in `echo "$to_remove"` ; do rm -ir "$f" done Short version: IFS=$'\n' rm -ir "$to_remove" Those two versions works as expected. Strange enough the following code doesn't work: IFS=$'\n' for f in "$to_remove" ; do rm -ir "$f" done Why?


3

simply use: rm -vri files | wc -l will include dirs, too (i.e. teh removal of A). This will work as -v will only send successful removed ’file’ (or dir) output to stout, while all others go to sterr. In your example the output will be 12, as there are 3 dirs and 9 files.


4

The command rm as been aliased to /bin/mv -f !* /u/stud/****/../TrashCan/****. Prefix the aliased command with \ to disable the alias: \rm, will run the original rm command.


2

It seems that someone has created an alias for rm command (probably replaced it by mv command) on the system. You can check by executing: alias rm You can reset it to default by: alias rm="rm -v"


7

There is no "precedence" for flags, each program handles them the way it wishes. Most do some effort to collect all flags and check for conflicts, for standard tools (like the referenced rm(1)) the relevant standards might mandate something (but then again, your particular version might be sloppy in interpreting corner cases of the standard/not get ...


2

See comments, but essentially removing some lingering configuration files which still pointed at /opt/pgAgent solved this. Suggest it is marked as answered. (OP did a manual cleanup of remaining configuration files and this enabled the install to work correctly)


6

Yes, for rm this is valid. If the last option overrides previous ones however depends on the individual program itself. From ´info rm´ ‘-f’ ‘--force’ Ignore nonexistent files and missing operands, and never prompt the user. Ignore any previous ‘--interactive’ (‘-i’) option. ‘-i’ Prompt whether to remove each file. If the ...


21

When using rm with both -i and -f options, the first one will be ignored. This is documented in the POSIX standard: -f Do not prompt for confirmation. Do not write diagnostic messages or modify the exit status in the case of nonexistent operands. Any previous occurrences of the -i option shall be ignored. -i Prompt for ...


0

With zsh and glob-qualifiers: print -rl -- *(.[1,-11]) will list all regular files except the last ten ([1,-11] means from the first up to the eleventh-to-last) If you're happy with the result replace print -rl with rm: rm -- *(.[1,-11])


5

*.*~ does not expand to any directories, it will just match any file or directory in the current directory that has a . in it somewhere and ends in ~ If you would like to find all the files that end in ~ from the directory you're in I would use find like find -type f -name '*~' -delete


6

Your rm -r *.*~ (same as rm -r ./*.*~) would remove files and directories matching *.*~ that is files and directories whose name contain a dot and ends with a ~ But subdir doe not contain any dot, so does not fit. Read glob(7) and remember that it is your shell (not the /bin/rm program!) which does the globbing. So what is happening is that you type rm -r ...


1

With zsh and (.m+n) glob qualifiers: . selects only regular files, m+n selects files modified more than n days ago; e.g. list the files in the current directory that were modified more than 9 days ago: print -rl -- *(.m+9) add D to include dot files: print -rl -- *(D.m+9) or if you want to recurse (and list e.g. only files ending with .log): setopt ...


1

If it has to be quick, I generate a new temporary directory, mv the directory below it and then recursively delete the temporary: t=`mktemp -d` mv certainFolder $t/ rm -rf $t &


5

Tracking freed blocks is unavoidable in any decent file system and ZFS is no exception. There is however a simple way under ZFS to have a nearly instantaneous directory deletion by deferring the underlying cleanup. It is technically very similar to Gilles' suggestion but is inherently reliable without requiring extra code. If you create a snapshot of your ...


4

What you're asking for is impossible. Or, more precisely, there's a cost to pay when deleting a directory and its files; if you don't pay it at the time of the deletion, you'll have to pay it elsewhere. You aren't just removing a directory — that would be near-instantaneous. You're removing a directory and all the files inside it and also recursively ...


2

The file (directory) is open. When you do rm it, the OS marks it as deleted without actually deleting it. In case you try to do cd into this directory from another shell instance, you will be denied the permission. After you cd out of this directory, the directory will actually get deleted.


2

The OS doesn't return that the working directory is 'dir1', the shell does. The shell keeps track of the current working directory, and the 'pwd' command you're running is a command built into the shell. The shell is not aware of the fact that your 'rm' command removed the directory. $ type pwd pwd is a shell builtin Try running /bin/pwd instead: $ ...


9

Why can you continue viewing a movie although it's been deleted? Because the file descriptor might be gone, but the inode is still there! And only when the inode gets deleted, is the file gone forever! So in your case: when you cd to / and all files in that tree are closed will the inodes be recycled and will the directory be gone forever¹... ...


6

I think pwd you run was a bash shell built-in. It just printed out the path it held in memory without looking up the file system. $ type pwd pwd is a shell builtin $ /bin/pwd /bin/pwd: couldn't find directory entry in '..' with matching i-node


4

In bash, this will delete everything in the current working directory which has the prefix ._: rm ._* If what you actually wanted to do was change their names to a form without the prefix, you can run: ls ._* | while read line do mv -- "$line" "${line:2}" done



Top 50 recent answers are included