Linux Tips and Tricks

Verify md5sum using linux
md5sum -c linux.iso.md5

Create an md5sum using linux
md5sum linux.iso > linux.iso.md5

Verify md5sum using windows
rename the md5sum file (.md5sum, .asc, etc.) to .md5 extension if not already.
Download QuickPar and in options check Associate with SFV/MD5 files
Double-click linux.iso.md5 and it’ll verify it’s md5sum.
linux.iso and linux.iso.md5 must be in the same directory.

Curl has support for files over 2GB while wget only has a hacked patched version.

To download a linux iso using wget or curl
curl -o linux.iso

To download a linux iso using wget or curl that has hot-linking protection
wget –referer=
curl -o linux.iso -e

To resume a partially download file using wget or curl
wget -c –referer=
curl -C – -o linux.iso -e

To resume a partially download file via ftp with username and password using curl
curl -C – -u username:password -o linux.iso

To download many linux iso images in queue using wget or curl
wget –referer=

curl -C – -o linux.iso -e

To get the size of all directories in the current directory:
find . -maxdepth 1 -type d -print | xargs du -sk | sort -rn

A spiffy way to see what directories are taking up the most space on your hard drive is du -sk * | sort -n — this will show just the base-level directories in whatever directory you run this in. So it will include the size of sub-directories, but not list them in the output.

To run a program in the background simply add a & to the end of your command, i.e. top &. If you have already started the program and you now want to run it in the background first suspsend it with CTRL – Z then type bg To get the program back in the foreground simply issue the command fg.

Instead of cd /home/user you can simply cd ~ or cd to quickly get to your home directory. also cd – will return you to your previous directory you were in.

If you untar a package, and it makes a mess of your directory because the packager didn’t include the files in his tarball in a directory, you can use rm `tar ftz stupidpackage-1.0.0.tar.gz` to quickly get rid of those cluttering files.

This might sound silly, but for the longest time I didn’t know how to examine my system and it’s information effectively. issuing df or df -h will show you free and used disk space, procinfo if installed gives you a wealth of information from /proc, and overmore cat/proc/interrupts or cat /proc/cpuinfo gives your irq settings and your cpu information respectively. Play around, /proc holds many more system tid bits if you look.

If you want to mirror via ftp something like the latest RedHat distribution, an easy way is to use Midnight Commander (mc). Type: $ mc and then press F9 and select FTP link . . . and enter a host such as Move to directory you want to download and select file/directory by Insert-key and press F5 to copy. This may be a nice alternative for people who don’t want to use a command line FTP client.

Search for SUID programs to save yourself from getting rooted with find / -perm -4000

