GNU/Linux Tidbits

 

# show the DNS server being used
nmcli device show <interfacename>

Checking type of memory
sudo lshw -short -c memory

 

CLONEZILLA
Change # of clients
/etc/dhcp/dhcpd.conf
range 192.168.1.1 192.168.1.xxx

########
# Bash #
########

# rsync flags
-a (archive) – preserve permissions, mod times, etc.
-v verbose
-r recursive
-P Progress and partial
–delete # removes files from backup that have been deleted
-n dry-run

 

# Tunneling with SSH
ssh -X remote-sys boinc

ssh -D 1357 user@ipaddress -p xxxx # change proxy on browser

 

# Test if file exists
if [ ! -f /tmp/foo.txt ]; then
echo “File not found!”
fi

 

# Ping scan
nmap -sn xxx.xxx.xxx.xxx/24

 

# Display tcp connections
watch netstat -tn

 

# Listing Shared Files/Folders
ls -l /var/lib/samba/usershares/
cat /var/lib/samba/usershares/xchange | grep path

 

# Clear recently used files
echo > ~/.local/share/recently-used.xbel

 

# Cronjobs
[sudo] crontab -e
@reboot /full/path/to/script # executes script at boot up

# dmesg: Major events that have occurred on your machine since last boot
# iftop: Shows network traffic
also… iptraf or… nethogs
# iostat: disk i/o info
# iwconfig: currently operating wireless devices
# iwlist: wireless access points in range
# lpq: Lists the current printer queue.
# lsb_release -a: OS version
# lsmod: What OS modules are installed, i.e. device drivers and the like.
# lsof: Lists open files/ports (e.g. to find info about a specific port–> lsof -i :80)
also… netstat ($ netstat -lp -net)
# lsusb: Lists what USB devices are currently plugged in.
# netstat: Lists current network connections.
# route: routing table info
also $ ip route show

# Output the last part of a file
tail -f /var/log/syslog

# tar: List the contents of a tar.gz file (e.g. $ tar -ztvf file.tar.gz)

# Reading exfat
sudo apt-get install exfat-utils exfat-fuse

# Wiping a drive
dd if=/dev/zero of=/dev/sdaX bs=1M
dd if=/dev/urandom of=/dev/sdaX bs=1M

 

###############
# System Info #
###############
# Memory
sudo dmidecode –type memory

# BIOS
sudo dmidecode -t bios

# Processor
sudo dmidecode -t 4

 

##################
# Recovery Tools #
##################
# testdisk: This does a lot of diagnostics on your hard drive, recover lost partitions, undelete deleted files, fix boot sectors and so on.
# ntfsix: May be able to fix your broken NTFS partition.
# photorec: Quite a program! It bypasses your (possibly broken) file system, and looks for files by going through your hard drive literally bit by bit, looking for bytes that encode any of 180 known file types, e.g. .jpg, .avi, .pdf etc.

 

 

##################
# System Freezes #
##################

# Executing a keyboard restart #
Alt+PrintScreen then pressing r,e,i,s,u and then b in that order to reboot the computer, if you want to close it down press ‘o’

# Program Freezes #
If an application program freezes up and you invoked it from the command line within a shell, you can in most cases kill it by hitting Ctrl-c in the terminal window from which invoked it. If this doesn’t work, in another terminal window, run:

$ ps ax

note the process number of your program. Then type:

$ kill -9 # Type the process number here #

 

If you have a program named, say, xyz, the command
pkill -9 xyz
kills all running instances of the program.

 

# Screen Freezes #
Ctrl-Alt-F1

# In Gnome hit Alt F2, which will bring up a little window in which you can run a command, say pkill as above.
# In Gnome, hit Ctrl Alt T, which will create a new terminal window, from which you can kill the offending program.
# Try going to another screen! Linux allows you to switch among multiple screens. In Gnome, for instance, You can switch to the second screen from the first via Ctrl Alt Right, and go back via Ctl Alt Left. Then open a terminal window in the new screen, find the process number of the program and kill the program, as described above.
# In Gnome, try hitting Ctrl Alt Del. This should cause an exit from Linux’s X11 windowing system but not an exit from Linux itself. You would then get an opportunity to log in again.

 

######
# Vi #
######

u = undo last change

J = join lines
i = insert
a = append

V = select entire line
d = cut selected area
p = paste below / after cursor
P = paste above / before cursor
Y = copy line
xY = copy x lines
yw = copy to end of word
y$ = copy to end of line

dd = Delete current line
d$ or D = Delete from cursor to end of line

e = go to end of word

: = command mode
set number = number lines
w = write
q = quit

/string = search forward for string
:s/pattern/string = replace pattern with string

 

#########
# Xtras #
#########

# Screenshots
# Alt-PrntScr > Copy
# Ctrl-V > Paste

# To toggle insert mode in gedit –> ‘Insert’ key