Commands

From Systerserver

Jump to: navigation, search

Contents

Command examples

Generic *nix interaction:

  • tune2fs -l /dev/sda1 (list info)
  • tune2fs -c 80 /dev/HARDDRIVE (fsck will run after 80 mounts)(30 is default in ubuntu)
  • tune2fs -L DATA /dev/HARDDRIVE (to set a volume label)
  • top/htop/atop and iftop/ntop
  • strace -p pid
  • lsof -p pid
  • which thunderbird (lists the full pathnames of the files that would be executed if the named commands had been run)
  • whereis thunderbird (finds the binary, source, and manual page files for a command)
  • udatedb, locate
  • find -name Aaf_*
  • du --max-depth=1
  • du -sh (-s = summarize, h = human readable)
  • du -s * |sort -nr (* is for both files and directories), sort in reverse numerical
  • du : disk usage (word of caution is that you should not run this command from the / directory. It will actually display size for every file on the entire Linux harddisk), eg du -a (all) http://www.linfo.org/du.html
  • df : disk free, eg df -alh
  • watch -d -n 2 'df; ls -FlAt;' (like top but for files instead of processes)
  • fdisk -l | grep -i disk
  • ls -ldct /lost+found |awk '{print $6, $7}'
  • cd -
  • sudo !!
  • mount |column -t
  • watch -n1 df -h -B M /media/disk/ ie how fast data is being copy'd (refreshes every 1 second)
  • ssh -X donna@23.42.23.42 xeyes (X forwarding, then start an app on remote server)
  • ssh -vD 8080 donna@23.42.23.42 (v = verbose, D = bind address, use any random port number)
  • then in firefox you need to set the proxy, ie localhost to use por 8080
  • check that your ip adres really has changed by browsing www.myip.dk in ff
  • ssh -t user@domain.com ssh user@otherdomain.com
  • iptraf instead of iftop
  • mtr, cfdisk, hwinfo, nmap, netstat, mc
  • for u in dani geert rian victy marlin ester; do sesame.sh -u $u Projects ; done
  • but what does the sesame.sh script do??
  • e2fsprogs includes: e2fsck, mke2fs, resize2fs, tune2fs, e2fsck, debugfs

Special characters

\ ' " ` < > | ; <Space> <Tab> <Newline> ( ) [ ] ? # $ ^ & * =

Here is the meaning of some of them:

  • \ ' " and ' are used for quoting.
  • < and > are used for input/output redirection.
  • | pipes the output of the command to the left of the pipe symbol "|" to the input of the command on the right of the pipe symbol.
  •  ; separates multiple commands written on a single line.
  • <Space> and <Tab> separate the command words.
  • <Newline> completes a command or set of commands.
  • ( ) enclose command(s) to be launched in a separate shell (subshell). E.g. ( dir ).
  • { } enclose a group of commands to be launched by the current shell. E.g. { dir }. It needs the spaces.
  • & causes the preceding command to execute in the background (i.e., asynchronously, as its own separate process) so that the next command does not wait for its completion.
  • * when a filename is expected, it matches any filename except those starting with a dot (or any part of a filename, except the initial dot).
  •  ? when a filename is expected, it matches any single character.
  • [ ] when a filename is expected, it maches any single character enclosed inside the pair of [ ].
  • && is an "AND" connecting two commands. command1 && command2 will execute command2 only if command1 exits with the exit status 0 (no error). For example: cat file1 && cat file2 will display file2 only if displaying file1 succeeded.
  • || is an "OR" connecting two commands. command1 || command2 will execute command2 only if command1 exits with the exit status of non-zero (with an error). For example: cat file1 || cat file2 will display file2 only if displaying file1 didn't succeed.
  • = assigns a value to a variable. Example. The command: me=blahblah assigns the value "blahblah" to the variable called "me". I can print the name of the variable using: echo $me
  • $ preceeds the name of a variable to be expanded. The variables are either assigned using "=" or are one of the pre-defined variables (which cannot be assigned to):

$0 name of the shell or the shell script being executed.

$# number of the positional parameters to the command

$1 the value of the first positional parameter passed to the command. $2 is the second positional parameter passed to the command. etc. up to $9.

$* expands to all positional parameters passed to the command

$@ expands to all positional parameters passed to the command, but individually quoted when "$@" is used.

See man bash if you really need more.

Backticks are outdated.

  • program1 $(program2 $(program3 $(program4)))
  • program1 `program2 \`program3 \`program4\`\``

Debian specific

use of root and su -

/sbin staat niet in het pad van de gewone gebruiker

dus voor ifconfig moet je /sbin/ifconfig

of je moet het pad gaan aanpassen

of je moet als root inloggen

Ubuntu specific

by default no root and first user is put in the sudoers file

MediaWiki

prevent new user account creations add to LocalSettings.php: $wgGroupPermissions['*']['createaccount'] = false;

disable anonymous editing add to LocalSettings.php: $wgGroupPermissions['*']['edit'] = false;

add a page to the navigation bar: log in as WikiSysop, goto index.php?title=MediaWiki:Sidebar&action=edit

overview index.php/Special:SpecialPages

to see all the pages made (this is how i found spam pages) Special:Allpages

to see everyone that's made an account Special:ListUsers

add &printable=yes to the URL to view printable version of page, eg yourdomain.com/wiki/index.php?title=Main_Page&printable=yes

things to change in the skin, eg to gumax:

changes to LocalSettings.php:

$wgDefaultSkin = 'monobook';

$wgLogo = '/path/to/your/logo.png';

changes to GuMax.php:

remove window: gumax-article-picture section

delete footer list: f-list section

changes to main.css and/or gumax_template.css in skins/gumax/:

in body: background: #f9f9f9 url(headbg.jpg) 0 0 no-repeat;

Networking

  • ifconfig = interface configure
  • ifconfig eth0:0 192.168.1.1/24
  • ip addr add 192.168.1.1/24 label eth0:1 dev eth0
  • route -n (no domain name resoving, is faster)
  • route delete default (delete the default gw)
  • route add default gw 10.8.8.8 (need to know that beforehand)
  • pico /etc/network/interfaces
  • nano /etc/resolv.conf (nameserver)
  • or : echo "nameserver 208.67.220.220" >> /etc/resolv.conf
  • See also : http://linux-ip.net/html/basic-changing.html
  • ethtool

MySQL

  • CREATE DATABASE example_db;
  • GRANT ALL ON mydb.* to db_user@localhost IDENTIFIED BY 'db_passwd';
  • FLUSH PRIVILEGES;
  • SHOW databases;
  • USE mydb;
  • mysql -u username -p -h localhost mydb < data.sql; #to import an sql dump
  • DROP DATABASE mydb; #to delete a database
  • CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;
  • DESCRIBE table; to view contents of table
  • view the entries with SELECT * from tablename;
  • use INSERT to add and UPDATE to change a row
  • change the table layout you can use ALTER TABLE
  • pas heel goed op dat je de juiste condities aan update meegeeft
  • anders verander je de value voor alle records