Post your Command line tricks

Forum rules
Share your brain ;)
User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Post your Command line tricks

Unread post by wuxmedia » Sat Oct 26, 2013 5:59 pm

^^ shouldn't that be 'pstree' ?
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Post your Command line tricks

Unread post by wuxmedia » Sun Oct 27, 2013 6:51 pm

bored, how many files on my system?

Code: Select all

find / | sort | uniq | wc -l
"Seek, and Ye shall find"
"Github | Chooons | Site"

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Mon Oct 28, 2013 4:35 am

Search for bloat (lol):

Code: Select all

find / -size +20000k
Search for the pattern "grill" within files inside of /usr/local/

Code: Select all

grep -nr "grill" /usr/local/
..gnutella..

User avatar
johnraff
Sperminator
Posts: 199
Joined: Wed Oct 17, 2012 6:38 pm
Location: Japan
Contact:

Re: Post your Command line tricks

Unread post by johnraff » Tue Oct 29, 2013 6:12 pm

wuxmedia wrote:^^ shouldn't that be 'pstree' ?
YES!!

Sorry bout that - a beer too many?
Thanks for catching it. Image
All code is one.

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Post your Command line tricks

Unread post by wuxmedia » Tue Oct 29, 2013 6:15 pm

heh, I thought it was a new one, ran it, nope - apt-cache searched it, nope... Ahhh ok...
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: Post your Command line tricks

Unread post by dkeg » Fri Nov 01, 2013 4:24 am

^a^b
take previous commnad and replace a with b.

Work hard; Complain less

User avatar
kiiroitori
dpkg-reconfigure
Posts: 72
Joined: Tue Aug 27, 2013 12:22 pm

Re: Post your Command line tricks

Unread post by kiiroitori » Fri Nov 01, 2013 2:12 pm

They are not really tricks but I find this useful and it's the best I can do, being a regular noob kind-a-guy (with a beard though).

This came after catfish crashed on me and I was like "what the hell I just want to find a damn file stupid GUI software crashing on me damn how hard can this be man it should be simple damnit" (note that when I swear I don't use punctuation).

So here is some find goodness:

Code: Select all

find . -name *ass.jpg -newermt 2013-10-01 ! -newermt 2013-11-01
will find all files that end with "ass.jpg" (e.g. biomass.jpg, compass.jpg, etc) created in October of this year.

Feel like wiping all asses pictures from your drive? Be careful and use this at your own risks (keep in mind that I am still a noob despite my beard):

Code: Select all

find . -name \*ass.jpg -type f -delete

"type -f" shouldn't be necessary but will prevent from deleting directories, it feels safer to me.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Fri Nov 01, 2013 2:19 pm

^ or you can pipe the output into a file, review it, and then cat the file into rm :)
..gnutella..

User avatar
kiiroitori
dpkg-reconfigure
Posts: 72
Joined: Tue Aug 27, 2013 12:22 pm

Re: Post your Command line tricks

Unread post by kiiroitori » Fri Nov 01, 2013 2:50 pm

^ Excellent Mr Bacon, piping is good!

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Fri Nov 01, 2013 3:02 pm

so something like

Code: Select all

find . -name \*ass.jpg > asses.txt && nano asses.txt && xargs -a asses.txt -d'\n' rm
and all the ass is gone. Probably there's a more elegant way. Or, I'm sure there is.
..gnutella..

User avatar
ivanovnegro
Minister of Truth
Posts: 5449
Joined: Wed Oct 17, 2012 11:12 pm

Re: Post your Command line tricks

Unread post by ivanovnegro » Fri Nov 01, 2013 3:22 pm

@Kiiroitiri: See, this is why I do not understand all the search features that come with some file browsers or in KDE.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Fri Nov 01, 2013 3:31 pm

To be honest, only Catfish is a really decent front end for complex searches (you can choose the backend and limit the results), but I find myself using find and grep actually every day, because it 'goes loosely from the hand' :D
..gnutella..

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: Post your Command line tricks

