
Terminal - Commands tagged perl - 79 results
This is sample output - yours may be different.
Available commands are:
l - List all installed modules
m <module> - Select a module
q - Quit the program
cmd? l
Installed modules are:
HTTP::Server::Simple
Perl
Sub::Uplevel
Test::Warn
Tree::DAG_Node
WWW::Facebook::FQL
WWW::Mechanize
cmd?
cmd? is the prompt.
instmodsh is a perl script. To view it use your fav editor. i.e.
vi $(which instmodsh)
perl -le 'print int(rand($ARGV[0]))+1;' YOUR_X
This is sample output - yours may be different.
$ perl -le 'print int(rand($ARGV[0]))+1;' 10
4
Both 1 and X are possible outcomes. If you want to exclude X, remove '+1'.
perl -M'Cwd qw/getcwd realpath/' -le '$d=realpath($ARGV[0])//getcwd;opendir(DIR, $d); @f=sort(readdir(DIR)); for (@f) { unless (/^\.+$/) { $_="$d/$_"; s#//#/#g; print; } } closedir(DIR);' OPTIONAL_DIR_NAME
This is sample output - yours may be different.
This version only uses Perl (the Cwd module has been included since 5.8). You can supply a directory name (relative to the current directory or absolute) at the end, or it will list the files in the current working directory if no argument is supplied.
If you're going to vote down, at least have the decency to explain why.
perl -le 'chomp($w=`which $ARGV[0]`);$_=`file $w`;while(/link\b/){chomp($_=(split/`/,$_)[1]);chop$_;$w.=" -> $_";$_=`file $_`;}print "\n$w";' COMMAND_NAME
This is sample output - yours may be different.
$ perl -le 'chomp($w=`which $ARGV[0]`);$_=`file $w`;while(/link\b/){chomp($_=(split/`/,$_)[1]);chop$_;$w.=" -> $_";$_=`file $_`;}print "\n$w";' vi
/usr/bin/vi -> /etc/alternatives/vi -> /usr/bin/vim.gtk
This will show you any links that a command follows (unlike 'file -L'), as well as the ultimate binary or script.
Put the name of the command at the very end; this will be passed to perl as the first argument.
For obvious reasons, this doesn't work with aliases or functions.
This is sample output - yours may be different.
This is sample output - yours may be different.
max@sinister:~$ echo hello | od -t x1
0000000 68 65 6c 6c 6f 0a
0000006
max@sinister:~$ echo hello | od -x
0000000 6568 6c6c 0a6f
0000006
Just use "od" and it can also dump in decimal or octal.
(use -t x1 and not just -x or it confuses the byte order)
There is a load of other formatting options, I'm not sure if you can turn off the address at the start of the line.
echo -n 'text' | perl -pe 's/(.)/sprintf("\\x%x", ord($1))/eg'
This is sample output - yours may be different.
Here's a version that uses perl. If you'd like a trailing newline:
perl -pe 's/(.)/sprintf("\\x%x", ord($1))/eg; END {print "\n"}'
perl -e 'print "\x41\x72\x74\x20\x6f\x66\x20\x68\x61\x63\x6b\x69\x6e\x67\x2e\x2e\x2e\n" x 100'
This is sample output - yours may be different.
gunslinger@localhost:~/shellcode$ perl -e 'print "\x41\x72\x74\x20\x6f\x66\x20\x68\x61\x63\x6b\x69\x6e\x67\x2e\x2e\x2e\n" x 100'
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
gunslinger@localhost:~/shellcode$
cat file_with_tabs.txt | perl -pe 's/\t/ /g'
This is sample output - yours may be different.
Replaces tabs in output with spaces. Uses perl since sed seems to work differently across platforms.
perl -MNet::Twitter -e '$nt = Net::Twitter->new(traits => [qw/API::REST/], username => "YOUR USERNAME", password => "YOUR PASSWORD"); $ud = $nt->update("YOUR TWEET");'
This is sample output - yours may be different.
Requires Net::Twitter. Just replace the double quoted strings with the appropriate info.
git log -p -z | perl -ln0e 'print if /[+-].*searchedstring/'
This is sample output - yours may be different.
aptitude purge linux-image | grep ^i | grep -v $(uname -r)
This is sample output - yours may be different.
perl -e 'chomp($k=`uname -r`); for (</boot/vm*>) {s/^.*vmlinuz-($k)?//; $l.="linux-image-$_ ";} system "aptitude remove $l";'
This is sample output - yours may be different.
for code in $(find . -type f -name '*.p[ml]'); do perl -c "$code"; done
This is sample output - yours may be different.
./foo.pl syntax OK
./bar/Baz.pm syntax OK
...
Finds all *.p[ml]-files and runs a perl -c on them, checking whether Perl thinks they are syntactically correct
perl -e 'foreach (@ARGV) {@T=stat($_); print localtime($T[8])." - ".$_."\n"}'
This is sample output - yours may be different.
perl -e '@F = `ls -1`;while (<@F>){@T = stat($_);print "$_ = " . localtime($T[8]) . "\n";}'
This is sample output - yours may be different.
Test_DR.sh = Mon Jul 6 09:22:35 2009
Test_DR.sh-20080806-hck = Sun Aug 17 13:46:34 2008
Test_DR.sh~ = Sun Aug 17 13:49:59 2008
utk_cod-savesets = Wed Mar 14 11:20:46 2007
utkdc8 = Fri Nov 3 17:18:21 2006
Vics-data = Thu Jan 21 14:30:29 2010
Solaris 'ls' command does not have a nice '--full-time' arg to make the time show after a year has passed. So I spit this out quick. It hates spaces in file names.
perl -MDigest::SHA -e 'print substr( Digest::SHA::sha256_base64( time() ), 0, $ARGV[0] ) . "\n"' <length>
This is sample output - yours may be different.
Of course you will have to install Digest::SHA and perl before this will work :)
Maximum length is 43 for SHA256. If you need more, use SHA512 or the hexadecimal form: sha256_hex()
echo $hex | perl -pe 's/(..)/chr(hex($1))/ge'
This is sample output - yours may be different.
perl -i -pe 's/\r/\n/g' file
This is sample output - yours may be different.
This is sample output - yours may be different.
Thu Jun 25 10:48:08 2009: "Module" IO::Dir::Recursive
? "installed into: /usr/lib/perl5/site_perl/5.8.8"
? "LINKTYPE: dynamic"
? "VERSION: 0.03"
? "EXE_FILES: "
This command will give you the detailed information about the installed perl modules i.e. installed path, Link type, version, files etc.
curl -s http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=${@:-<YOURZIPORLOCATION>}|xmlstarlet sel -E utf-8 -t -m //forecast/txt_forecast/forecastday -v fcttext -n
This is sample output - yours may be different.
you can use xmlstarlet to parse output instead of perl
perl -MStatistics::Descriptive -alne 'my $stat = Statistics::Descriptive::Full->new; $stat->add_data(@F[1..4]); print $stat->variance' filename
This is sample output - yours may be different.
$ cat test
A 25 26 24 28
B 10 20 30 40
C 10 20 10 20
$ perl -MStatistics::Descriptive -alne 'my $stat = Statistics::Descriptive::Full->new; $stat->add_data(@F[1..4]); print $stat->variance' test
2.91666666666667
166.666666666667
33.3333333333333
In this example, file contains five columns where first column is text. Variance is calculated for columns 2 - 5 by using perl module Statistics::Descriptive. There are many more statistical functions available in the module.
perl -pi -e 's/\r\n?/\n/g'
This is sample output - yours may be different.
This method will also convert mac line endings.
perl -ne 'BEGIN{undef $/}; print "$ARGV\t$.\t$1\n" if m/(first line.*\n.*second line)/mg'
This is sample output - yours may be different.
Using perl you can search for patterns spanning several lines, a thing that grep can't do. Append the list of files to above command or pipe a file through it, just as with regular grep. If you add the 's' modifier to the regex, the dot '.' also matches line endings, useful if you don't known how many lines you need are between parts of your pattern. Change '*' to '*?' to make it greedy, that is match only as few characters as possible.
See also http://www.commandlinefu.com/commands/view/1764/display-a-block-of-text-with-awk to do a similar thing with awk.
Edit: The undef has to be put in a begin-block, or a match in the first line would not be found.
echo "$url" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"'
This is sample output - yours may be different.
$ echo "this & that" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"'
this%20%26%20that
$ echo "this & that" | python -c 'import sys,urllib;print urllib.quote(sys.stdin.read().strip())'
this%20%26%20that
Converts reserved characters in a URI to their percent encoded counterparts.
Alternate python version:
echo "$url" | python -c 'import sys,urllib;print urllib.quote(sys.stdin.read().strip())'