
Ask HN: How would you improve this bash oneliner for deleting tweets? - jamiehall
Many people use tweet deletion services, which periodically remove everything from their Twitter timeline; I wondered if it could be done from a Bash command line.<p>I wrote up my experiences as an explainer for nontechnical people: <a href="https:&#x2F;&#x2F;jamiehall.cc&#x2F;2020&#x2F;03&#x2F;10&#x2F;delete-all-your-tweets-with-one-line-of-bash&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jamiehall.cc&#x2F;2020&#x2F;03&#x2F;10&#x2F;delete-all-your-tweets-with-...</a><p>TL;DR, here is the oneliner I&#x27;ve been using:<p><pre><code>  $ twurl &quot;&#x2F;1.1&#x2F;statuses&#x2F;user_timeline.json?screen_name=YOUR_TWITTER_HANDLE&amp;count=200
    &amp;max_id=$(
      twurl &#x27;&#x2F;1.1&#x2F;statuses&#x2F;user_timeline.json?screen_name=YOUR_TWITTER_HANDLE&amp;count=200&amp;include_rts=1&#x27;
     | jq -c -r &#x27;.[] | .id_str&#x27; | head -10 | tail -1)
    &amp;include_rts=1&quot;
   | jq -c -r &#x27;.[] | .id_str&#x27; 
   | parallel -j 10 -a - twurl -X POST &#x2F;1.1&#x2F;statuses&#x2F;destroy&#x2F;{1}.json
   &gt; &#x2F;dev&#x2F;null
</code></pre>
[Edit: I&#x27;ve put line breaks in there to make it more legible.]<p>I&#x27;m curious if it&#x27;s possible to do better. In particular: could this be more elegant? Is it possible to do it using common built-ins, instead of twurl and jq?<p>Any suggestions or improvements would be very welcome!
======
rhacker
I feel like this is normally the content you see in Stack Overflow

~~~
ollien
Probably best for the code review StackExchange forum, actually.

~~~
rococode
Might be pretty fun for the code golf stack exchange too!

------
toomuchtodo
You might consider putting this in a GitHub Gist, sharing the link for it, and
accept comments and improvements within the Gist comments functionality.

This would also allow others to fork your code to improve upon or keep a copy
for themselves.

~~~
jamiehall
Great idea, thanks!
[https://gist.github.com/nerdcha/3e811ef28d04561f73337e46267a...](https://gist.github.com/nerdcha/3e811ef28d04561f73337e46267a0d5c)

~~~
toomuchtodo
Did you get the feedback you were looking for?

------
Pirate-of-SV

        jq -c -r '.[] | .id_str'
        # Can be rewritten to
        jq -r '.[].id_str'
    
        jq -c -r '.[] | .id_str' | head -10 | tail -1
        # Can be rewritten to
        jq -r '.[9].id_str'

~~~
jamiehall
Ah, nice. Thanks! :D

------
t0astbread
What are the rate limits on the /statuses/destroy endpoint? I've checked the
docs and the docs say it is limited but the actual limit is not specified.

Other than that, thanks for writing this! I've been thinking about a tool like
this and this might come in handy. The code looks fine to me although I would
probably spin this out into a script and add some logging, as others have
already pointed out.

------
viraptor
I don't think there's a good reason to calculate the max_id every time. If you
want to delete all tweets, you could skip it.

------
a-wu
I've tried this before in a Python script but quickly got rate limited by the
300 tweet update limit [0]. Does this get around that?

[0] [https://developer.twitter.com/en/docs/basics/rate-
limits](https://developer.twitter.com/en/docs/basics/rate-limits)

~~~
darepublic
It's hard to imagine that it would

------
jamiehall
Thank you to everybody who commented! The suggestions to use something more
sensible than a oneliner (and to post on Stack instead) are well taken. A big
motivation of this project was "just because", for shits and giggles, so I
hope it's amused you for a minute or two. Cheers!

------
jlelse
Not answering your question, but I found a way to mass delete tweets without
creating an app: [https://jlelse.blog/posts/mass-delete-
tweets/](https://jlelse.blog/posts/mass-delete-tweets/)

------
mirimir
Not a Twitter user here, but would this delete retweets by others of your
tweets?

Those might include tweets that you'd most want to delete. As well as ones
that you'd most want to retain, for that matter.

~~~
jamiehall
Yes, it takes care of that; if someone has retweeted you with a comment, the
thing they're commenting on is replaced with "This tweet is no longer
available." (Obviously, it's no defence against people screenshotting your
tweet, manually copy-pasting what you said, etc etc.)

------
ksherlock
You could improve it by not tweeting in the first place.

------
cosmiccatnap
Make it delete the account instead.

------
staktrace
You could improve it by making it not a one-liner! Usually making it a
multiple-liner can improve readability. And unless you're typing it into the
command line directly everytime you run it (as opposed to putting it in a file
that you invoke) it doesn't really matter how many lines it has.

~~~
Normal_gaussian
It's not just readability.

One day the code breaks. For a one liner I have to pick it apart, add logging
/ diagnostics, fix it, and reassemble. The two most time consuming and error
prone parts of that are dealing with the 'one liner'

