This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:scripts:basics [2014/10/01 13:21] – lunetikk | linux:scripts:basics [2021/01/07 14:55] (current) – lunetikk | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | |||
| - | ===== Linux Commands ===== | ||
| - | |||
| - | ^ Command | ||
| - | | cd / | ||
| - | | pwd | shows current directory | ||
| - | | ls | shows all files and folders in the current directory in one line -> confusing) | ||
| - | | ll | = ls –al -> shows all files and folders + owner + size, 1 item each line |\\ | ||
| - | | alias | shows alias like „..“ for „cd ..“ |\\ | ||
| - | | cat [textfile] | ||
| - | | tail [-f -n 20] | displays the last 20 lines of the file – extension „–f“ refreshes the file, extension „–n 20“ displays the last 20 lines |\\ | ||
| - | | head | same a tail but it displays the first lines |\\ | ||
| - | | touch [file] | ||
| - | | chmod 777 [file] | ||
| - | | chown user:group [directory] –R | change owner and group, -R changes the complete directory including files and subdirectorys | ||
| - | | useradd –m | add a user |\\ | ||
| - | | groupadd | ||
| - | | cp source target [-r -a] | copy data, -r copy directory, -a keep the rights | ||
| - | | mv source target | ||
| - | | rm –r | removes a directory with all data in it / rmdir only removes empty directorys | ||
| - | | cut –d : -f 1,3 | : is the delimiter and 1 and 3 are the columns | ||
| - | | echo " " > test.sh | ||
| - | | which sutp | shows path of sutp |\\ | ||
| - | | echo $? | 0 = success of the last command | ||
| - | | env | run a program in a modified environment | ||
| - | | uptime | ||
| - | | mkdir –p / | ||
| - | | rpm –ivh | ||
| - | | mount / | ||
| - | |||
| - | |||
| - | ===== Debian Commands ===== | ||
| - | |||
| - | ^ Command | ||
| - | | apt-cache search [Package] | ||
| - | | apt-get install [Package] | ||
| - | | apt-get update | ||
| - | | apt-get upgrade | ||
| - | | apt-get remove [Package] | ||
| - | | apt-get purge [Package] | ||
| - | | dkpg --install [Package.deb] | ||
| - | | aptitude install [Package] | ||
| - | | service [Service] start/ | ||
| - | |||
| - | |||
| - | \\ | ||
| - | == EasterEggs == | ||
| - | |||
| - | ^ Command | ||
| - | | apt-get moo | Try it out ;) |\\ | ||
| - | | aptitude moo | Try it out and add aptitude -v[vvvvv] moo ;) |\\ | ||
| - | |||
| - | |||
| - | |||
| ====== Script ====== | ====== Script ====== | ||
| Line 62: | Line 8: | ||
| | $VAR | inserts var whereever $VAR is placed | | $VAR | inserts var whereever $VAR is placed | ||
| | case - esac | inserts case | | | case - esac | inserts case | | ||
| - | | if - fi | inserts if | | + | | if [ " |
| + | |||
| + | ==== if conditions ==== | ||
| + | |||
| + | ^ Operator | ||
| + | | -eq | Returns true if two numbers are equivalent | ||
| + | | -lt | Returns true if a number is less than another number | ||
| + | | -gt | Returns true if a number is greater than another number | ||
| + | | == | Returns true if two strings are equivalent | ||
| + | | != | Returns true if two strings are not equivalent | ||
| + | | ! | Returns true if the expression is false | | ||
| + | | -d | Check the existence of a directory | ||
| + | | -e | Check the existence of a file | | ||
| + | | -r | Check the existence of a file and read permission | ||
| + | | -w | Check the existence of a file and write permission | ||
| + | | -x | Check the existence of a file and execute permission | ||
| + | | -z | string is null, that is, has zero length | ||
| + | | -n | string is not null. | | ||
| + | |||
| + | https:// | ||
| ===== Troubleshooting ===== | ===== Troubleshooting ===== | ||
| Line 68: | Line 33: | ||
| ==== Interpreter error ==== | ==== Interpreter error ==== | ||
| - | Problem: | + | === Problem: |
| Running your script prompts interpreter error\\ | Running your script prompts interpreter error\\ | ||
| - | Fix: \\ | + | === Fix: === |
| Open your script with vi and execute the following | Open your script with vi and execute the following | ||
| < | < | ||
| Line 77: | Line 42: | ||
| ==== Not enough rights ==== | ==== Not enough rights ==== | ||
| - | Problem: | + | === Problem: |
| Running your script requires more rights | Running your script requires more rights | ||
| - | Fix:\\ | + | === Fix: === |
| - | Make your script | + | Make your script |
| < | < | ||
| + | \\ | ||
| + | \\ | ||
| + | ~~DISCUSSION: | ||