Sometimes it is necessary to know which rpm package contains one or another file. One way to make a catalog of all files from all rpms of your favorite distribution is:
rpm -qpil /mnt/cdrom/YourDistro/RPMS/*rpm > rpms-info.txt

This will create rpms-info.txt file contaning information about each rpm from requested directory with the list of all files encapsulated in each rpm packages. The same should work for ftp directories.

lsmod is a great way to check out information about your loaded modules.

You can use the smbmount command to mount windows shares like normal drives. For this you need samba and smbfs support in your kernel. The syntax is:
smbmount “\\\\name\\share” -c ‘mount /mnt/point’ -I ip#
smbmount “\\\\WINDOZE\\c” -c ‘mount /mnt/smb1’ -I

While using bash, if you have typed a long command, and then realize you don’t want to execute it yet, don’t delete it. Simply append a # to the beginning of the line, and then hit enter. Bash will not execute the command, but will store it in history so later you can go back, remove the # from the front, and execute it.

To view the contents of a file that is growing in size (e.g. a log file) use tail +0 -f file. The command tail -0 -f file can be used to create an ersatz or substitute FIFO.

Where has all my disk space gone! start in /home or /var and run the following:
du -S | sort -n -r | more

which will lists directory sizes, starting with the largest.

Sometimes you may want to unzip more than one file simultaneously. Doing unzip * does not work, the correct way to do it is by adding quotes, like this: unzip “*”

In the bash console, hitting ALT-printscreen will switch you immediately to the tty you were last at.

To search the entire hard disk for files containing “pattern” you can use find:
find / -name ‘*’ -exec grep pattern {} \;

Type ls -alF | grep /$ for a list of subdirs in the current directory. I have this aliased to ‘lsd’

netstat -a will allow you to see all the tcp and udp ports your system has open.

pstree will print out they system’s tree of process, so you can see what processes came from what processes.

To look at an RPMs information for both already installed packages and packages for which you have the file for, rpm -qi package_name will do it.

A cool way to get screenshots in X windows is to use the import command. Example: import background.jpg then make a box around what you want with you cursor.

You can use all valid terminals, even if they aren’t being used, by sending your data to the terminal number you want. Example: tail -f /var/log/messages > /dev/tty12
would send any messages or syslog stuff to tty12, which is accessable by LEFTALT-F12.

If you want to run a command and log out while it is running, you nohup. Example: nohup program or nohup %1

To use a text mode other than the default 80×25, such as 80×50 or even 132×60, put vga=ask into your lilo.conf file and then run lilo. When you reboot it will let you choose your video mode. When you decide which one you want, you can put vga=n where n is the number of the video mode you would like. Usually n is 1 through 8.

ifconfig eth0 <ipaddress>
route add default gw <ipofgateway>
vi /etc/HOSTNAME

lpr -P <printername>

mount -t ramfs ramfs /ramfiles
mount -o loop .iso /mnt/pt

lftp rm-r /mirror -Rv /localdirectory

mount -t iso9660 -o ro,loop=/dev/loop0 /var/tmp/some.iso /mnt/cdrom

ping <ipaddress> -i90 > /dev/null &

:set ic (ignore case-sensitivity)
%s/.\ (wg html logs)

dd if=boot.img of=/dev/fd0

cdrecord -scanbus
cdrecord -v -eject speed=4 dev=0,5,0 -isosize /dev/cdrom
cdrecord -v -eject speed=4 dev=0,5,0 /home/files

dd if=/dev/cdrom of=imagename.iso

mount -o loop somecool.iso /mnt/iso

tr -d ‘\r’ < dosfile.txt > unixfile.txt

du -s * | awk ‘{printf(“%6s %s\n”, $1, $2)}’ | sort could be, and could be .
ifconfig eth0:1; ifconfig eth0:2 to bind both ip addresses to a box.

mount -t smbfs -o username=user,password=pass //server/share /mount/point
smbmount //windowsmachine/sharename /mnt/mountpoint -I windowsIpAdress -U windowsUsername

wireless connections
iwconfig wlan0 essid topsecret
ifconfig wlan up
pump -i wlan0

________________________________________________________________ – – –

netmask | x | Subnet
~~~~~~~~~~~~~~~~|~~~~|~~~~~~~~~~~~~~~ | /8 | Class A | /16 | Class B |/ 24 | Class C |/ 32 | Point-to-point


1 kilobyte = 2^10 Bytes = 1024 bytes
1 Megabyte = 2^20 Bytes = 1024 kilobytes
1 gigabyte = 2^30 Bytes = 1024 Megabytes
1 terabyte = 2^40 Bytes = 1024 gigabytes
1 petabyte = 2^50 Bytes = 1024 terabytes
1 Exabyte = 2^60 Bytes = 1024 petabytes
1 Zettabyte = 2^70 Bytes = 1024 Exabytes
1 Yottabyte = 2^80 Bytes = 1024 Zettabytes

1 kilobyte =1024 bytes
1 kilobytes=1048576 bytes
1 gigabyte =1073741824 bytes
1 terabyte =1099511627776 bytes
1 petabyte =1125899906842624 bytes
1 Exabyte =1152921504606846976 bytes
1 Zettabyte=1180591620717411303424 bytes
1 Yottabyte=1208925819614629174706176 bytes


Prevent Hotlinking

Prevent Hotlinking files and/or images code should be put in main config file if you have access to httpd.conf as opposed to .htaccess in the www/ directory if you have root access to server

vi /etc/apache/conf/httpd.conf (and put and end of file)

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?*$ [NC]
RewriteRule .*\.(iso|exe|zip|rar|jpg)$ [R]

Then restart apache and it’ll tell you if any errors exist or not
/etc/init.d/apache restart

If you don’t have apache mod_rewrite loaded then you could use below however it restricts you only allowing you to return a 403 forbidden page.

SetEnvIfNoCase Referer “^” local_ref=1
SetEnvIfNoCase Referer “^” local_ref=1
SetEnvIfNoCase Referer “^$” local_ref=1
<FilesMatch “.(iso|exe|zip|rar|jpg)”>
Order Allow,Deny
Allow from env=local_ref

Scroll to Top