Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # first of all I played with shh / scp / rsync commands
- # and created a bit ugly script on perl, which expands all crap,
- # I stored at structure things like
- # host_name, user_id, password or file with password
- # port, e.t.c.
- #
- # so, it's easy to login and trassfer files now
- # if password exists, all commands gain prefix
- # sshpass -p bandit0 | sshpass -f ~/tmp/bash_game/../loaded_file
- # ssh user -> ssh user@server
- # scp user:path -> ssh user@server:path
- # scp user:'path with spaces' -> ssh user@server:"path\ with\ spaces"
- #
- # also port auto added if exists at config
- # scp user:smth -> scp -P 2220 user@server:smth
- # scp user -> scp user@path -p 2220
- # rsync -R user:smth -> rsyn -e 'ssh -p 2220' --info=progress2 -R user@....
- #
- # script on perl
- # https://pastebin.com/n7zPMMDq
- #
- # aliases for bash, which uses script
- # https://pastebin.com/ecaU6XCm
- # 0->1
- cat readme
- # 1->2
- cat ./-
- # 2->3
- cat 'spaces in this filename'
- # 3->4
- cd inhere
- ll
- cat .hidden
- # 4->5
- cd inhere/
- find . -exec file "{}" \; | grep ASCII | grep -v Non;
- # 5->6
- find inhere/ -readable -and -size 1033c -and ! -executable | cat
- # 6->7
- #1. using find options
- find / -user bandit7 -group bandit6 -size 33c 2>/dev/null
- # 2. find used only to iterate file
- find inhere/ -type f | while read -r f; do ls -l "$f"; done | perl -awne 'print "$F[-1]\n" if ($F[0] !~ /x/ && $F[4]==1033)' | while read -r f; do file "$f"; done | grep 'ASCII text' | cut -d: -f1 | (x=$(cat);cat $x)
- # explanation
- # a) ls prints giant table for each file
- # b) data from std_in read via read -r line by line
- # c) next perl oneliner works
- # perl options -awne
- # -e -- execute, perl -e 'some_code here' - common oneliner notation
- # -w -- warnings, print warnings to debug code
- # -n - wrap code to cycle, default cycle variable $_ store line of input
- # BEGIN {some code} # optional
- # while (<>) {
- # 'my code here'
- # print $_; # $_ contains result of read -r _
- # }
- # END {some code} # optional
- # -a -- autosplit by ' ', each line splited and stored at array @F
- # it's possible to user delim -F: - split via ':'
- # d) use comand file on each output file via read again
- # e) grep readable file
- # f) get only file name part
- # g) cat file, it's possible to get file_name with read -r, but I got with $(cat) for fun
- # a=$() runs anonymous shell, executes what inside and put result to variable `a`
- # cat by default reads std_in, but this time std_in is ouput from prev command
- # 3. same, but via xargs versus while ... done and $(cat)
- find inhere/ -type f | xargs -I {} ls -l "{}" | perl -awne 'print "$F[-1]\n" if ($F[0] !~ /x/ && $F[4]==1033)' | xargs -I {} file "{}" | grep 'ASCII text' | cut -d: -f1 | xargs cat
- # explanation
- # -I macro some_command arg1 "smth macro smth2" arg2..., so it's possible to use macro multiple times
- # {} - notation from file -exec, but it could be any
- # 7-8
- grep millionth data.txt | cut -f2
- # 8->9
- # create struct for perl - hash a
- # a = (
- # 'first_str' = 3, # 3 times count
- # 'second_str' = 2,
- # ...
- # 'last_str' = 8,
- # )
- cat data.txt | perl -ne 'BEGIN{%a=();}$a{$_}++;END{while(($k,$v) = each %a) {print $k if $v==1}}'
- # 9->10
- cat data.txt | perl -ne 'print "$&\n" if $_ =~ /={2,}\s+\K\w{5,}/'
- # want at least 2 '=' and at least 5 [a-zA-Z0-9], e.g. \w
- # \K removes all matched from group
- cat data.txt | grep -aPo '={2,}\s+\K(\w{5,})'
- # -a for binary files
- # -o - only matching strings
- # -P - perl regexp engine
- # 10->11
- base64 --decode data.txt
- # 11->12
- cat data.txt | perl -pe 'tr/N-ZA-Mn-za-m/A-Za-z/'
- tr 'A-Za-z' 'N-ZA-Mn-za-m' < data.txt
Add Comment
Please, Sign In to add comment