Linux commands ~~~~~~~~~~~~~~ #!/bin/sh beginning of bash script man command manual pages info command manual pages rm -rf / ;-) cp -r copies a directory recursively cp -p preserves attributes and permissions of the file rename .htm .html *.html renaming of files (from file 1 to file 2) lsmod lists all modules installed at present from the kernel lspci lists all PCI devices depmod -a adds new compiled module to list of known modules pico -z very simple text editor (-z enable suspend mode) uname -a displays kernel version information dmesg displays kernel boot messages sh runs or processes jobs through the Bourne shell exec execute a command cal displays calendar date displays date and current time users displays all users logged on who prints who is currently logged in last displays login and logout information about users and terminals clear clears text out of the top of a terminal history prints out about the last 1000 commands du -h shows size in megabytes of current directory, as well as all subdirectories df -h shows space used and available on filesystems env displays exported environment variables, like the path and other interesting stuff xhost server access control program for X ifconfig get a listing of all of your current network interfaces and their settings mii-tool view, manipulate media-independent interface status vconfig VLAN (802.1q) configuration program netstat -rn displays the kernel routing table as dotted quad IP numbers netstat -a shows connections on all network connections/sockets netstat -l listening sockets only netstat -p shows processes listening and includes PID. Useful to kill processes hogging key ports arp manipulates system ARP cache arping send ARP REQUEST to a neighbour host iostat -kx 2 IO statistics wget -m retrieves files from the Web (-m mirror with infinite recursion) sudo lets ordinary users perform certain tasks as root or some other privileged user dig @ns domain mx|any is indexing and searching system for a domain or intranet (dig domain.com mx) dig -x reverse lookups - mapping addresses to names iptables -vL -t nat configuration of nat iptables -vL -t filter configuration of ip traffic filter tcpdump -l -n dump traffic on a network + buffered output + ip addresses only tcpdump proto\\udp dump all udp traffic on a network tcpdump -w write the raw packets to file (.pcap) chown root:nogroup set owner/group of file/directory chgrp set permissions for group chmod chmod 755 (read 4;write 2;execute 1) CTRL+Z suspends task CTRL+R reverse-i-search bg run task in background fg return task to foreground jobs list of running (suspended) tasks ps -aux show running processes kill -9 stops a process from running, either via a signal or forced termination. killall stops processes by names ! repeat last command & used to run the task in background (pine &) && used to run task in queue (configure && make && make install) nice -n 15 make job run a command with modified scheduling priority / print priority -20 >> 19 renice -n -5 [ -g | -p | -u ] ID ... alters the nice value of running processes. -20 >> 20 shutdown -h now = halt shuts down system shutdown -r now = reboot reboot system which locate a program file in the user's path. whereis locate the binary, source and manual page files for a command cat useful for displaying content of short files of a few lines cat a.txt b.txt > c.txt usage for concatenate files zcat zcat uncompresses list of files and writes the data on standard output less displays output one screen at a time, Search through output, Edit the command line. zless file perusal filter for crt viewing of compressed text tail -f output tha last part of files, (-f) append data as the file grows find / -name *.txt searches a folder hierarchy for filename(s) that meet a desired criteria find /data/nfsen/profiles-data -name "nfcapd*" -type f -mtime +35 -exec rm {} \; find /data/nfsen/profiles-data -name "nfcapd*" -type f -mtime +35 | xargs rm find /data/nfsen/profiles-data -name "nfcapd*" -mtime +35 -delete grep '\[-3 6 0\]' -A 3 < input > output search file(s) for lines that match a given pattern grep -i word * -R search pattern 'word' in all files in current dir and subdir + ignore case grep -v inverts the sense of matching, to select non-matching lines (invert-match) grep -h suppress the prefixing of filenames on output when searching multiple files grep -s suppress error messages about nonexistent or unreadable files grep -w select only those lines containing matches that form whole words fgrep search fixed strings cat /var/log/messages | grep -i "update\|run" cat /var/log/messages | grep -iE "update|run" cat /var/log/messages | egrep -i "update|run" find / |grep serches for files on / witch contain the string specified after grep wc print the number of newlines, words, and bytes in files uniq report or omit repeated lines tar -zxvf unpacks the file separate files in its own directory tar -zcvf packs up files into a tarball scp user@machine:/files /destination secure copy for files and folders strace trace system calls and signals mkreiserfs --format 3.6 /dev/hdx creates a linux ReiserFS file system reiserfsck check a linux ReiserFS file system resize_reiserfs ReiserFS filesystem resizer useradd abc -m -G users,wheel -s /bin/bash adds user abc + adds to groups + select bash as shell passwd abc changes the password for user abc chfn abc change the finger information of user chsh abc changing the login shell of user quota abc displays disk usage and limits edquota abc edit user quotas xf86config configure X on your system rdesktop -g 90% -a 16 remote desktop (geometry 90% , color depth 16 bpp) Tunneling ~~~~~~~~~ ssh -Nf -L local_port:localhost:destination_port user@ssh_server telnet localhost local_port --> telnet ssh_server destination_port Cron ~~~~ crontab -e user edit crontab file for user crontab -l user list crontab file for user AWK - SED examples ~~~~~~~~~~~~~~~~~~~ sed -r 's/,/ /g' - use extended regular expressions, replace comma with space globally awk -F'abcd' '{ print $1" "$2" "$31" "$23" "$24}' - delimiter string "abcd" and printout fields separated by spaces cat /etc/passwd | awk -F: '{ print $2 }' echo /etc/init.d/ | sed 's/\//_/g' > redirecting output >> appending output VIM keyboard shortcut ~~~~~~~~~~~~~~~~~~~~~ e open (edit) a file i activate insert mode v activate visual mode y yank selected text yy yank current line into buffer p paste text /after cursor P paste text /before cursor u undo change CTRL+R redo change o insert empty line /after cursor + activate insert mode O insert empty line /before cursor + activate insert mode r activate overwrite mode for one character R activate overwrite mode x delete character at cursor s delete character at cursor + activate insert mode D delete from cursor till end of line dd delete line dw delete word wq! save changes and exit q! exit with no changes h displays help :75 goto line 75 ^ beginning of the line $ end of the line g /re/ search patterns matching 're' g! /re/ search patterns notmatching 're' / search for string /\c search re - case_insensitive /\C search re - case_sensitive %s/ / /ic substitute string + ignore case + ask for confirmation %s/ / /ic | %s/ / /ic | wq usage of multiple commands %s/re/CTRL+v ENTER/ replace 're' with new line 1.2.3.[0-9]\{1,2\} match of IP address w/ 1 or 2 digits in last octet :set noautoindent [set noai] disables auto-formatting :set nu display line numbers :set list show special characters in the file vimtutor tutorial for new users Screen shortcuts ~~~~~~~~~~~~~~~~~ screen -r reattach session screen -D detach session CTRL+A+c create window CTRL+A+n switch to next window CTRL+A+p switch to previous window CTRL+A+space switch to next window CTRL+A+d detach screen CTRL+A+K kill window CTRL+A+ESC activate copy/scroll mode CTRL+A+" list of all windows CTRL+A+x lock screen GPG commands ~~~~~~~~~~~~ gpg --gen-key gpg --list-keys gpg --fingerprint gpg --import gpg --armor--output public.asc --export FFFFFFFF (-ao) gpg --encrypt--sign (-se) gpg --decrypt (-d) gpg -r FFFFFFFFF -sea >text.asc ctrl+D 2016 ~~~~ while (true) do date ; sleep 10; done ; exit /proc/mdstat mdadm - manage MD devices aka Linux Software RAID # mdadm --create /dev/md1 -n2 -l1 /dev/sda2 /dev/sdb2 pvscan - scan all disks for physical volumes vgscan - scan all disks for volume groups and rebuild caches lvscan - scan (all disks) for Logical Volumes rpm - RPM Package Manager yum - Yellowdog Updater Modified sync - flush file system buffers $? - the exit status of the most recently executed foreground pipeline export $EDITOR strace - trace system calls and signals lsof - list open files lsattr - list file attributes on a Linux second extended file system chattr - change file attributes on a Linux file system getfacl - get file access control lists setfacl - set file access control lists test - check file types and compare values openssl - OpenSSL command line tool ssldump - SSLv3/TLS network protocol analyzer systemctl - control the systemd system and service manager mtr/mtr-tiny - combines the functionality of the 'traceroute' and 'ping' programs in a single network diagnostic tool. qshape - print Postfix queue domain and age distribution >format LVM >boot outside of LVM >edit fstab >update-initramfs >update-grub DNS troubleshooting ~~~~~~~~~~~~~~~~~~~ dig google.com +trace dig soa +short google.com dig +trace +recurse +all +qr -t any google.com dig +trace +norecurse +all @8.8.8.8 google.com dig -x 8.8.8.8 +trace ~~~~~~~~~~~~~~~~~~~~~~~~ Michal Goceliak (C) 2017