Friday, February 26, 2016

bash command braindump

man -k ls /[search] help ls pwd eacho $PATH $BASH SSH 192.0.0.0 $ 1st promp > 2nd promp ls -alcat less /[search] file rm mv mkdir touch reset clear cd 'prog files' cd prog\ files ls ~/tmp/../temp/web1 ls ~ ls / cp -R docs newDir ls -R rmdir -r mv (safe -Ri -ri) ln -s ls [RegcatEx]a[RegEx] ls [abc_$]a[^abc]?.txt touch file{1,2}.{txt,jpg} cat>file1.txt ls >>file1.txt pgrep -u daemon |less grep 1978 file1.txt  cat -f 3 file1.txt | wc -l touch "note$(whoami).txt" touch "note$(date+%Y-%m-%d).txt"


find -name "*.txt" -exec grep -l Hello {} \; cat student.txt | tr Steve steve  tr \\t \; coldel.csv
ls -lS | head ls -lt |tail  tail -f Live.log ls -a |wc -l grep -v "^$" student.txt sort student.txt |uniq sort -nk2 -t\; Data.txt cut -f 3 -d\; Data.txt paste f1.txt f2.txt join f1.txt f2.txt

gedit delayed.sh & bash delayed.sh chmod u+x delayed.sh ./delayed.sh >output.txt & bg %1 ^Z bg fg ^c jobs kill %1 kill -KILL %cp ps -e | grep delayed* kill 9969 (dangerous) xkill pkill top

vi .bashrc :q ls -al $HOME |grep .bashrc find ~ -name ".prof*" alias  alias rm="rm -I" \rm alias dw="cd ~/Donwloads" echo $PS1 man bash /[search] PS1 n env echo $PATH PATH="$PATH:~/bin" >> .bashrc less text.txt v echo $SHELL chsh
sudo find -type f -name "/var/log/*.log" -print0 | xargs  -0 sudo chmod a+rw
ifconfig |grep 'inet'
set -o set -o noclober ls -l >| f1.txt history -c -r -w ls -l /etc>f.txt 2>&1 df -h
mkfifo p1 ls -l >p1 wc -l p1 mkfito /tmp/p1 ls -l !$ (last arg) ls -F !$ ls -l | tee f1.txt

Useful Command Line interface

^[A-Z][1,2]\s[a-z]{2}\b$--start-option-space-must-wordboundary-end [[ =~ ==* ]] pattern matching test [[ hello =~ h*o ]] && echo "matched" [[ hello =="h*o" ]] not a match of str
grep -i -v -E -ve '^#' -ve '^$'(case, inverse, enhance, multi expression as in e) grep '\bserver\b'
sed -i '/^#/d;/^$/d' (in-place really edit file,d=delete ; multi cmd) 

WinScp --open source Windows Ubuntu file copying
cat -vet notepad.sh show M$ dos2unix test.sh to remove
ls /proc cat /proc/version (all  process)
sudo -i switch to root, service apache2 restart, less /etc/passwd , 15G,goto, /[search]+n next PageUp/Dwn
cut -f1,3 -d':' /etc/passwd sort f1.csv (by 1st char) sort -r -k4 -t ',' -n f1.csv (revese, column 4 space and ',' deliminated) cut ...| sort...
cp/rm/mv -i -r -a (interactive, recursive, keep owner as in ls -lh) rm -rf dir1 (r+force)
ls -l lnk1= readlink lnk1 alias ls='ls --color=auto' -lt (time).
dd if=/dev/sda1 of=mbr count=1 bs=512 (disk image)
rsync -av /home/ /backup/ (keep owner, verbose, end / =dir) useradd -m bob userdel -r bob rsync -av --delete (sync deletion)
time tar -czvf etc.tgz /etc (create zip,verbose file) tar -tzf=file etc.tgz (test zip file) -xzf (expand)
find -newer -type f -delete -size +138k -exec ls -lh {} \;
find /usr/share -name '*.pdf' -maxdepth 2
cd /dev cd - // cd to prev out of dev

Process Command
dpkg -L procps which uptime uptime cat /procs/uptime (up, idle) /procs/loadavg
ps -t -l -e    sleep 180 & seconds jobs fg bg 
pgrep sleep  kill 2300 = pkill sleep killall sleep  kill -l (list all signals. e.g -9=sigkill=no-respondings)

top toggle l,t,m (load,cpu%,mem) f arrow s=sortby esc r=renice=lower priority k (invalid pid or 0 sig to esc)

vi q q! w x i : esc dw (del word), i, a (before, after) x=bsp=del I/A=begin/end of line u=undo
vi +603 /[search] f.c goto line 603 search when open,603G, 1G   b w $ ^ (back forward)
vi /etc/hosts  3,7w ip.txt (write out 3-7 words)
ln -s file1/dir1 slink1 symbolic=soft link ln file1 hlink hard link only to file

FAQ
tac = sed "1! G; h$!;d" sed -n "10p" f1.txt = head -10|tail -1 sed -n "5,$p"|sed "/MNO/s/ABC/DEF"
finger jimmy comm f1.txt f2.txt
sed -i "/^[(backslash)011(backslash)040]*$/d" f.txt oct for space/tab remove empty line.
grep -c "ABC" count line du -s jimmy disk usage summary egrep=ext cmdf3 2>f2 input to cmd out,err
awk 'END {print NR} filename' awk -F':' '{print $1} /etc/shadow' all user name. sed '100iABC' f.txt
find . -mtime -2 -exec wc -l {} \;  #must {}[space]\; mod last 2 days
umask 777 default rwx for all

Remove/Search/Replace -- param expansion
$() vs ${} ${str[op][pattern]} op=empty=> remove op=/ or // => search replace # begin % end, pattern=*?[] ##/%% #/% =>longest vs shorted in remove.
i="mytxt.txt" ${i/txt/jpg} myjpg.txt # not useful ${i/%txt/jpg} mytxt.jpg ${i//txt/jpg} myjpg.jpg
${i%txt} mytxt. ${i#*txt} .txt  ${i##*txt} empty ${i/[yx]/a} matxt.txt ${i//[yx]/a} matat.tat remove is replace with empty

default value --- v2=${v_unset:-99} echo $v2 99 v_unset=88 now echo $v2  88 end of option --  touch -a.txt failed touch -- -a.txt 


No comments:

Post a Comment