Tag Info

New answers tagged

0

I had accidentally deleted my sqlite db file. What I did to find out the file was, Opened the location /proc/ in a file browser and searched for the deleted sqlite db file over there. I found out that file in a search result. Copied that file from there to my old place.


1

In one line grep -f <(ls "A") <(ls "B") | xargs -I'{}' rm "B/{}" but it work depends on file name only and may affect to empty subdirs. To avoid this use find -type f -maxdepth 1 instead of ls. For more secure check use @KasyA recepie.


1

In 3 lines: $ delfrom=/home/KasiyA/dirB # delete from $ cd /home/KasiyA/dirA # matched from /dirA$ find . -type f -exec cmp -s '{}' "$delfrom/{}" \; -exec echo rm -v "$delfrom/{}" \; In a test: $ ls -1 ~/dirA dupfile file1inA $ ls -1 ~/dirB dupfile file1inB /dirA$ find . -type f -exec cmp -s '{}' "$delfrom/{}" \; -exec echo rm -v "$delfrom/{}" \; ...


2

One way: #!/bin/bash cd ~/B for file in ~/A/* do file1=$(basename "$file") [ -f "$file1" ] && { echo "deleting $file1 "; rm -- "$file1"; } done


1

-delete will perform better because it doesn't have to spawn an external process for each and every matched file. It is possible that you may see -exec rm {} \; often recommended because -delete does not exist in all versions of find. I can't check right now but I'm pretty sure I've used a find without it. Both methods should be "safe". EDIT per comment ...


43

The correct syntax in bash is the following: rm /tmp/!(lost+found) As @goldilocks wrote in the comments, the original command makes an expansion on the query (it deletes all the files in the /tmp folder, then goes on, and deletes all the files in the current working folder, in your case the home folder). You can try to check if you can recover some of ...


26

The !(lost+found) in your rm command was probably the fatal mistake: 1978 rm -rf /tmp/* !(lost+found) 1979 sudo rm -rf /tmp/* !(lost+found) I don't know exactly bash is doing with that, but this command prints everything in my /tmp and also everything my current directory, which is currently ~: echo /tmp/* !(lost+found)


1

I prefer using find with -exec, that would make your call something like this: find /config/filegroups/ -maxdepth 1 -mindepth 1 -type d -exec rm -rf {} \;


8

If you are using bash: shopt -s extglob rm !(file1|file2|file3) After bash manual: !(pattern-list) matches anything except one of the given patterns and pattern-list is a list of one or more patterns separated by a |.


1

Add the names of the files you want to keep to a text file, one per line. This file should not be in the directory or you should add its name too. If the name of your directory is foo and the name of the file is bar, do the following. find foo -type f -print0|grep -vzZ -f bar|xargs -0 rm This does the following: find -type f searches for the names of ...


5

Make a subdirectory tmp, move all all the files that you want to keep to that directory and do a rm -f * afterwards. That will not affect the tmp directory. After that just do: mv tmp/* . rmdir tmp (Assuming none of the files you moved starts with a dot). This is one of the few cases where it makes sense to use the mouse and a file browser like Nautilus ...


1

My AIX's rm '-e' option is analogous to '-v'. "The -e option will display a message after each file is deleted."


2

There might be simpler ways, but when I have encounterd the Mac's filesystem to behave against my (Unix) expectations I moved the files that I need to a new directory, remove the old one and renamed the new directory to the old one. cd .. mkdir tmptest mv test/*.py tmptest rm -rf test mv tmptest test I am not sure what causes this except that it probably ...


0

With zsh: rm -- *(.) removes the regular files only rm -- *(D.) to also include dot-files (hidden ones) rm -- *(D^/) removes all types of files except directories (that include symlinks to directories) rm -- *(D^-/) removes all types of files except directories and symlinks to directories (it would remove symlinks to directories if it can't ...


1

Using bash (and ignoring symlinks): for file in *; do [[ -f $file ]] && rm -- "$file"; done


-1

sudo mkdir a b c d e sudo touch a/1 b/2 c/3 d/4 e/5 e/a e/b ls a b c d e pqr xyz cd a/ ls 1 cd ../e/ ls 5 a b cd /var/warehouse/abc/ find . -type f ! -path "./a*" ! -path "./b*" ./d/4 ./e/a ./e/b ./e/5 ./c/3 sudo find . -type f ! -path "./a*" ! -path "./b*" -exec rm -f {} \;


1

Simple way is to use $ rm ./* Here we are not using recursive delete (-r) and so only the files (except the hidden ones) in the parent directory should get deleted.


2

You could use find with a type argument. find . -maxdepth 1 -type f -exec rm -f {} \; You can do a dry run by removing the -exex rm -f {} \; portion to see the files that would be deleted.


7

Paths that start with / are from the root of the entire filesystem. Leave off the slash to specify a file relative to the current directory. You can also say ./admin/accounting to refer to a path relative to ., which is the current directory.



Top 50 recent answers are included