miércoles, 8 de junio de 2016

Remove files with "special characters" on their name....

If you've something like this:

root@server1:/tmp/test_dir>ls -l
total 0
-rw-r-----    1 root     system            0 Jun 08 12:51 --f
-rw-r-----    1 root     system            0 Jun 08 12:51 -f
-rw-r-----    1 root     system            0 Jun 08 12:50 \     j
-rw-r-----    1 root     system            0 Jun 08 12:50 \-f
-rw-r-----    1 root     system            0 Jun 08 12:49 \n\tk
-rw-r-----    1 root     system            0 Jun 08 12:51 normal_file
-rw-r-----    1 root     system            0 Jun 08 12:51 space file
root@server1:/tmp/test_dir>


Don't run!!!! It's a piece of cake...

"ls -li" gives us the inode the file is using...

root@server1:/tmp/test_dir>ls -li
total 0
57357 -rw-r-----    1 root     system            0 Jun 08 12:51 --f
57356 -rw-r-----    1 root     system            0 Jun 08 12:51 -f
57354 -rw-r-----    1 root     system            0 Jun 08 12:50 \       j
57355 -rw-r-----    1 root     system            0 Jun 08 12:50 \-f
57348 -rw-r-----    1 root     system            0 Jun 08 12:49 \n\tk
57358 -rw-r-----    1 root     system            0 Jun 08 12:51 normal_file
57359 -rw-r-----    1 root     system            0 Jun 08 12:51 space file
root@server1:/tmp/test_dir>


Then, the "magic"....

root@server1:/tmp/test_dir>find . -inum 57357 -exec rm {} \;
root@server1:/tmp/test_dir>ls -l
total 0
-rw-r-----    1 root     system            0 Jun 08 12:51 -f
-rw-r-----    1 root     system            0 Jun 08 12:50 \     j
-rw-r-----    1 root     system            0 Jun 08 12:50 \-f
-rw-r-----    1 root     system            0 Jun 08 12:49 \n\tk
-rw-r-----    1 root     system            0 Jun 08 12:51 normal_file
-rw-r-----    1 root     system            0 Jun 08 12:51 space file
root@server1:/tmp/test_dir>


Repeat the operation for each "wierd file" you've found...





No hay comentarios:

Publicar un comentario