I need to rm files from a unix directory that only belong to my id. I tried building this command, but to no avail:
ls -la | grep 'myid' | awk ' { print $9 } ' | rm
My result: Usage: rm [-firRe] [--] File...
I need to rm files from a unix directory that only belong to my id. I tried building this command, but to no avail:
ls -la | grep 'myid' | awk ' { print $9 } ' | rm
My result: Usage: rm [-firRe] [--] File...
find . -user myuser -print0 |xargs -0 rm
Put your own userid (or maybe user number) in for "myuser".
rm does not accept a list of files to delete on the stdin (which is what you are doing by passing it through the pipe.
Try this
find . -type f -user username -exec rm -f {} \;
rm doesn't read from stdin.
find -user $(whoami) -delete
Please always test without the delete first.
You could use find:
find . -maxdepth 1 -type f -user myid -print0 | xargs -0 rm -f
Drop the -maxdepth 1 if you want it to handle subdirectories as well.
You were really close. Try:
rm `ls -la | grep 'myid' | awk ' { print $9 } '`
Note that those are backticks, not single quotes surrounding the first three segments from your original pipeline. Also for me the filename column was $8, but if $9 is the right column for you, then that should do it.