Linux Notes

  • Delete whole lines in many files - If you have a load of files which contain a line you don't want, you can use a combination of find and sed to remove them. This came in useful when one of my servers had been compromised and a number of html files had had malicious content inserted. ...
  • Verify that a network connection is secure - You can verify that network data is encrypted by transferring a file containing a known string and sniffing the network to see if it can be found. Wireshark Formerly Ethereal, Wireshark can sniff all traffic that's transferred via a particular networ...
  • Xfce - Notes about Xfce Desktop Environment 4. Default applications There are two places that you can set default applications. Settings -> Preferred Applications To blank out e.g. the Web Browser dropdown, edit ~/.config/xfce4/helpers.rc a...
  • Determine and change file character encoding - Determine what character encoding is used by a file file -bi [filename] Example output: steph@localhost ~ $ file -bi test.txt text/plain; charset=us-ascii Use vim to change a file's encoding If you use the vim text editor, you can configure it ...
  • Text manipulation - cut, awk and sed - Tokenize strings using cut If you know the exact delimiter (e.g. a tab) you can use cut. The format is as follows: cut -d[delimiter] -f[field_number] [filename] Where [delimiter] is the delimiter, [field_number] is the number of the field we want ...
  • Acroread notes - Notes about acroread. Toggle menu bar To toggle the menu bar (File Edit View etc), press F9. References How do I restore the PDF menu bar (File-Edit-View)?
  • Transfer files between computers without ftp - If you have the scp program, you can use the following line of code to transfer a local file to a remote computer called the.computer.name: scp /the/local/file/name username@the.computer.name:/the/remote/file/name If you don't have scp you...
  • How to archive and encrypt a directory with a password - To tar and compress a directory, then encrypt it with the AES algorithm: tar -czf - [directory] | gpg -c --cipher-algo AES -o [directory].tgz.gpg You will be prompted to input a password. To decrypt, decompress and untar: gpg -d [directory].tgz....
  • vmware-server-console hanging - If you have started vmware then try to log in via vmware-server-console and it hangs, check /var/log/messages for xinetd messages. For example: Mar 25 22:26:34 slap xinetd[24938]: FAIL: vmware-authd address from=127.0.0.1 Mar 25 22:26:34 slap xinetd[...
  • Bash script to check SSH connection - You can use the following bash script to check whether an SSH connection is working. I run it via a cron job so that I receive an email alert when there’s a problem with a server. #!/bin/bash ssh -q -o BatchMode=yes -o ConnectTimeout=10 example.com e...
  • Pass flags to the kernel from Grub GUI - When you get to the graphical Grub OS selection screen, press escape. This will drop you to a command line where you can boot linux with any desired kernel flags. E.g. linux 3 to boot into runlevel 3.
  • Apache - FCGID notes - You need mod_fcgid and suexec enabled. <VirtualHost *:80> ServerName drupal DocumentRoot /home/steph/webapps/drupal/ <Directory "/home/steph/webapps/drupal/"> Order allow,deny Allow from all AllowOverride Al...
  • Do not use hard links for incremental backups - I’ve read in many places that a good simple incremental backup approach is to use rsync to sync your files to a backup destination and then hard link the backup to a copy via cp -al so that you have historical snapshots. It works as follows: rm -rf m...
  • Sudo notes - Note on sudo. Last matching rule is used When you issue a command via sudo, it will run through /etc/sudoers for all rules that match and then apply the last one that matches. For example, I wanted steph to be able to shut down the computer without ...
  • Emacs and Slime usage notes - Notes and keyboard shortcuts/commands for Emacs with Slime. C is control. C-x C-x means hold down control and press x twice. M is meta (alt). E is escape. Documentation Key binding Action C-h View lis...
  • Subversion (svn) - Getting current revision using svnversion – How to query the current revision of a directory using svnversion. How to move a repository into a different repository – How to merge a repository into a different repository using svnadmin dump ...
  • Remapping keys of Microsoft Natural keyboard - Use xev to get keycode and name (note that these key codes differ from when using showkey -k when not in X). Forward key… KeyPress event, serial 27, synthetic NO, window 0x3a00001, root 0x3e, subw 0x0, time 3026042600, (107,-95), root:(365,188), ...
  • Query DNS - You can use nslookup to query a doman name server (DNS). Determine which name server is used by a domain Query the [domain] name server (NS) record to find out which name servers it uses: nslookup -type=ns [domain] E.g: Query the NS record for ex...
  • My xfce4 setup - So xfce4 resets things occasionally after update. I do have a backup of the config folder (at ~/.config/xfce4) but sometimes I prefer to recreate everything from scratch so that old settings aren’t hanging around. Reset to default Delete ~/.config...
  • Open all files containing a pattern - To search the current directory for all files called [filename] (a regexp) that contain the given [pattern] (a regexp) and open them in [program]: find . -name "[filename]" -exec grep "[pattern]" -ls {} \; | xargs [program] For example, this will o...
  • Rsync - Notes about rsync. Basic usage To backup /the/source directory in to /the/destination/… rsync -avP --delete --exclude='a/dir/to/exclude' /the/source /the/destination/ The a option causes rsync to use ‘archive’ mode, which preserves . v increases ...
  • Convert a PDF to images - Use can use the convert command to convert a PDF into images. It uses ImageMagick behind the scenes. The following will convert foo.pdf PDF into foo-[n].jpg images, where [n] is an image number from 0: convert foo.pdf foo.jpg Note that it will cre...
  • See which processor governor is being used - If you are running the cpufreq to manage your CPU, there are a number of governors that control how it's used. E.g. "performance" will thrash the processor, "conservative" won't and "ondemand" will scale the frequency as a...
  • How to determine Linux kernel details - The uname command will print system details. By default it shows the kernel name: bpc steph # uname Linux The -a flag will show everything: bpc steph # uname -a Linux bpc 3.2.12-gentoo #11 SMP Sun Feb 3 22:19:46 GMT 2013 x86_64 Intel(R) Core(TM)2 ...
  • SBCL ADSF 2 error - Update: I’ve a better solution / more detail about this here: Slime with SBCL and ASDF 2 on Gentoo. Today I started slime and received an error about ASDF 2: ; loading #P"/usr/share/emacs/site-lisp/slime/swank-loader.lisp" debugger invoked on a SIMP...
  • Using netstat to monitor your internet connections - The following command will show a list of your TCP and UDP internet connections, along with the PIDs of the programs that are using them: netstat -tup As with most commands, you can keep an eye on it by running it through the watch command: watch...
  • How to duplicate a DVD - To duplicate a DVD - copy it to a blank DVD - you can use dd to dump its data as an ISO file then record it to a new DVD using growisofs. dd if=/dev/dvd of=thedvd.iso growisofs -dvd-compat -Z /dev/dvd=thedvd.iso
  • Change owner of vmware virtual machine - Here I document what I did to get some VMs appearing in a user's vmware-server-console list when they previously were only available to a different user. Note: Read this first: Understanding Permissions and Virtual Machines. Note that I'm not sure ...
  • How to join video files in linux - So far, I have tried this command successfully with wmv and mpg files. To join several video files [part1], [part2], etc into a file called [whole], run the following command: mencoder -oac copy -ovc copy -o [whole] [part1] [part2] ... [partn] If...
  • Run MySQL commands from the Bash command line - MySQL 5. You can run MySQL commands by logging into the MySQL shell or by redirecting a file into mysql with mysql -u[user] -p[pass] [database] . You can also execute MySQL commands directly from the Bash command line using the -e flag: mysql -u[...
  • How to get the details of available wireless networks - To scan your eth1 network interface for the details of available wireless networks, run the following... iwlist eth1 scan Should give you an output something like this: eth1 Scan completed : Cell 01 - Address: 00:14:7F:40:20:4A ...
  • Compiz notes - Group and tab multiple windows hold super and s to select every window that you want grouped. press super +s on each window. This selects the windows. Then press super + g to group them all into one. Now you can minimize and unminimize them together...
  • ACPI - ACPI establishes industry-standard interfaces for OS-directed configuration and power management on laptops, desktops, and servers. Here is the home page: ACPI - Advanced Configuration & Power Interface. acpid won't start but logs nothing Proble...
  • wget notes - Index Mirror site for local viewing Mirror site with external dependencies wget for cron job / routine tasks References Mirror site for local viewing You can use wget to spider / crawl a site and take a mirror of it for local viewing: wget...
  • vim and gvim - vim is a text editor, common on many *nix platforms. gvim is its GUI. All of the notes have been tested with gvim, but should also be applicable to vim. Here’s a good intro to the basics of navigation and editing: Efficient Editing With Vim. Index ...
  • List top 10 largest files and directories - The following command chain will output a list of the top 10 largest files and directories in the current directory. Change the dot to a directory location to search in some other directory. du -a . | sort -n -r | head -n 10 You'll get a list somet...
  • Resizing images with convert - Downsize JPGs by 50% convert -resize 50% *.jpg convert has loads of other options, for e.g changing dimensions or quality. NOTE 1: It has a problem with patch resizing, whereby it freezes the computer. I’ve found batches of 100 is too much. Batche...
  • Split and join files - Some filesystems can't handle particularly large files. e.g. ISO 9660, used to store data on DVDs, has a 4Gb or 2Gb limit, depending on implementation. To split a large file into smaller files: split -b 1G -d [filename] [filename]. This will split th...
  • Configure postfix for local delivery only - To configure postfix so that it sends emails to the local machine but rejects those sent to external domains, add the following to /etc/postfix/main.cf: inet_interfaces = loopback-only mynetworks_style = host default_transport = error: Local delivery ...
  • xsane notes - Notes about xsane, the scanner tool. HP no devices available If you have an HP printer/scanner (on wifi in my case) and xsane fails to find the scanner, then you may need to to reconfigure the printer driver via hp-setup. See my HP Officejet j6410 p...
  • Reboot frozen system - reisub - “Raising Elephants Is So Utterly Boring” Hold down alt-sysrq (aka print screen) and enter reisub to reboot frozen system (switch keyboard from raw mode to xlate mode, send sigterm to all processes except init, send sigkill to all processes ex...
  • Check directory is mounted - To check that a directory is mounted in a bash script: echo "Mounting /mnt/share..." sudo mount /mnt/share if ! mount | grep '/mnt/share ' > /dev/null; then echo "/mnt/share not mounted. Exiting." exit fi # Do stuff with /mnt/share echo "Unm...
  • Quit Chrome with ctrl-q - Chrome on Linux (Gentoo) doesn’t quit on ctrl-q, you have to use ctrl-shift-w instead (the idea being that ctrl-w closes a single tab and ctrl-shift-w closes all of them). I think ctrl-q is not used by Chrome to prevent people hitting it accidentally w...
  • See where a program is crashing - Run gdb to start a command line debugger. At the prompt type run program, where program is the name of the program that is crashing. After the program has crashed, type backtrace to trace where the program crashed. See GDB: The GNU Project...
  • Multiple ISPs for PPP - I use WvDial to connect to the internet (their homepage is at open.nit.ca/wvdial/). Install it and follow their instructions to configure your internet connection(s). This will generate a file called /etc/wvdial.conf that contains the telephone ...
  • Postfix notes - Notes about Postfix mail server. Determine postfix version postconf -d | grep 'mail_version =' Postfix autoresponder / autoreply Use the ‘vacation’ program. On debian: apt-get install vacation As the user who will have the autoresponder: ...
  • Testing for a non-interactive shell - I had some backup scripts that used ssh and scp but reported the following warning to stderr: stdin: is not a tty If you receive this error then it’s likely that your .bashrc file (or another terminal init file, on the server side) is trying to do ...
  • Newline conversion from DOS/Windows to Unix/Linux - To convert DOS/Windows newlines (CRLF) to Unix/Linux newlines (LF): sed 's/^M$//' Important: To generate the ^M type ctrl-v-m, not the ^ character followed by M.
  • Mount a Windows shared folder using Samba - To list shares on [server] visible to [username] use the following. You will be prompted for a password. smbclient -L \\[server] -U [username] To mount the //server/dir share on /mnt/dir, giving [username] and [password] as authentication: smbmou...
  • Redirect stdout and stderr to a file - From Redirect stdout & stderr and append to a file. It is possible to redirect one output channel to another like “2>&1” which means “put the output of channel 2 (stderr) where right now channel 1 (stdout) goes” and let channel 1 point to a...
  • Cron notes - Notes about cron, specifically Vixie cron, which is the version I use. How to create cron jobs Create a file called crontab.txt (or whatever you want). Add your cron jobs to it. Run crontab crontab.txt to create the jobs. Run crontab -l to c...
  • Cannot find install-sh or install.sh - configure: error: cannot find install-sh or install.sh in ./ First check that you've got the correct version of autoconf installed. Look at the configure.ac script for AC_PREREQ and check that it refers to a version number equal to or less...
  • Panoramas in Linux - There are a number of linux programs available that contribute in some way to the creation of panoramas. However, there is currently no complete program that offers all features rolled into one. I use a combination of autopano-sift (actually, the GUI...
  • Postfix with Dovecot setup - Notes about setting up a Postfix MTA with Dovecot email server. Versions used were Postfix 2.5.5 and Dovecot 1.0.15. Index Desired setup System users Virtual domains Aliased domains Complete configuration files Testing with telnet Refe...
  • Use Samba v2 with Windows 2003 server - Ok, so it seems that version 3 of samba is needed to view Windows 2003 Server active directories. This is because of changes Micro$oft has made to the security policies of the active directory protocol. Since I couldn't be arsed to install v3 of samb...
  • How to su as another user without requiring a password - You can use sudo with su to login as another user without requiring a password. Add the following to /etc/sudoers: from_user ALL=NOPASSWD: /bin/su - to_user This allows from_user to login as to_user by issuing this command: sudo su - to_user Be...
  • xargs - The xargs command is commonly used with find to perform a command on each of files that match the search criteria, by piping the results of the find command into xargs. find ./ -type f -print xargs -i mv -f {} ./newdir T...
  • Device is busy - This is an article I found at http://www.idevelopment.info/data/Unix/General_UNIX/GENERAL_Troubleshootingthedeviceisbusy.shtml documenting how to user the fuser command. --- begin article --- by Jeff Hunter, Sr. Database Administr...
  • Remove old files by date in filename - I have backup scripts that create files with the backup date in their filename, in ISO 8601 format, as generated by date -I, as follows: mirrors.tgz-2015-12-31 This is year-month-day: mirrors.tgz-Y-m-d Every month I want to delete all old backu...
  • Find target given a symlink - To find the target of a symbolic link i.e. the real file or directory that your symlink points to… realpath [symlink] Or: readlink -f [symlink] This can be useful in shared hosting environments where your home or html directory is a link but so...
  • Scan open ports - You can use the nmap command to find out which ports are listening for TCP connections from the network. nmap -sT -O localhost In this example, the -sT flag will scan for TCP ports and the -O flag will try to determine the operating system. Replace...
  • Mozplugger notes - Mozplugger allows you to open attachments like PDFs from within Firefox. It does this by using the applications you’d normally use to read the files, such as Zathura for PDFs, but embedded inside a container that’s opened in the browser. Configuration...
  • ttyS* to COM* mapping - Linux refers to the COMmunication ports using the following devices... Linux DeviceDOS COM port /dev/ttyS0COM1 (Oftern used for the mouse) /dev/ttyS1COM2 (Typically used for external modems) ...
  • CMYK using the Separate+ plugin with Gimp - Gimp 2.4 doesn't have CMYK support (it'll come later, when the GEGL has matured). However, the Separate+ gimp plugin can create colour separations from an RGB image and save as an CMYK TIFF file. Get it from the Gimp plugin registry, here: Separate+. ...
  • Find files by date - All examples on this page search from the current directory, as specified by the dot after the find command. To locate files that have been modified after [date]: touch -d [date] date_marker find . -newer date_marker Where [date] can be "13 may 2...
  • Misc Linux notes - Find help Show all man pages containing the keyword: apropos keyword List files in a zip archive unzip -l the.zip Copy with parents To copy loc, creating /the/file directories beneath it at the destination: cp --parents /the/file/loc /to/whe...
  • latex2rtf - To convert a lyx file to rtf format, do the following. When converted, you can of course open it in programs like Micro$oft Word or Sun's OpenOffice. Export as latex, so you have a document called [filename].tex. Create a .aux file with latex [filena...
  • Mount a remote directory - First, you'll need the NFS server daemons running on the machines. If you're running Redhat you can start them with /etc/rc.d/init.d/nfs start. Next, add the following to the /etc/exports file on the remote machine: /dir/to/mount your.linux.bo...
  • Git-GUI notes - Notes about git-gui, the git GUI. Gotchas Failure traversing parents If you get the following error when cloning a repository using Git Gui… error: Could not read afbf…etc error: Could not read 68a3…etc fatal: Failed to traverse parents of commi...
  • Generate patch file in unified format - This will create a patch file specifying the difference between file and file.new in unified format: diff -u file file.new > patch
  • Log in to MySQL without password prompt - To allow you to log in to MySQL without having to type a password at the prompt, add your password to a file called .my.cnf in your home directory. [client] user=the_user password=the_pass Important: Make sure the file is readable only to you, by cha...
  • Find duplicate lines in a sorted file - After sorting a file you will often find that some duplicate data, or you may be given various lists that need deduping. sort and uniq will quickly and easily remove duplicates, lsit only the dupilcates or only the unique data. sort myfile.txt | uniq ...
  • Useful Linux commands - Unclassified Information User administration Unclassified Monitor processor speed: watch x86info -mhz Determine which filesystems are mounted: cat /etc/mtab Information Find location of command whereis [command] User administration ...
  • Generate a list of a site's URLs using wget - You can use wget to generate a list of the URLs on a website. Spider example.com, writing URLs to urls.txt, filtering out common media files (css, js, etc..): wget --spider -r http://www.example.com 2>&1 | grep '^--' | awk '{ print $3 }' | gre...
  • Creating encrypted archives - To create an encrypted archive of thedirectory, using des3 encryption, to produce a file called thearchive.tgz.des3 which is protected by thepassword: tar -cz thedirectory | openssl des3 -salt -out thearchive.tgz.des3 -pass pass:thepassword To decry...
  • Escape spaces with sed - When dealing with file paths, you may need to escape spaces. You can do this using sed. #!/bin/sh p = "/var/lib/vmware/Virtual Machines" echo $p q = $(echo $p | sed 's/ /\\ /g') echo $q Output: /var/lib/vmware/Virtual Machines /var/lib/vmware/Vi...
  • git notes - Notes about Git, the distributed version control system. Index Useful links for those coming from Subversion How tos Delete a tag Remove a file from the last commit Remove added file / remove file from index Find com...
  • Expand a VMware Server virtual disk. - You can use the vmware-vdiskmanager tool to expand a VMware Server virtual disk and increase its capacity, like so: vmware-vdiskmanager -x [size] [vmdk_filename] Where [size] is the size you want the disk to be, in sectors, Kb, Mb or Gb, and [vmdk_fi...
  • Ubuntu SSH key management - Ubuntu uses the gnome-keyring-daemon to manage ssh keys / passwords, with the seahorse front end (which in typical Ubuntu fashion it unhelpfully refers to as ‘Passwords and Keys’). Reference: How can I permanently save a password-protected SSH key? D...
  • Fixing evdev 'module ABI major version' error - On occasion I’ve updated X11 on Gentoo and evdev has failed to load, with the following error in /var/log/Xorg.0.log: module ABI major version (12) doesn't match the server's version (13) This prevents my keyboard (and presumably the mouse) working...
  • Run a command on each line in a file - You can cat a file and pipe it to a while loop in order to perform a command in each line in the file. cat [filename] | while read line; do [command] "$line"; done For example, if you have a text file, called filenames.txt, that contains line-separat...
  • Ubuntu and Lubuntu notes - Notes about Ubuntu and Lubuntu (a lightweight Ubuntu). Ubuntu is based on Debian so you may find my Debian notes useful. Determine Ubuntu version lsb_release -a Reference: Checking your Ubuntu Version Purge an application sudo apt-get purge [pa...
  • Convert text file to pdf - To convert a text file into a PDF you can use enscript to convert it into a PostScript and pipe that through ps2pdf. To get a txt2pdf command, add the following to your bash functions (in e.g. ~/.bash_function): txt2pdf() { read -p "This will overw...
  • How to scp with spaces in the filename - If you have spaces in your file name then you must use both quotes and escape the spaces: scp example.com:~/some/file/'with\ spaces' . scp example.com:~/some/file/"with\ spaces" . Or use a combo of single and double quotes: scp 'example.com:~/s...
  • Find files containing a pattern - You can find files with grep or find with grep. Using grep grep -riHn [pattern] . This will recursively find all files under the current directory (and it’s subdirectories) that contain the given pattern. The flags are as follows: r recursive...
  • Bash - Notes about Bash. Run command on each line in a file Run the [command] on each line in a [file]: while read l; do [command] $l & done < [file] This will run [command] [line n] & for every line in [file], where [line n] is the next line...
  • Set sound volume at boot - If the driver for your sound card is installed as a module then you can use aumix to set the volume shortly after the module is loaded. In /etc/modules.conf add & aumix -v50 at the end of the line where the driver is loaded to set the volume to 50%.
  • md5 digests via md5sum - MD5 is a message digest algorithm that can hash a string or file. The md5sum is used on Linux systems to create MD5 digests. Strings (terminal command line) To create the md5 of a string via the command line: echo -n "Digest this" | md5sum The -n...
  • How to login as another using without a password - You have two choices about how to log in as another user at the command prompt, without being prompted for a password. Use sux You could use sux. Add the following to /etc/sudoers: user1 ALL=NOPASSWD: /usr/bin/sux - user2 user1 will now be able t...
  • Linux print commands - Determine printer status lpstat -p -d E.g: me@pc ~ $ lpstat -p -d printer Officejet_J6400 is idle. enabled since Fri 31 Aug 2012 10:22:16 BST system default destination: Officejet_J6400 Set default printer lpadmin -d <printer> Where ...
  • Find and replace - Notes on how to use the find command to find and replace text. Index Delete everything up to the first occurence of a regexp Keep everything between <START> and <END> Find and replace over multiple lines with sed Find and replace ...
  • UK date format in Sunbird - The Mozilla Sunbird calendar does not give you the option of changing the date format, from e.g. US mm/dd/yyyy to UK dd/mm/yyyy. However, the program does pick up the system locale and should set the date format accordingly. So, if you're seeing the US...
  • Android MTP - To mount an Android 4 phone (I have a Galaxy S2 with Android 4.1.2), you must use the MTP protocol. You can no longer mount it using the USB mass storage protocol, because this won't work on devices that have only a single partition (because you can't ...
  • Changing window manager from Compiz to Xfce XFWM - Compiz will no longer be maintained in gentoo portage, so I’ve had to move to XFWM, the window manager from Xfce. In a way this is a natural progression for me because I’ve been using the rest of Xfce for some time. However, XFWM doesn’t do many things...
  • Bluetooth on linux - I configured my Gentoo system as per the Gentoo Linux Bluetooth Guide, which required recompiling the kernel with bluetooth support and installing the bluez-libs and bluez-utils packages. Usage notes Query (HCI) device: hciconfig -a Bring the device...
  • Get window name using xprop - In X, if you run the xprop command and click on a window, it will print verbose details about the selected window. You can pipe this through a text processing program like awk to pick out particular details, such as the window name. xprop |awk '/WM_C...
  • How to encrypt a file with a password - Encrypt. This will add an encrypted file called [filename].gpg. gpg --cipher-algo AES -c [filename] Decrypt. This will create the decrypted file called [filename]. gpg -o [filename] -d [filename].gpg
  • How to scan the ports of a computer and network - Scanning a computer The netcat command (or simply nc) can be used to scan the ports of a computer. This example scans localhost for open ports in the range 1-1023: bpc steph # nc -zv localhost 1-1023 localhost [127.0.0.1] 631 (ipp) open localhost [1...
  • Disable MySQL binary logging - MySQL can keep a so-called binary log of transactions, which keeps track of all updates to the database. It is used for database restoration and replication. The logs can grow very quickly in size. At the time of writing, my logs take up around 68G. ...
  • Zathura notes - Zathura is a document viewer. It reminds me a bit of vim to use. Commands To enter a command in Zathura you type a colon followed by the command. E.g. To print, type the following: :print This will open your standard (GTK+) print dialog where you...
  • Join text files with filenames - You can use cat to join the contents of files. For example, this will create a file called tmpfile that contains the contents of all .txt files in the current directory: cat *.txt > tmpfile Use >> to append to tmpfile rather than overwriting...
  • sftp with custom port - With the sftp program, you can specify the port using the -o option: sftp -oPort=[port] [user]@[server]
  • Bash aliases - A Bash alias allows you to simplify long commands, so that you only have to type a few characters rather than a lengthy command and its options. Computer wide aliases go in /etc/bash/bashrc and user wide alises go in ~/.bashrc. alias alias_name='co...
  • How to scan your network for computers - You can use arp-scan to scan the IPs of all computers connected to your local network: me@pc ~ $ sudo arp-scan -l Password: Interface: enp2s0, datalink type: EN10MB (Ethernet) Starting arp-scan 1.9 with 256 hosts (http://www.nta-monitor.com/tools/arp...
  • Allow a normal user to shutdown - One method of allowing a normal user to shutdown is as follows: Grant the wheel group permission to shutdown via sudo by adding this line to /etc/sudoers: ~~~ %wheel ALL= NOPASSWD: /sbin/shutdown now -h ~~~ Add the user to the ‘wheel’ group. Th...
  • Inkscape notes - Notes about Inkscape, a vector graphics program. Selection Use the selection tool to select objects. This is the plain black arrow, top left. It’ll say “Select and transform objects” when you hover over it. To select objects, drag around them. Noth...
  • Keyboard shortcuts - This is a list of keyboard shortcuts for a number of popular linux programs. It is by no means comprehensive - I've created it simply so that I don't have to trawl the web to find one that I've forgotten. The list will start off small and grow as I for...
  • How to format a DVD with UDF - This document assumes you already have UDF support, either built into the kernel or as a module. To format a DVD at /dev/dvd with the UDF filesystem, use the mkudffs command: mkudffs /dev/dvd If that fails with a 'trying to change type of multipl...
  • Converting m4a files to mp3 using faad and lame - This script will convert all m4a files in a directory to mp3 format. For each mp4 file, the faad program converts it into wav format, then lame converts it to mp3 (a temporary wav file will be created, with the same name as the mp4 but with an added .w...
  • Run command as another user - If the user has a shell: su [user] -c "[command]" If they don’t have a shell: su -s /bin/sh [user] -c "[command]"
  • Symbolic links, aka symlinks - Symbolic links, aka symlinks, reference other files/directories, essentially acting as short cuts to the file/directory they reference (note that there are two kinds - hard and soft, aka symbolic links, aka symlinks). I won't go into details because th...
  • How to detatch a program from the terminal - Sometimes, when you start a program from the terminal, closing the terminal will also close the program. Even if you start the program in the background. vlc does this. E.g. Start vlc with vlc &, close the terminal and vlc will also close. To prev...
  • rpm commands - In all of the following examples, the vh options are simply so you get a nice verbose, human readable (i.e. progress bar) output when rpm runs. Search for an available package: Search for an installed package: rpm -q [package] In the above exampl...
  • CUPS - Common UNIX Printing System - commands - Install CUPS and you get the print server cupsd and the print commands lpstat, lpr and lpq, amongst others. I installed CUPS on two Gentoo boxes, following the Gentoo Printing Guide. On one of these machines I run the cupsd server. To specify the pri...
  • Find notes - Notes on the Linux find command. Index Find multiple file names Find ignoring a file Find ignoring a file and a directory Find files with particular permissions Find files not owned by a particular user or group Change extension of multip...
  • Nice terminal prompt - To change the terminal prompt to show current user, machine and current location (and a flashy green dot instead of normal hash symbol), put in .bashrc: export PS1="\u@\h:\W`if [ $? = 0 ]; then echo -e '\[\e[01;32m\] #'; else echo -e '\[\e[01;31...
  • Kill a process from PID file - Some applications create a PID file - a file that stores the process identifier of the application. The Mongrel server (and I think WEBrick too) creates a PID file in an application’s root directory at e.g. [app]/tmp/pids/mongrel.pid. You can use the ...
  • httrack - Notes about httrack website copier. httrack [web page] [filters] [filters] are specified with +[yes] -[no], where [yes] and [no] are strings to match, wildcards supported. Exclude everything from mirror but some httrack "http://www.the.pages/to/m...
  • Configure DMA - DMA can be turned off for all disks by sending ide=nodma to the kernel using LILO (add it to the append line in /etc/lilo.conf). You can then turn on (and optimise) DMA for any disks that support it using hdparm. I added action "Running hdparm...
  • Setting up Bordeaux Threads in SBCL - To set up Bordeaux Threads in SBCL (on Gentoo Linux with slime)… Download Bordeaux Threads from their releases page. Clone Alexandria, because it’s a dependency and BT won’t install without it. I couldn’t find a download link so I cloned (via git...
  • Problem pinging localhost - Problem I couldn't ping my external IP, 127.0.0.1 or localhost - pinging my external IP 192.168.0.50 returned an error message and pinging localhost just hung until ctrl-c. # ping 192.168.0.50 connect: Invalid argument # ping localhost PING local...
  • du notes - du is the linux command to show disk usage. To show usage of all files in a [directory], in human-readable (-h) format: du -h [directory] To show a summary (-s) of a [directory]: du -hs [directory] Drop the -h flag if you want usage in Kilobyt...
  • Add syntax highlighting to nedit - You can download syntax highlighting patterns for nedit from http://www.nedit.org/ftp/contrib/highlighting/. Download a pattern file, close all instances of nedit, and start it again with the import option, as follows: nedit -import <name of pat...
  • How to use a regex in a bash conditional - Use the double bracket syntax to use regular expressions (aka regex or regexp) in bash conditionals: me@pc ~/tmp/bashregextest $ if [[ "foo/bar" =~ ^foo ]]; then echo 'yes'; else echo 'no'; fi yes me@pc ~/tmp/bashregextest $ if [[ "foo/bar" =~ ^bar ]]...
  • Resizing a reiserfs loopback device encrypted with dm-crypt. - My home directories are encrypted via dm-crypt / cryptsetup using a loopback device and formatted with the reiserfs filesystem. See Disk cryptography with dm-crypt and SECURITY dmcrypt - Gentoo Linux Wiki. For the user 'bn', the image is a 5G file call...
  • Cacti notes - Cacti is a monitoring application. After installation it’ll be available at http://localhost/cacti/ When you’ve configured the graphs via the web interface, you’ll need to have cron run its poller.php script in order to have it monitor. I found it be...
  • Hydra notes - Notes about Hydra, a network login cracker. This can be used to bruteforce login to a service (that you run!) for which you’ve forgotten the password. hydra [server] [protocol] -l [username] -P [passwords file] -s [port] -S -v -V [server] The ...
  • Work with filenames listed in a file - If you have a text file with a number of line-seperated filenames, you can do the following to manipulate them: cat thefile.txt | while read line; do ls "$line"; done That example will simply run ls on each filename in the text file.
  • Determine Linux memory usage - You can get an idea of an application’s memory use via top: me@somewhere:~$ top Tasks: 159 total, 1 running, 158 sleeping, 0 stopped, 0 zombie %Cpu(s): 2.0 us, 0.0 sy, 0.0 ni, 89.7 id, 8.3 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem: 3612.672 tot...
  • Extract filenames from file - grep for word in file | remove spaces | remove unwanted text | do op on file grep whatever whatever.log | sed 's/ /\\ /g' | sed 's/whatever//g' | xargs ls -l Example: List infected files clamscan -r -lclamscan.log / recursively scans all files and...
  • Bashrc for root - On Gentoo (and perhaps other distributions), root doesn’t have the normal bash startup configuration files. If you want to use a ~/.bashrc file to load e.g. ~/.bash_aliases and ~/.bash_functions, then you’ll need a ~/.bash_profile file to kick everythi...
  • How to get around the umount device is busy error. - Sometimes you will try to unmount a disc and get a 'device is busy' error: # umount /mnt/dvdrw umount: /mnt/dvdrw: device is busy I am using /mnt/dvdrw in this example, but the same goes for any disc, like /mnt/cdrom, /dev/hdc, etc. fuser You ca...
  • Setup Grub boot loader - First start grub with the command grub. At the grub command prompt tell it the location of the files needed by grub: root (hd2,0) Where, in this case, the files are on hard disk hd2, partition 0. You can optionally check that the files are there wi...
  • hplip hp-setup - When running hp-setup (on gentoo), you may need to select “Advanced” and choose SLP as the communication method, otherwise device communication will fail. See HP Officejet J6410 printer notes for an example of setup steps for that printer.
  • How to determine your gateway / router IP - You can use the route command to determine your gateway (router) IP: me@pc ~ $ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.1.254 0.0.0.0 UG 2 ...
  • Audio recording and playback of ISO - ISO - Raw data. Creation: dd if=/dev/cdrom of=cd.iso (or cat /dev/cdrom > cd.iso) dd if=/dev/dvd of=dvd.iso Playback via mount: mount -t iso9660 -o loop,user cd.iso /mnt/cdiso mount -t iso9660 -o loop,user dvd.iso /mnt/dvdiso Play as if mou...
  • Gentoo - How to remove KDE from gentoo - list all packages in kde-base: for p in /var/db/pkg/kde-base/*; do echo $p|sed -e 's#.*/#=#'; done Uninstall / remove: for p in /var/db/pkg/kde-base/*; do echo $p|sed -e 's#.*/#=#'|xargs emerge -C; doneIntel HDA on ...
  • cURL - Silently accessing a file protected by basic auth E.g. Drupal cron.php. curl --anyauth --user [user]:[pass] --silent --compressed http://the.web.site/cron.php Caching Don’t understand this yet!.. cURL seems to cache the response somehow, so even...
  • SSH with X11 forwarding after su - You can SSH to a server with X11 forwarding to allow you to run X11 (graphical) applications on the server and have them show up on your local machine. ssh -X [the user]@[the server] However, if you then run su to log in as a different user, you'll...
  • diff notes - To compare the contents of all files in directories [dir1] and [dir2]: diff -r [dir1] [dir2] To list the files that differ, without showing differences: diff -qr [dir1] [dir2] Generate a diff in unified format: diff -u [old] [new] > [diff]
  • Change date of image EXIF data - Increment by 2 years: exiftool "-allDates+=2:0:0 0:0:0" [files] Decrement by 6 hours: exiftool "-allDates-=0:0:0 6:0:0" [files] [files] can be any list of filenames, with normal shell expansions (e.g. wildcards) allowed.
  • SuSE - Index System files Disable SuSE Firewall Set services to start at boot System files | Go to top Location Description /etc/init.d/ Holds service initialisation scripts. This is known as the SystemV style - the script...
  • How to get your IP from the command line - http://icanhazip.com/ will tell you your IP. curl http://icanhazip.com/ I previously did this using whatsmyip.org, but it doesn’t work any more. whatsmyip.org tells you your IP address clearly at the top of their web page. You can also use this to...
  • X11 notes - Keyboard layout A list of the valid keyboard layout codes can be found in /usr/share/X11/xkb/rules/base.lst. E.g, for the UK, use code gb in e.g. /usr/share/X11/xorg.conf.d/10-evdev.conf (for gentoo): Section "InputClass" Indentifier "evdev keyboa...
  • Get total memory usage of a program - You can use ps to list details of the processes running on your system and awk to filter for a particular program and total the values. In this case we’ll total the RSS, which is awk’s 6th token hence the $6 in the command. If you wanted to total the ...
  • Network services - There are a number of services associated with the network (often held in the /etc/rc.d/init.d or /etc/init.d/ directory). These can be started, stopped or restarted using the service command, like so: service service_name start|stop|restart. ...
  • ALSA - Notes about ALSA. Mixer To show mixer with controls for all devices: alsamixer -V all Set default microphone I have ALSA with Pulseaudio, but after much searching on the Internet I couldn’t determine where to set the default input source. Instea...
  • How to extract archives using Rox Filer - You can set a ROX Filer run action to extract archives in the current directory. You reference the current directory with the following: $(dirname "$1") The quotes around $1 are needed to handle names that contain spaces. Zip files xterm -exec un...
  • Mutt notes - Notes about Mutt. To delete all emails: shift-d ~s .* q confirm
  • Turn on DPMS - In Mandrake 9 (and probably most other distributions) xset +dpms turns on the monitor's DPMS energy saving feature (likewise, -dpms disables it). This command can be put in /etc/rc.d/rc.sysinit or /etc/rc.d/rc.local, depending on when you want i...
  • Tar - List contents of gzipped tar archive tar -tzf archive.tgz Tar and encrypt from list tar -cz -T files.lst | gpg --cipher-algo AES -c -o files.tgz.gpg Where files.lst is a list of files, gathered by e.g (all systems.txt or details.txt files under...
  • Bash keyboard shortcuts - Some keyboard shortcuts and commands for the Bash. Key sequence Action ctrl-c Kill current process ctrl-z Send current process to background fg return Restore...
  • ClamAV clamscan notes - Scan for viruses To run a scan for viruses, use the clamscan program. This will recursively scan some/directory: clamscan -i -r some/directory -i To only show infected files. If you don’t do this you’ll get a list of every scanned file. -r...
  • Thunar - Thunar 1.4 ish (though most of this also applies to earlier versions). Drag and drop On my system the default drag and drop is a copy. I suspect this has changed in recent versions because I’m sure that before a recent upgrade to v 1.4 the default wa...
  • Hiding stderr or stdout - To hide the standard error (stderr) or standard output (stdout) messages produced by a program, redirect them to /dev/null, a special file that swallows all data written to it. Hide stdout: the_program > /dev/null (Shorthand for the_program 1&g...
  • Date and time - From Changing the timezone, date, and time. The date and time can be changed directly to the hardware clock and then used to update the system clock. > hwclock --show Tue Nov 4 22:13:40 2003 -0.684660 seconds > hwclock --set --date"02/19/2003...
  • Convert image to vector image - To convert a bitmap (or compressed bitmap) image e.g. bmp, jpg, png etc into a vector image… Open the image in Inkscape. Edit -> Select All. Path -> Trace Bitmap. Select Grays. File -> Save As. Choose an SVG format e.g. Plain SVG. ...
  • How to get window properties and information - Use the xprop command to get a list of properties for the selected window, such as its name and state, and xwininfo to get information about the window, such as its size and position. Run the command and click a window. You’ll get output a little like ...
  • How to create a multisession DVD-R. - For data backups to a DVD-R, you can use the growisofs command to write data to the disk and then add more data later. Note: Do not use the -dvd-compat option because it fixates the disk. To add to blank media growisofs -Z /dev/dvd -R -J -V [volume la...
  • Dealing with whitespace in git diff-tree - I wanted to use a git post-commit hook to perform an action on every file that had been committed. A git command can be used to list files committed (from a question on stackoverflow): git diff-tree -r --name-only --no-commit-id HEAD However, this ...
  • Diff and merge using vim (or gvim) - vimdiff allows you to diff and merge two files in vim. Start it with either of the following commands: vimdiff [file1] [file2] vim -d [file1] [file2] You can also use gvim, in which case substitute "vim" for "gvim" in the above ...
  • Using the Bash IFS variable to make for loops split with non whitespace characters - A basic for loop The Bash for loop splits using a whitespace (space, tab or newline). This allows you to easily iterate over a glob of values, as follows (this particular example uses a glob of filenames, taken from a backup script that requires a lis...
  • Printing multiple pages per sheet - How to print multiple page of a document on single sheets of paper (example prints pages 2x2 on a sheet): Convert the doc to pdf pdfnup --nup 2x2 --no-landscape doc.pdf lpr doc-nup.pdf To get pdfnup on gentoo you’ll need to install app-text/p...
  • Determine release (distribution) information - To get release information about your Linux distribution, look for a file in the /etc directory that contains "release" in it's name. On a Gentoo system, this is called /etc/gentoo-release. Redhat will be something like redhat-release. ...
  • Default settings of X applications - For a user, default settings for X apps go in ~/.Xdefaults. For example, here's mine, which sets some aterm settings: aterm*saveLines: 50000 aterm*foreground: white aterm*background: black #aterm*foreground: black #aterm*background: white aterm*transp...
  • NTP stratum - NTP servers are normally set in /etc/ntp.conf. It may take up to 4 hours of semi-continuous reachability to calibrate the clock before you achieve right stratum status. If the stratum status hasn’t changed in a few hours, your synchronization is defin...
  • Trac - Trac is an open source SCM (Source Code Management) and project management tool. This page documents some oddities I came across when configuring it. If I were to be more accurate I suppose the oddities are more conceptual gaps, since, like so many ope...
  • Rake - rake 0.8.7. How to specify subtask in aggregate tasks Problem: This won’t work, failing with “syntax error, unexpected ‘:’, expecting ‘]’”: task :build_and_deploy => [ :build, :deploy:rsync ] Solution: task :build_and_deploy => [ :build, '...
  • Fluxbox key bindings - Here are some fluxbox key bindings, held in the file .fluxbox/keys. They allow me to easily switch windows and workspaces, manipulate windows (close/minimize/shade/move/resize) and open programs. Mod1 Tab :NextWindow Mod1 Shift Tab :PrevWindow Mod1 F...
  • mdadm has been started with 1 drive out of 2 - One of my backup procedures involves mounting a RAID1 array built from two external drives. Today I ran the backup script and it failed to create the array properly - mdadm was refusing to start the array with all disks (in the following examples bpc ~...
  • ldapsearch - For a brief overview of LDAP, these resources may be of use: An introduction to naming services An Introduction to LDAP LDAP Wikipedia entry OpenLDAP provides the ldapsearch command line tool. You can install it on Gentoo by installing the openl...
  • How to remove incompatible extensions / add-ons from Thunderbird or Firefox - When I upgraded Thunderbird 8.0 (on Gentoo Linux) some of the extensions I was using turned out to be incompatible with the latest version. When I viewed the extensions via Tools -> Add-ons -> Extensions tab they were described as incompatible an...
  • Gitosis setup - How to set up gitosis on Debian. gitosis readme Git Repository Hosting in 5 Minute With Gitosis in Debian Lenny Gitosis and a non-standard SSH port Index Install (server-side) Local (server-side) admin setup Remote (client-side) admin ...
  • Debian notes - Notes about Debian Query Debian version: cat /etc/debian_version Logs Debian writes to /var/log/syslog not /var/log/messages. Packages List repositories To see which repositories are being used: cat /etc/apt/sources.list Querying packages ...
  • fstab and octal umasks - The file /etc/fstab defines the various mount points and their parameters (see the Configuration files and directories page). One key attribute is the umask. This is a set of octal values that detemine the permissions of a mount point. It maps...
  • File sharing with Mac OSX - To browse files on a Linux machine from a Mac, install netatalk on the Linux box. This will provide AFP support. On gentoo… emerge -av netatalk Then start the afpd service: /etc/init.d/afpd start On the Mac you should now be able to bring up th...
  • Make Thunderbird open links in your browser - Thunderbird can use a variety of mechanisms to determine which browser to use. System default browser If the http or https content type action is not configured (more on this later), then Thunderbird will open links using the system’s default browser...
  • Grep notes - Some notes on grep, the pattern matching program found on most Linux distributions. Show partial lines on match Grep doesn’t have an option to show leading/trailing characters before/after the match. Instead you have to prevent it returning the entir...
  • PHP script to log in to Drupal and save web page using cURL - The following the PHP script will log in to Drupal 6 and save a web page using cURL. It can be run from the command line (provided PHP is at /user/bin/php) via e.g. a cron job. #!/usr/bin/php <?php /** * Log in to Drupal 6 as USERNAME:PASSWORD and ...
  • Rubygems / gem notes - Notes about Rubygems, the Ruby package manager. View installed gems gem list gem list [package] View available updates gem outdated View gem versions available To show the most recent version: gem list --remote --versions gem list [package...
  • vim with the rails.vim plugin - This page is under construction, so it won't be too useful yet. vim is an advanced text editor. rails.vim is a plugin that adds functional enhancements useful for developing Rails applications. This page is a collection of my notes on using vim wit...
  • Search for words in man pages - To search for [words] in a man page: apropos [words] A shortcut for apropos: man -k [words] Use double quotes for exact phrases, with apropos and man alike: apropos "an exact phrase" No quotes for OR matching: apropos any of these words ...
  • Physical to Virtual (p2v) disk migration for VMWare - The following was copied from a linux manually p2v topic on the VMWare Technology Network (by rjohnso5 on May 18 2005): Here's what I did for a Redhat 9 machine. Maybe you can adapt it? Migrating a Linux Machine to VMWare ESX Before the Linux image i...
  • Fix RMagick after ImageMagick version change - If you update ImageMagick then RMagick will complain that it was configured against the older version. For example: This installation of RMagick was configured with ImageMagick 6.7.5 but ImageMagick 6.7.6-4 is in use For me this occurred because Im...
  • How to rescan a USB card reader - When you plug in a USB card reader, a number of devices will be added (depending on the number of cards supported by the reader). Looking at dmesg output after plugging in the reader... usb 1-2.1: new high speed USB device using ehci_hcd and address ...
  • Modify your routing table to add/remove a route - To add a route.: route add -net [DESTINATION_IP] netmask [MASK_IP] gw [GATEWAY_IP] dev [DEVICE] To delete a route: route del -net [DESTINATION_IP] netmask [MASK_IP] gw [GATEWAY_IP] dev [DEVICE]
  • mdadm notes - Notes on mdadm. Useful commands Get basic info on RAID status: cat /proc/mdstat Read config: cat /etc/mdadm.conf Get detailed info, e.g. for /dev/md1 array: mdadm --detail /dev/md1 Assemble an array To assemble /dev/md1 array from disk p...
  • Send an email from the command line - Sendmail You can use the mail command. I believe it relies on sendmail by default. echo -e "message body" | mail -s "message subject" whoever@example.com With php php -r "mail('whoever@example.com', 'message subject', 'message body');"
  • Configuration files and directories - This page tabulates some common locations of configuration file in Linux. Different distributions store their config in different locations with different filenames. I've made no effort to specify the distribution (these example are from Mandrake 8/9, ...
  • BIND - Berkeley Internet Name Domain - BIND (Berkeley Internet Name Domain) is a DNS server. The daemon /usr/sbin/named is commonly installed as a service /etc/init.d/named. The namespaces (called zones) are defined in /etc/named.conf, and reference config files in the named ...
  • at / atd - The at command is used to run commands at a certain time. Start its daemon: /etc/init.d/atd start Run the command and specify what you’d like it to do: at 13:57 at> touch tmp/attest.txt at> EOT (Send EOT via ctrl-d) The command has a va...
  • How to protect windows in Slime to prevent it replacing your buffers - When you compile something in Slime it can create a number of temporary buffers, which it opens all over the place. I assume that it opens these buffers in the current window (or frame, or whatever the Slime terminology is), but the odd thing is that t...
  • ssh or scp without password - You can prevent ssh asking for a password by using a signature key. You first generate a key pair for your computer, then you copy the public part of it to the remote computer. From then on in, you'll be able to ssh (or scp) from your computer to the r...
  • Working with filenames in bash - Bash has powerful shell parameter expansion capabilities, which we can use along with a couple of functions to deconstruct filenames. To get the directory of a file, use dirname: me@pc ~/tmp $ dirname /home/steph/tmp/test.txt /home/steph/tmp To ge...
  • Find filenames of a certain length - To find files whos filenames have a certain length, you can use various combinations of the ls, egrep and find commands. E.g. find files that have 9 characters followed by .txt: me@pc ~/tmp $ ls ?????????.txt analytics.txt capilinks.txt particles.t...
  • dm-crypt tests - Some tests I did to understand how to work with dm-crypt. Create slap steph # dd if=/dev/urandom bs=1M count=2 >> crypttest 2+0 records in 2+0 records out 2097152 bytes (2.1 MB) copied, 0.673763 s, 3.1 MB/s slap steph # ls -l crypttest -rw-r--...
  • Debugging load library path issues - If you get a problem with a library that can't find another, you should check the library's dependencies and make sure that the directory in which the missing library resides is part of the load library path. One example of this problem, that I exper...
  • Terminating or killing a process - Send a TERM signal (SIGTERM) to the process to terminate gracefully, by requesting that it do so. kill -TERM pid Or: kill -15 pid Where pid is the process identifier. Send a KILL signal to force the termination: kill -KILL pid Or: kill -9...
  • How to get rid of a blue tint / inverted colours in flash videos and PDF documents - I recently upgraded my system (which uses an nVidia graphics card) and found that Flash videos (e.g. YouTube) and PDF documents inverted some colours, so e.g. skin would appear blue! To fix this for flash videos I enabled hardware acceleration in the ...

Last modified: 04/06/2007 Tags: (none)

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top