Skriptimine 2017: Difference between revisions
From ICO wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 134: | Line 134: | ||
'''fi''' | '''fi''' | ||
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html | http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html | ||
https://bash.cyberciti.biz/guide/If..else..fi | |||
==Debug mode== | ==Debug mode== | ||
Line 144: | Line 145: | ||
Juhul kui käsk õnnestus on exitkood 0 | Juhul kui käsk õnnestus on exitkood 0 | ||
Juhul kui käsu käivitamisel tekkis tõrke on exit kood 0'ist erinev | Juhul kui käsu käivitamisel tekkis tõrke on exit kood 0'ist erinev | ||
==Sisendi lugemine== | ==Sisendi lugemine== | ||
Line 153: | Line 155: | ||
https://www.cyberciti.biz/faq/bash-for-loop/ | https://www.cyberciti.biz/faq/bash-for-loop/ | ||
https://www.cyberciti.biz/faq/bash-while-loop/ | |||
https://bash.cyberciti.biz/guide/The_case_statement |
Revision as of 10:08, 13 April 2018
Linuxi käsud
Käsk | Funktsioon | Man link | Näidis |
---|---|---|---|
cd | Change Directory | http://www.skrenta.com/rt/man/cd.1.html | cd /var/log |
ls | list directory contents | http://www.skrenta.com/rt/man/ls.1.html | ls -lah /var/log |
ps | report process status | http://www.skrenta.com/rt/man/ps.1.html | ps -ef |
grep | print lines matching a pattern | http://www.skrenta.com/rt/man/grep.1.html | grep -R 'error' /var/log/* |
tail | output the last parts of file | http://www.skrenta.com/rt/man/tail.1.html | tail -f /var/log/syslog |
cat | concatenate files and print on the standard output | http://www.skrenta.com/rt/man/cat.1.html | cat /var/log/syslog |
man | format and display the on-line manual pages | http://www.skrenta.com/rt/man/man.1.html | man man |
su | run a shell with substitute user and group IDs | http://www.skrenta.com/rt/man/su.1.html | su - root |
cp | copy files and directories | http://www.skrenta.com/rt/man/cp.1.html | cp /var/log/syslog /tmp/tmp_syslog |
mv | move (rename) files/directories | http://www.skrenta.com/rt/man/mv.1.html | mv /var/log/syslog.5 /arhiiv |
rm | remove files or directories | http://www.skrenta.com/rt/man/rm.1.html | rm /tmp/tmp_syslog |
sed | Stream editor | http://www.skrenta.com/rt/man/sed.1.html | sed -ie 's/mida/millega/g' /tmp/tmp_syslog |
mkdir | make directories | http://www.skrenta.com/rt/man/mkdir.1.html | mkdir /tmp/skript |
chmod | change file access premissions | http://www.skrenta.com/rt/man/chmod.1.html | chmod 700 /tmp/skript/myscript.sh |
chown | change file owner or group | http://www.skrenta.com/rt/man/chown.1.html | chown student:student /tmp/skript/myscript.sh |
chgrp | Change group ownership | http://www.skrenta.com/rt/man/chgrp.1.html | chgrp root /tmp/skript/myscript.sh |
whoami | print effective userID | http://www.skrenta.com/rt/man/whoami.1.html | whoami |
pwd | print name of current/working directory | http://www.skrenta.com/rt/man/pwd.1.html | pwd |
awk | pattern scanning and processing language | http://www.skrenta.com/rt/man/awk.1.html | Echo one two | awk ‘{print $1}’ |
find | search for files in a directory hierarchy | http://www.skrenta.com/rt/man/find.1.html | find / -name passwd |
cut | remove sections from each line of files | http://www.skrenta.com/rt/man/cut.1.html | http://www.thegeekstuff.com/2013/06/cut-command-examples |
sort | sort lines of text files | http://www.skrenta.com/rt/man/sort.1.html | ls -la /var/log | sort -k5 -n |
bc | An arbitrary precision calculator language | http://www.skrenta.com/rt/man/bc.1.html | echo 5+5 | bc |
Bash-i info
If lause moodustamine
if [ Funktsioon ] then tee midagi fi http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html https://bash.cyberciti.biz/guide/If..else..fi
Debug mode
bash -x /skripti/path.sh
Exit koodid
Viimase käivitatud käsu exit koodi leiate muutujast $? Juhul kui käsk õnnestus on exitkood 0 Juhul kui käsu käivitamisel tekkis tõrke on exit kood 0'ist erinev
Sisendi lugemine
read muutujanimi read -p "tekst" muutujanimi
Bash tsüklid
https://www.cyberciti.biz/faq/bash-for-loop/ https://www.cyberciti.biz/faq/bash-while-loop/ https://bash.cyberciti.biz/guide/The_case_statement