? Earlier 3 items total Later ?

On this page:?

Find and change a users uid

Most useful for providing a consistent uid on machines accessing an NFS mount:

$ sudo find . -xdev -user  -print -exec chown  {} \;

delete a filename starting with a dash

Have you ever created a file by mistakenly adding a flag where you shouldn't? Find the inode number of the file and delete it using find:

[one:~/src/oops] ryanschwartz$ cp test -p
[one:~/src/oops] ryanschwartz$ ls
-p test
[one:~/src/oops] ryanschwartz$ rm -p
rm: illegal option -- p
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
[one:~/src/oops] ryanschwartz$ \rm -p
rm: illegal option -- p
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
[one:~/src/oops] ryanschwartz$ ls -li
total 0
5937393 -rw-r--r-- 1 ryanschwartz textdrive - 0B May 27 18:04 -p
5937392 -rw-r--r-- 1 ryanschwartz textdrive - 0B May 27 18:04 test
[one:~/src/oops] ryanschwartz$ find . -inum 5937393
./-p
[one:~/src/oops] ryanschwartz$ find . -inum 5937393 -exec rm {} \;
[one:~/src/oops] ryanschwartz$ ls -li
total 0
5937392 -rw-r--r-- 1 ryanschwartz textdrive - 0B May 27 18:04 test

Clearing out a bunch of spam with spoofed emails that were bounced back to some poor guy with a catchall email

We don't really want to delete them all just in case.

cd /usr/local/scratch/
mkdir junk
find /var/spool/postfix -exec grep "somediscernible-feature.com" '{}' \; | awk '{print($3)}' | xargs -J X mv X ./junk/


The "find" produces

Binary file /var/spool/postfix/active/D/D8832E38 matches
Binary file /var/spool/postfix/active/D/D78EC1C72 matches
Binary file /var/spool/postfix/active/D/D593D279D matches
Binary file /var/spool/postfix/active/D/D0EB32833 matches


The awk

/var/spool/postfix/active/D/D8832E38
/var/spool/postfix/active/D/D78EC1C72
/var/spool/postfix/active/D/D593D279D
/var/spool/postfix/active/D/D0EB32833


And then the mv, moves it.

? Earlier 3 items total Later ?