Diverse Commando's
Algemene tips en trucs
Linux maakt onderscheid tussen hoofdletters en kleine letters.
Linux gebruikt een slash / om directories van elkaar te scheiden. DOS gebruikt hiervoor een backslash.
In tegenstelling tot DOS kijkt Linux niet of het uit te voeren programma in de huidige directory staat. Als het programma dat je wilt uitvoeren niet in het path staat, moet je de directory expliciet aangeven. Als het programma in de huidige directory staat, moet je er ./ voor zetten.
Met alt-f1, f2, ...f9 kun je schakelen tussen verschillende virtual consoles. alt-f7 is meestal de console waar X-windows op draait. Om vanuit X-windows naar een van de text consoles te schakelen, moet je ctrl-alt-f1, f2, ... gebruiken.
ctrl-alt-backspace stopt de X-server (wordt meestal automatisch herstart). Tegenwoordig is dit meestal uitgeschakeld.
Als je achter een commando een & teken typt, wordt dit proces losgemaakt van de shell, zodat je verder kunt werken terwijl het commando op de achtergrond draait. Als een proces te lang duurt, kun je het onderbreken met ctrl-z, en daarna alsnog op de achtergrond laten doordraaien met het commando bg. Met 'fg n', met n het procesnummer, kun je een proces weer op de voorgrond halen.
Installing linux
If installation from cdrom is not working right, try booting with 'linux ide=nodma'
Getting help
help geeft een lijst met all build-in bash commando's
help x geeft uitleg over het bash build in commando x
info help systeem
man help systeem
whatis geeft een korte omschrijving van een commando
file somefile geeft een korte omschrijving van een file
Working with files
ls lijst van files en subdirectories
ls -d */ list alleen subdirectories
cd change directory
pwd path van huidige directory
cp copy
cp -r copy also dirs
rm qwe Remove file 'qwe'
rm -rf qwe Remove directory 'qwe' and dissable prompt for confirmation
chmod wijzigen van toegangrechten van bestanden
chmod 777 somefile Makes somefile executable
chmod -R a+rw . Stel de toegangsrechten van dehuidige directory, en alle sub-directories in op lezen en schrijven
grep -r "qwe" * doorzoek alle files in de directory boom, en zoek naar de string "qwe"
grep -rn "#define MB_LEN_MAX" . --exclude-dir=proc --exclude-dir=sys
find -name "qwe*" doorzoekt de directory boom en geeft alle file names die beginnen met "qwe"
find -mtime 2 vindt alle files die de afgelopen 2*24 uur zijn gewijzigt
find -mmin 20 vindt alle files die de afgelopen 20 minuten zijn gewijzigt
find -name somename | xargs md5sum run a program (in this case md5sum) on each result
Getting your bearings on the command line
pwd Gives your current directory
ls list files in your current directory
whoami Gives your user name
uname -a Gives the version of your kernel
hostname Shows the name of your system
cat /etc/os-release Print some info about your distro
who Gives a list of all logged-in users
ip a See your IP address
ping google.com Check if you have internet access
exit Close your current shell
Getting system info
ps aux | head list of all processes
top interactive live list of all processes
dmesg Prints the messages in the kernel ring buffer
df -h hoeveel disk space vrij is
du -hs * geeft groote van alle files en sub directories
free -h hoeveel geheuger er vrij is
pstree lijst van processen in een tree formaat
lsmod Lists loaded kernel modules
which qwe geeft het voledige pad van executable 'qwe'
blkid Laat de UUID's van de partitions zien
cat /proc/cpuinfo geeft informatie over de processor
cat /proc/meminfo geeft details over het geheugen
cat /proc/version geeft details over versie van kernel
//lsblk -a Lists info about block devices //lscpu Lists CPU information \journalctl -xb view system log \lspci list all PCI devices \lspci -v -s 0:2 lists detailed info aboutpci device in slot 0:2 \lsusb Lists all usb devices \lsusb -v -s 1:3 Lists detailed info about usb device in slot 1:3
\ldd qwe geeft de libraries die executable 'qwe' nodig heeft \ldd $(which qwe) combinatie van de bovenste twee \lsof lijst van alle open files. Is nuttig als umount niet lukt omdat de device busy is.
## systemd
systemctl status Gives status of all services, or for a specific one if you give it as argument systemctl start / stop / restart systemctl enable / disable journalctl systemctl list-units list all units which are started by systemd systemctl --failed Shows everthing which has failed
## User and permission administration
adduser voeg een nieuwe gebruikertoe adduser user1 somegroup Add user1 to the somegroup group. Often you want to add a user to the sudo group. addgroup somegroup Create a new group passwd wijzig het password su start een shell met de identiteit van root. Je blijft je eigen environment houden, (dus geen /sbin in je path) su - Zelfde als su, maar nu werk het beter omdat je ook de root environment variable hebt, zodat /sbin in het path staat. su user2 start een shell met de identiteit van user2 chgrp -R myGroup * Change group ID of all files chown -R marnix:employee * Change ownder of all files and dirs
## System administration
mkdir qwe maak een nieuwe directory rmdir qwe verwijderd directory mknod maak een device file ln -s myTarget myLink maakteen nieuwe symbolic link myvar=hello defines environment variable myvar tobe 'hello' $myvar use environment variable myvar set geeftalle environment variabelen unset myvar delete environment variable myvar export myvar maakt myvar beschikbaar voor child-processes? echo \(PATH geeft de PATH environment variabele PATH=\)PATH:/mydir voegt 'mydir' aan het search path toe ps -Al lijst van alle processen kill -kill n stopt het process met pid n insmodfoo laad module foo in dekernel rmmodfoo verwijderd modulefoo uit de kernel alias l=ls maakt een alias alias -p print allegedefineerde aliassen halt stopt linux init n schakeld het systeem in runmode n chroot qwe/ start een shell en gebruik qwe/ als root directory exit verlaat een shell startx starts the X-server and the default graphical shell
service --status-all Laat de status van alle services zien service smbd restart Restart een service. Je kunt ook start en stop doen.
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target Disable sleep and hibernation (use 'unmask' to enable them again)
## File system
fdformat /dev/fd0 formateert een floppy mke2fs /dev/fd0 maak een filesystem op een floppy dd if=device1 of=device2 kopieert data van device1 naardevice2 dd if=/dev/zero of=file count=1000 maak een file met 1000 nul-bytes fdisk -l /dev/hda list the partition table fdisk -s /dev/hda1 geeft de grootte van een partitie in kByte pivot_root new/ old/ mount new/als het nieuwe root filesystem, en mount het huidige op old/ umask 000 Give new files have read, write and execute permision for all users
## Graphical user interface
systemctl start lightdm systemctl stop lightdm
cvt 1920 1080
xrandr --newmode "1366x768" 85.25 1368 1440 1576 1784 768 771 781 798 -Hsync +Vsyn
xrandr --addmode VGA1 "1366x768"
xrandr --addmode VGA-1 "1920x1080_76.00"
## Compression
tar -cf qwe.tar * Combine all subdirs into 'qwe.tar' gzip qwe.tar Compres 'qwe.tar' to 'qwe.tar.gz' bzip2 qwe.tar Compres 'qwe.tar' to 'qwe.tar.bz2' gzip -d qwe.tar.gz Uncompres bzip2 -d qwe.tar.bz2 Uncompres tar -xf qwe.tar Extract all filesfrom .tar file tar -zxf qwe.tar.gz Extract all filesfrom .tar.gz file tar -jxf qwe.tar.bz2 Extract all files from.tar.bz2 file
## Building software
gcc foo.c compileer de c broncode file foo.c
g++ foo.cpp compileerde C++ broncode file foo.cpp
gcc foo.c-L/usr/X11R6/lib-lX11 compileer een X-programma
gcc gtk-config --cflags --libsfoo.c compileer een GTK+programma
ndisasm qwe.bin disasseble a binary file
make xconfig configuratie scherm voor compile opties voor kernel
make dep; make clean; make bzImage build een nieuwe kernel
make modules build kernel modules
make modules_install kopieerd de modules naar /lib/modules
Extracting a source RPM rpm -i/mnt/cdrom/SRPM/qwe.src.rpm
Apply patches cat qwe-asd0.1.2.patch | patch -p0
Generate a make file ./configure
Start building make
Install the software make install
## Network
ssh 192.168.0.2 log in op 192.168.0.2 insmod natsemi laad de driver voor een national semiconductors netwerkkaart in de kernel ip a geeft informatie over actieve netwerkkaarten ifconfigeth0 192.168.0.1 actieveert deethernerkkaart dhclient actieveertde netwerkkaart via dhcp netstat -apn shows processes that listen orcommunicate over the network netstat -lpn shows onlylisten sockets smbd SMB-server; onderdeel van Samba. nmbd netBIOS name server; onderdeelvan Samba. smbclient geeft toegang tot bestanden op een andere pc smbtree geefteen lijst met smb hosts op het netwerk httpd Start de Apache web-server ping 192.168.0.2 Checksand times a tcp/ip route to a host nmap -sS 192.168.0.2 Do a port scan nmap -p 22 --open 192.168.123.0/24 Scan the network for open ssh ports. Finds al the targets for which the first 24 bits of the address match resolvectl Laat zien welke DNS servers je gebruikt
## Installing Software
wget http://ftp.nl.debian/somefile Downloads somefile from internet
### With RPM
Location of RPM database /var/lib/rpm
rpm -i qwe.rpm Instals package "qwe" rpm -i --nodeps qwe.rpm Instals package "qwe",even if dependentcies are missing rpm -i --root /mydir qwe.rpm Instals package while using directory /mydir as root
rpm -e qwe Remove package qwe rpm -e --nodeps qwe Removepackage qwe, even if it breaks dependencies
rpm -qa List alle geinstallerde packages rpm -qg Asd/Zxc list geinstallerdepackages in groep Asd/Zxc rpm -qi qwe geeft een beschrijvingvan geinstalleerde package qwe rpm -qpi qwe.rpm geeft een beschrijving van package qwe rpm -qpl qwe.rpm list de files in package qwe rpm -ql qwe list alle files ingeinstalleerde package qwe rpm -qf /usr/bin/foo geeft de package waar foo in zit
### With YUM
yum install somepackage
## Debian packages
List of repositories /etc/apt/sources.list(contains for example: http://archive.ubuntu.com/)
dpkg -i something.deb Installs package something.deb dpkg -l Lists all installed packages dpkg -l something List packages which contain 'something' in their name dpkg -S somefile See which package provides somefile dpkg -x somepackage.deb qwe Extracts somepackage.deb to the qwe directory dpkg -I somepackage.deb Shows info about somepackage.deb
apt-cahce search something search for the string "something" in all available pacakges apt install something download and installs something apt install something --reinstall Re-installs a package. Usefull for repairment if some file of the packege became corrupt or missing apt install -f something.deb installs a local deb package apt --purge remove qwe Remove package qwe
apt update Resync the package index files wiht the locations found in /etc/apt/sources.list apt upgrade Install latest version of all currently installed packages apt check Check for broken dependencies
apt remove somepackage Removes packages somepackage but keeps configuration files apt remove somepackage -s Simulate the removal of a package apt purge somepackage Completely removes somepackage and all its configuration files apt dist-upgrade
apt-cache search something This command will find packages that include the string something apt-cache show somepackage Shows detailed info of somepackage
apt download somepackage Download the .deb file of somepackage
apt-cache rdepends somepackage Laat zien welke pakketen afhankelijk zijn van somepackage
aptitude Een curses applicatie waarmee je de apt database kunt bekijken
aptitude why somepackage Laat zien waarom een package geinstaleerd zou kunnen zijn (op basis van dependency info in andere packages)
sudo update-alternatives --config editor Manages the symbolic links that determine the alternatives for certain tools
## Applications
factor n factoriseerd n in priemgetallen
GUI apps
xkill kill a gui application via a mouse click gtop grafische tool die alle actieve processen laat zien display start ImageMagic netconf configureren van netwerk gnome-session starts the gnome desktop system startlxde-pi start the lxde destop environment on the raspberry-pi
sort somefile.txt sorts the lines of a file aphabetically
## Samengestelde commando's
--------------------------------------------------------------------------------
Generate a word-frequency list of a text file:
cat file1 | tr ' ' "\n" | sort | uniq -i -c | sort -g -r > file2
--------------------------------------------------------------------------------
Find out to which package a command belongs. Replace <b>foo</b> with the
name of the command you want to look up
rpm -qf which <b>foo</b>
--------------------------------------------------------------------------------
Hexdump of an file
cat myfile | xxd -g1 | less
--------------------------------------------------------------------------------
View the binary contents of a partition. Replace n whith the
block you want to see.
dd if=/dev/hda1 bs=1k count=1 skip=n | xxd -g1 | less
--------------------------------------------------------------------------------
Open port 1200 and connect it to a shell
netcat -l -p 1200 -e /bin/bash
--------------------------------------------------------------------------------
See which serial ports (COM ports) are connected:
sudo dmesg | grep tty
--------------------------------------------------------------------------------
Find all changed files on your system:
find / -type d \( -path /proc -o -path /sys \) -prune -o \( -cmin +2 -a -cmin -10 \) -print 2>/dev/null ```