Bash Programmierung
USEFUL THINGS:
- tab: auto completion
- tab 2x: list with all possibilitys
- piping: command | commannd2: | = output send to the next command
- command > test.txt: overwrite the output of the command in the textfile
- command >> test.txt: append the output of the command in the textfile
- command 2> test.txt: indicates that you are interested inredirecting only error output
- command 2> error.txt > output.txt: combination of both commands
- /dev/zero > /dev/sda: will erase all data on your hard drive and put zeroes there instead
- Dash = normal user
- Bash = root user -> more functions
- STDIN = 0 (input)
- STDOUT = 1 (output)
- STDERR = 2 (errors)
COMMANDS:
- aptitude: graphical interfaces for installed packages
search KEYWORD: search an package with the keyword
- cdrecord -data etherboot-net.iso
dev=1,1,0
-v: Speed
-audio /folder/*.wav
- chkconfig: for set off/on services at startup
- dd if=/dev/cdrom of=/mycd.iso: to make a iso of the cdrom
if: input file
of: output file
- df: shoes usage of harddisk space
- dpkg: package manger database for apt-get
-l: list all installed packages
- dmesg | grep eth0 -> Hardware testen
- du FILE: estimate file space
-s: silent
- eject: open the CD or DVD drive and eject the optical media that is currently in the drive
-t: close the tray
- env: Variables of the environment -> use with $variable in the shell
- find /home -name "hosts*": shows all files that starts with hosts
find / -user "alex": shows all files created by alex
find / -user "alex" -exec cp {} /groups/sales \; -> exec start with the outputfiles a 2. com.
- free: shows information about memory usage on your system
-m: Shows in Meabyte
-t: Shows total
- getent passwd: zeigt passwd inkl. ldap an
- grep TEXT: search for TEXT inside a txt document
grep TEXT /etc/*: search in the subfolders of /etc
^text: searches for text at the beginning of a line
text$: searches for text at the end of a line
\<text: searches for text at the beginning of a word.
text\>: searches for text at the end of a word
-i: case insensitive
-r: rekursiv
- history: Shows a list of commands of the history -> to use a command: !number of command
-c clear the history
- less: to read files
ls -l | less -> piping
- ln -s ORIGINALFILE LINK: create a symbolic link
- ls: list directory
-d *.a: show lists of files that ends with .a
-d [abc]*: show lists of files thet start with a, b or c
- lsmod: shows the loaded modules
- lsusb: shows the usb-connections
- passwd: change Password of user
-l: locks the account of a user
-u: unlocks a locked account
-e: Forces the user to change his or her password upon next login
- partprobe /dev/sdb: refresh the partition informations for ther kernel -> /proc/partitions
- ps aux: produces a list of all processes active at your server
- ps -A: list all process status
- man passwd: show manual about passwd
-k test: show all manuals that have they keyword inside the manual
- mkdir: create directory
-p: create also subdirectory same (mkdir /same/test)
- mount -o loop /mycd.iso /mnt: to mount an iso file in /mnt
mount //192.168.1.100/clonezilla /home/usb -o user=silvan
mount -t cifs -o username="wydsi1,domain=brig" //172.17.0.10/wydsi1 /mnt
-> zuerst smbmount installieren!!! (smbfs)
-t cifs -o username=yourname //lor/myshare /mnt: so mount a windows share
-o remount,rw /: when system starts with errors and only read
-t vfat: for type fat
-t iso9660 -o loop: mount an iso-file
-t cifs: for network connections as windows or samba
- netstat -tulpen: produces a list of all processes that are offering network connections on your server
- rm: remove files
-rf remove directory with all files inside
- smbmount //192.168.1.80/Exchange /backup/temp -o username=silvan,password=,uid=silvan
- split รข€“b 1000m /path/to/large/file /path/to/output/file/prefix
cat prefix* > NEWFILENAME: for unspliting
- su: switch user -> ohne user wird root genommen
- tar
-c: create archive
-C: change to directory DIR
-f: .tar file
-g: create snapshot file for incremental backups
-j: bz2
-t: list content of archive
-x: extract archive
-z .gz
-xf blah.tar: extract blah.tar
-jxf: for .bz2 files
-zxf: for .gz files
-cf somefile.tar /somedirectory: make
tar -czvg /backup/snapshot-file -f /backup/full-backup.tar.gz /home -> for incrementel backup
tar c . | tar xC /home/test : copy all files from DIR (.) to /home/test
- trail FILE -> show last 10 lines (rows) of a file
- useradd USER
-m: create Home folder -> when forget this option -> /etc/skel
-e YYYY-MM-DD: expiration date of the user
-G: add additional groups to the default (/etc/default/useradd)
-g: sets the primary group of a us
- userdel: doesn't delete the home folder
-r: deletes also the home folder!
-rf: deletes also the files that aren't owned by the person to delete
- usermod
- vol_id: shows informations about volumes
- w3m: to show html files in w3m browser
- who: displays a list of users currently logged in
- wodim: for burning cd's
--scanbus: shows the devices
- zcat changelog.gz | less: to read .gz files in /usr/share/doc
