Post your Command line tricks
Forum rules
Share your brain ;)
Share your brain ;)
- wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
- Contact:
Re: Post your Command line tricks
^^ shouldn't that be 'pstree' ?
- wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
- Contact:
Re: Post your Command line tricks
bored, how many files on my system?
Code: Select all
find / | sort | uniq | wc -l
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: Post your Command line tricks
Search for bloat (lol):
Search for the pattern "grill" within files inside of /usr/local/
Code: Select all
find / -size +20000k
Code: Select all
grep -nr "grill" /usr/local/
..gnutella..
Re: Post your Command line tricks
YES!!wuxmedia wrote:^^ shouldn't that be 'pstree' ?
Sorry bout that - a beer too many?
Thanks for catching it.
All code is one.
- wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
- Contact:
Re: Post your Command line tricks
heh, I thought it was a new one, ran it, nope - apt-cache searched it, nope... Ahhh ok...
Re: Post your Command line tricks
^a^b
take previous commnad and replace a with b.
take previous commnad and replace a with b.
Work hard; Complain less
- kiiroitori
- dpkg-reconfigure
- Posts: 72
- Joined: Tue Aug 27, 2013 12:22 pm
Re: Post your Command line tricks
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:
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):
"type -f" shouldn't be necessary but will prevent from deleting directories, it feels safer to me.
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
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.
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: Post your Command line tricks
^ or you can pipe the output into a file, review it, and then cat the file into rm :)
..gnutella..
- kiiroitori
- dpkg-reconfigure
- Posts: 72
- Joined: Tue Aug 27, 2013 12:22 pm
Re: Post your Command line tricks
^ Excellent Mr Bacon, piping is good!
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: Post your Command line tricks
so something like
and all the ass is gone. Probably there's a more elegant way. Or, I'm sure there is.
Code: Select all
find . -name \*ass.jpg > asses.txt && nano asses.txt && xargs -a asses.txt -d'\n' rm
..gnutella..
- ivanovnegro
- Minister of Truth
- Posts: 5449
- Joined: Wed Oct 17, 2012 11:12 pm
Re: Post your Command line tricks
@Kiiroitiri: See, this is why I do not understand all the search features that come with some file browsers or in KDE.
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: Post your Command line tricks
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..
Re: Post your Command line tricks
Let's not forget "locate". Fewer options than find, but much faster when you want to search the whole system.
Re: Post your Command line tricks
pidsley just made a valid point.
also:
also:
lol.(note that when I swear I don't use punctuation).
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.
Re: Post your Command line tricks
"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!
Plus, .Xresources.bak is left if you want to renege on the decision.
Code: Select all
sed -i.bak 's/^\*/URxvt./' .Xresources
Re: Post your Command line tricks
@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):Thanks for that -i.bak tweak though!
@dkeg that ^a^b trick is amazing!
Code: Select all
sed -i.bak 's/^/URxvt./' list
@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.
Re: Post your Command line tricks
@ Johnraff
....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.
....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.
Re: Post your Command line tricks
^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...
All code is one.
Re: Post your Command line tricks
New useful tool, I have it as a function in my .zshrc, but should work in bash as well.
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.
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"
}