Unread post by pidsley » Fri Nov 01, 2013 3:35 pm

Let's not forget "locate". Fewer options than find, but much faster when you want to search the whole system.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Post your Command line tricks

Unread post by rhowaldt » Fri Nov 01, 2013 3:45 pm

pidsley just made a valid point.
also:
(note that when I swear I don't use punctuation).
lol.
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Post your Command line tricks

Unread post by DebianJoe » Sat Nov 02, 2013 12:16 pm

"Hey brah, I just downloaded this totally sweet color theme, but someone put a '*color' at the beginning of all of the lines instead of the "Urxvt.color" that I normally use to make it work. I don't like editing files manually because I'm lazy." Basic sed to the rescue!

Code: Select all

sed -i.bak 's/^\*/URxvt./' .Xresources
Plus, .Xresources.bak is left if you want to renege on the decision.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
johnraff
Sperminator
Posts: 199
Joined: Wed Oct 17, 2012 6:38 pm
Location: Japan
Contact:

Re: Post your Command line tricks

Unread post by johnraff » Wed Nov 06, 2013 2:14 pm

@joe you sure that worked? I've just tried it on a random list file (not Xresources) to no effect. However, this put a 'URxvt' at the front of every line (no discrimination):

Code: Select all

sed -i.bak 's/^/URxvt./' list
Thanks for that -i.bak tweak though!

@dkeg that ^a^b trick is amazing!
Last edited by johnraff on Wed Nov 06, 2013 4:26 pm, edited 2 times in total.
All code is one.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: Post your Command line tricks

Unread post by dkeg » Wed Nov 06, 2013 2:44 pm

small but mighty :D

Work hard; Complain less

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Post your Command line tricks

Unread post by DebianJoe » Wed Nov 06, 2013 2:53 pm

@ Johnraff
Image
....I accidentally left a ' at the end of the command. I'll fix it. Thanks for the catch. Remove extra single quote, profit.

The regex needs to be tied to the "*" which should be escaped first.

Edit: Sed is my favorite tool on systems that don't have emacs (where I'd normally just open and do a regex search and replace). Let's break this one down for fun, because you're a Bash guy, this is handy to know.

sed -i.bak (defines that we're going to use sed with the -i which edits the original file while making a .bak of it.)
's/ (search and replace, the / is a delimiter, expression starts at the single quote)
^\*/ (like a bash regex, the ^ anchors us to the start of the line, and we escape the * so that it's literal, and not a glob. Then we add another delimiter to let sed know we're done with what we're looking for.)
URxvt./' (the string to replace the occurance with. If we find a * at the beginning of the line, we sub this in for it. One more delimiter. Then we close the command with the single quote)
.Xresources (the file that we wish to perform this function on.)

The extra quote at the end meant that it would have only performed this operation on a file named .Xresources' which you probably don't have either. Sorry for the mistake.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
johnraff
Sperminator
Posts: 199
Joined: Wed Oct 17, 2012 6:38 pm
Location: Japan
Contact:

Re: Post your Command line tricks

Unread post by johnraff » Wed Nov 06, 2013 4:24 pm

^ah got it. Thanks. It looks as if there might not have been anything wrong with your original code anyway. I didn't see the * (blame it on the font+my eyes) in front of color in " ...but someone put a '*color' at the beginning of..." so of course as my test file had no asterisks it didn't do anything...Image
All code is one.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Post your Command line tricks

Unread post by DebianJoe » Sun Nov 10, 2013 8:54 am

New useful tool, I have it as a function in my .zshrc, but should work in bash as well.

Code: Select all

internetquery() {
    ping -q -w 1 -c 1 $(ip r | grep default | cut -d ' ' -f 3) \
               > /dev/null && echo "Internet up" || echo "No Internet"
}
Let's me know if it's my connection or not by pinging default gateway and then telling me if internet is up, or not.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

Post Reply