Difference between revisions of "Linux"

From Wiki2
Line 14: Line 14:
  sudo halt -p shuts down power
  sudo halt -p shuts down power
  sudo ifconfig find ip adress etho innet addr is lan ip (ipconfig on windoows)
  sudo ifconfig find ip adress etho innet addr is lan ip (ipconfig on windoows)
====locate====
sudo apt-get updat
sudo apt-get install mlocate
sudo updatedb
locate libtinfo.so.5


{{:e2fsck}}
{{:e2fsck}}

Revision as of 16:47, 18 September 2015

unix

http://www.namhuy.net/3116/how-to-fix-gpg-error-no_pubkey-in-ubuntu.html

commands

chmod -R 777 /var/backups/dog
sudo chown -R tim www
du -ah /var/www //gives size of directory and everything in it
vim . //opens vim with directory tree
rename_a_file mv oldname newname
landscape-sysinfo
grep -r "siteUrlis dog" /var/www/fworks/meteor/epool //search for text recursively
sudo ps -x | grep meteor
sudo kill -s KILL 29484
df list filesystem
sudo halt -p shuts down power
sudo ifconfig find ip adress etho innet addr is lan ip (ipconfig on windoows)

locate

sudo apt-get updat sudo apt-get install mlocate sudo updatedb locate libtinfo.so.5

e2fsck

finding port of address already in use

  $ sudo netstat -nlp | grep 80
  tcp  0  0  0.0.0.0:80  0.0.0.0:*  LISTEN  125004/nginx

or

 # sudo lsof -i :25
 COMMAND  PID        USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
 exim4   2799 Debian-exim    3u  IPv4   6645      0t0  TCP localhost:smtp (LISTEN)
 exim4   2799 Debian-exim    4u  IPv6   6646      0t0  TCP localhost:smtp (LISTEN)

home ubuntu

Ubuntu 12.04LTS

sudo halt -p

/etc/network/interfaces to make 10.0.1.101 static

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 10.0.1.101
netmask 255.255.255.0
gateway 10.0.1.1
dns-nameservers 8.8.8.8 10.0.1.1
lamp
https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu
http://10.0.1.101/info.php
ruby1.9.3 rails4.0.0
https://www.digitalocean.com/community/articles/how-to-install-ruby-on-rails-on-ubuntu-12-04-lts-precise-pangolin-with-rvm

tools

perl

handy code

remove blank lines from file

perl -wnl -e 'print $_ unless /^$/' infile.txt >outfile.txt

sed awk

lib/images/toolbar/list_ul.png
lib/images/toolbar/rule.png
lib/tpl/default/images/interwiki.png

People with shell access to their server can copy the text above and paste it into a file on the system, then run the following commands to check for and remove all those files. Only those that exist are removed.

grep -Ev "^($|#)" /tmp/removeold.txt | xargs -n 1 rm -f

If you are paranoid, replace the "rm -f" with "ls -la" to see what files will be deleted.

To remove directories as well as files you have to use: grep -Ev "^($|#)" /tmp/removeold.txt | xargs -n 1 rm -fd

However, some systems may not support the "rm -d" option for directory removal. In that case, you have to use recursive removal (just be sure to double-check that the file list does not include any paths that will delete too much): grep -Ev "^($|#)" /tmp/removeold.txt | xargs -n 1 rm -fr

regex

https://alligator.io/js/regular-expressions-for-regular-people/

http://exploringjs.com/impatient-js/ch_regular-expressions.html

https://www.smashingmagazine.com/2019/02/regexp-features-regular-expressions/

https://regex101.com/

php example

 $search = array(
   '@<script[^>]*?>.*?</script>@si',   // Strip out javascript
   '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags
   '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
   '@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments
 );
   $output = preg_replace($search, , $input);
   return $output;
 }

?> <?php function sanitize($input) {

   if (is_array($input)) {
       foreach($input as $var=>$val) {
           $output[$var] = sanitize($val);
       }
   }
   else {
       if (get_magic_quotes_gpc()) {
           $input = stripslashes($input);
       }
       $input  = cleanInput($input);
       $output = mysql_real_escape_string($input);
   }
   return $output;

}

typical

A username fro 3- 16 characters w -or_ /^[a-z0-9_-]{3,16}$/

a password 6-18 long /^[a-z0-9_-]{6,18}$/

a hex number /^#?([a-f0-9]{6}|[a-f0-9]{3})$/

a number sign is optional because it is followed a question mark but if there takes it(greedy)
6 characters or 3 character

a slug /^[a-z0-9-]+$/

beginning of the string (^), followed by one or more (the plus sign) letters, numbers, or hyphens. and the end of the string ($).

an email /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/

. get delimited \.
each section in parens

only lower case, nubers or dots'/[^a-z0-9.]/'

url /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/

s? s if you got em
delimit / and . with \
you don't need http at all (https?:\/\/)? but be greedy
\d is any number
([\da-z\.-]+) numbers letters dotts or hyphens
\.([a-z\.]{2,6})~ .com .co .commie
([\/\w \.-]*)*\/?$/ files and directories
([\/\w \.-]*) * is zero or more, \w is words

html tag /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/

.* any characters
([^<]+) any characters but a <
(?:>(.*)<\/\1>|\s+\/>) non-capture group.it will contain either a greater than sign, some content, and a closing tag; or some spaces, a forward slash, and a greater than sign \1 represents the content that was captured in the first capturing group

no dots: ^[^\.]*$

^ - beginning of string
[^\.]* - any character except ., any number of repetitions
$ - end of string

replace spaces and punctuation with nothing str.replace(/\W/g, )

\W not letters digits or underscores

to take out all non alpha characters (Ruby)

 test_str = "Madam, I'm Adam"
 str = test_str.gsub(/[^a-zA-Z]/,'')
 puts str
returns MadamImAdam


  • ^[ \t]+ //finds all the space and tabs
  • [1-9]\. //finds all the line numbers. (replace with #)
  • [A-E]\. //find A. etc (replace with ##)

to clean special characters from a string

$clean = preg_replace("/^[^a-z0-9]?(.*?)[^a-z0-9]?$/i", "$1", $text);

sites

expressions

If you want to get'Aloha World'out

Input:

Hello World
Aloha World
Hey There

RegEx:

  \<div\sclass\=\"somename\"\>(?<Text>.*?)\<\/div\>

Yields:

Aloha World (note: In a single group named Text)