
Terminal - Commands using perl - 316 results
ps -e -m -o user,pid,args,%mem,rss | grep Chrome | perl -ne 'print "$1\n" if / (\d+)$/' | ( x=0;while read line; do (( x += $line )); done; echo $((x/1024)) );
This is sample output - yours may be different.
How much memory is chrome sucking?
pwd|grep -o '/'|perl -ne '$x.="./.";print`readlink -f $x`'|xargs -tn1 chmod 755
This is sample output - yours may be different.
chmod 755 /tmp/1/2/3
chmod 755 /tmp/1/2
chmod 755 /tmp/1
chmod 755 /tmp
`pwd` returns the current path
`grep -o` prints each slash on new line
perl generates the paths sequence: './.', './../.', ...
`readlink` canonicalizes paths (it makes the things more transparent)
`xargs -tn1` applies chmod for each of them. Each command applied is getting printed to STDERR.
for i in `gpg --list-sigs | perl -ne 'if(/User ID not found/){s/^.+([a-fA-F0-9]{8}).*/\1/; print}' | sort | uniq`; do gpg --keyserver-options no-auto-key-retrieve --recv-keys $i; done
This is sample output - yours may be different.
gpg: requesting key E8D80906 from hkp server keys.gnupg.net
gpg: key E8D80906: public key "Ayush Sharma <ayush.cena@gmail.com>" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg: imported: 1
gpg: requesting key EFFF0243 from hkp server keys.gnupg.net
gpg: key EFFF0243: public key "GSWoT:US10 (www.gswot.org)" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
The original command doesn't work for me - does something weird with sed (-r) and xargs (-i) with underscores all over...
This one works in OSX Lion. I haven't tested it anywhere else, but if you have bash, gpg and perl, it should work.
curl http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 2>/dev/null | grep '^<h3' | grep -v '^\d' | perl -pe 's/^.*(?<=(\d\d\d)) (.*)<\/h3>$/$1 : $2/' | grep -v h3
This is sample output - yours may be different.
100 : Continue
101 : Switching Protocols
200 : OK
201 : Created
202 : Accepted
203 : Non-Authoritative Information
204 : No Content
205 : Reset Content
206 : Partial Content
300 : Multiple Choices
301 : Moved Permanently
302 : Found
303 : See Other
304 : Not Modified
305 : Use Proxy
306 : (Unused)
307 : Temporary Redirect
400 : Bad Request
401 : Unauthorized
402 : Payment Required
403 : Forbidden
404 : Not Found
405 : Method Not Allowed
406 : Not Acceptable
407 : Proxy Authentication Required
408 : Request Timeout
409 : Conflict
410 : Gone
411 : Length Required
412 : Precondition Failed
413 : Request Entity Too Large
414 : Request-URI Too Long
415 : Unsupported Media Type
416 : Requested Range Not Satisfiable
417 : Expectation Failed
500 : Internal Server Error
501 : Not Implemented
502 : Bad Gateway
503 : Service Unavailable
504 : Gateway Timeout
505 : HTTP Version Not Supported
When you need a quick ref guide while troubleshooting Apache|NGINX error|access logs.
wget -q -O - http://listen.di.fm/public2 | sed 's/},{/\n/g' | perl -n -e '/"key":"([^"]*)".*"playlist":"([^"]*)"/; print "$1\n"; system("wget -q -O - $2 | grep -E '^File' | cut -d= -f2 > di_$1.m3u")'
This is sample output - yours may be different.
1.- Enter into the playlist path.
2.- Run the command.
3.- Playlists created!
FULLPATH=$(perl -e "use Cwd 'abs_path';print abs_path('$0');")
This is sample output - yours may be different.
]$ ls -l test.sh
-rwxr-xr-x 1 follier dev-user 78 Feb 01 14:05 test.sh
]$ ./test.sh
/home/follier/test.sh
]$ ls -l linktest.sh
lrwxrwxrwx 1 follier dev-user 12 Feb 01 14:07 linktest.sh -> /tmp/test.sh
]$ ./linktest.sh
/tmp/test.sh
Since none of the systems I work on have readlink, this works cross-platform (everywhere has perl, right?).
Note: This will resolve links.
perl -MModule::Name\ 9999 -e 1
This is sample output - yours may be different.
jon@red6:~$ perl -MMoose\ 9999 -e 1
Moose version 9999 required--this is only version 2.0604.
BEGIN failed--compilation aborted.
foo@bar:~$ perl -MModule::Name\ 9999 -e 1
Can't locate Module/Name.pm in @INC (@INC contains: /home/foo/perl5/lib/perl5/x86_64-linux-gnu-thread-multi /home/foo/perl5/lib/perl5/x86_64-linux-gnu-thread-multi /home/jon/perl5/lib/perl5 /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .).
BEGIN failed--compilation aborted.
This attempts to load a Perl Module (-M flag) and use version 9999, since no module has a version this high, Perl exits either a) telling you the version of the module installed or b) tells you it can't find the module.
module_exists(){ perl -e 'use '$1 2>/dev/null; }
This is sample output - yours may be different.
$ module_exists diagnostics && echo yes || echo no
yes
$ module_exists beeblebrox && echo yes || echo no
no
This version uses a bash function and does not print the path to the module.
perl -MFile::Find=find -MFile::Spec::Functions -Tlwe '$found=1; find { wanted => sub { if (/$ARGV[0]\.pm\z/) { print canonpath $_; $found=0; } }, no_chdir => 1 }, @INC; exit $found;' Collectd/Plugins/Graphite
This is sample output - yours may be different.
/usr/local/share/perl5/Collectd/Plugins/Graphite.pm
find . | xargs perl -p -i.bak -e 's/oldString/newString/;'
This is sample output - yours may be different.
find . = will set up your recursive search. You can narrow your search to certain file by adding -name "*.ext" or limit buy using the same but add prune like -name "*.ext" -prune
xargs =sets it up like a command line for each file find finds and will invoke the next command which is perl.
perl = invoke perl
-p sets up a while loop
-i in place and the .bak will create a backup file like filename.ext.bak
-e execute the following....
's/ / /;' your basic substitute and replace.
perl -E 'say $_,`tput setb $_`," "x(`tput cols`-length("$_")),`tput sgr0` for 0..(`tput colors`-1)'
This is sample output - yours may be different.
Using perl and tput, show all the colors with numbers that your actual $TERM can handle.
If want to remove the numbers at beginning of new line, it should be something like this:
perl -E 'say `tput setb $_`," "x `tput cols`, `tput sgr0` for 0 .. (`tput colors` - 1)'
perl -E 'say$_%15?$_%3?$_%5?$_:Buzz:Fizz:Fizzbuzz for 1..100'
This is sample output - yours may be different.
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
Fizzbuzz
Just another FizzBuzz in Perl.
perl -e 'print "$_=$ENV{$_}\n" for keys %ENV'
This is sample output - yours may be different.
user@server:~$ perl -e 'print "$_=$ENV{$_}\n" for keys %ENV'
HOME=/home/user
LESS=-R
LC_ALL=de_DE.utf8
EDITOR=/usr/bin/vim
...
p=1 ; lynx -source http://www.lipsum.com/feed/xml?amount=${p} | grep '<lipsum>' -A$(((p-1))) | perl -p -i -e 's/\n/\n\n/g' | sed -n '/<lipsum>/,/<\/lipsum>/p' | sed -e 's/<[^>]*>//g'
This is sample output - yours may be different.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce consequat tincidunt diam ut lobortis. Aenean sed dolor nibh, eget consequat purus. Curabitur luctus nibh nec velit dignissim ultrices. Mauris id elit ac diam tempus facilisis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Proin euismod consectetur lorem, sit amet pellentesque felis elementum a. Vivamus congue nulla et lorem convallis rutrum. Curabitur dapibus aliquam nunc sed vestibulum. In at ornare mauris. Integer congue sem turpis. In at velit at neque facilisis facilisis a egestas justo. Proin gravida diam sed metus elementum egestas. Maecenas et enim vel dolor dictum faucibus. Sed ultrices rutrum nisi, vitae rutrum tortor consequat ac. Maecenas at nunc in neque vestibulum varius.
This fixes the extra lines you get when you request only 1 paragraph using a little bit of grep. Just set p to the number of paragraphs you want.
history | perl -pe "~s/ *[0-9]+ *//"
This is sample output - yours may be different.
perl -pi -e 's/:([\w\d_]+)(\s*)=>/\1:/g' **/*.rb
This is sample output - yours may be different.
# strace ... | perl -lne '@F=split(/\\/, $_);for(@F){push @ddd, sprintf("%x", oct("0" . $_))}END{shift @ddd; print pack("H*", join("", @ddd));}'
This is sample output - yours may be different.
perl -e 'print map { $_ .= "$ENV{$_}\n" } (keys %ENV)'
This is sample output - yours may be different.
Print environment (system) information using Perl.
perl -e 'print map { -l and $_ .= "\n" } <libxml*>'
This is sample output - yours may be different.
libxml++-1.0.so.1
libxml++-2.6.so
libxml++-2.6.so.2
libxml++.so.1
libxml2.so
libxml2.so.2
Perl alternative to list symlinks with a clumsy regexp filter: place the regex instead of he example 'libxml' and end it with a wildchar to see the results (previous cd on dir).
Is it possible change the '-l' test for '-d' and it will search for directories. [Same applies for -x and -X. See $(perldoc -f -x) for more tests].
I use it quite often when dealing with shared libraries...
perl -MHTML::Entities -ne 'print encode_entities($_)' /tmp/subor.txt
This is sample output - yours may be different.
Encode HTML entities supporting UTF-8 input and output
perl -e '$|++; while (1) { print " " x (rand(35) + 1), int(rand(2)) }'
This is sample output - yours may be different.
cat log | perl -ne 'use POSIX; s/([\d.]+)/strftime "%y-%m-%d %H:%M:%S", localtime $1/e,print if /./'
This is sample output - yours may be different.
works where perl works, because the awk version is gnu awk only.
perl -e '$s="$s\xFF" while length($s)<512; print $s while 1' | dd of=/dev/sdX
This is sample output - yours may be different.
ping g.co|perl -ne'$|=/e=(\S+)/||next;(push@_,$1)>30&&shift@_;print"\r",(map{"\xe2\x96".chr(128+7*$_/(sort{$b<=>$a}@_)[0])." "}@_),"$1ms"'
This is sample output - yours may be different.
bgrantham$ ping g.co|perl -ne'$|=/e=(\S+)/||next;(push@_,$1)>30&&shift@_;print"\r",(map{"\xe2\x96".chr(128+7*$_/(sort{$b<=>$a}@_)[0])." "}@_),"$1ms"'
▄ ▆ ▅ ▆ ▅ ▆ ▅ ▅ ▅ ▅ ▅ ▅ ▅ ▅ ▅ ▅ ▄ ▅ ▅ ▅ ▆ ▅ ▄ ▄ ▆ ▅ ▇ ▅ ▅ ▅ 87.458ms^C
bgrantham$
Nasty perl one-liner that provides a sparkline of ping times. If you want a different history than the last 30, just put that value in. It (ab)uses unicode to draw the bars, inspired by https://github.com/joemiller/spark-ping . It's not the most bug-free piece of code, but what it lacks in robustness it makes up for in capability. :)
If anyone has any ideas on how to make it more compact or better, I'd love to hear them.
I included a ping to google in the command just as an example (and burned up 10 chars doing it!). You should use it with: $ ping example.com | $SPARKLINE_PING_COMMAND
perl -e 'printf "00:16:3E:%02X:%02X:%02X\n", rand 0xFF, rand 0xFF, rand 0xFF'
This is sample output - yours may be different.