20100203

Linux secrets

Linux Tips and Tricks

Verify md5sum using linuxmd5sum -c linux.iso.md5
Create an md5sum using linuxmd5sum 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
wget http://www.mrbass.org/linux.iso
curl -o linux.iso http://www.mrbass.org/linux.iso


To download a linux iso using wget or curl that has hot-linking protection
wget --referer=http://www.mrbass.org http://www.mrbass.org/linux.iso
curl -o linux.iso -e http://www.mrbass.org http://www.mrbass.org/linux.iso

To resume a partially download file using wget or curlwget -c --referer=http://www.mrbass.org http://www.mrbass.org/linux.iso
curl -C - -o linux.iso -e http://www.mrbass.org http://www.mrbass.org/linux.iso
To resume a partially download file via ftp with username and password using curlcurl -C - -u username:password -o linux.iso ftp.mrbass.org/linux.iso

To download many linux iso images in queue using wget or curl
wget --referer=http://www.mrbass.org http://www.mrbass.org/linuxcd1.iso http://www.mrbass.org/linuxcd2.iso http://www.mrbass.org/linuxcd3.iso
curl -C - -o linux.iso -e http://www.mrbass.org http://www.mrbass.org/linux.iso 
http://www.mrbass.org/linuxcd2.iso http://www.mrbass.org/linuxcd3.iso 
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 overmorecat/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 sunsite.unc.edu 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 withfind / -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#
Example:
smbmount "\\\\WINDOZE\\c" -c 'mount /mnt/smb1' -I 10.0.0.13
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_namewill 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 80x25, such as 80x50 or even 132x60, 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.

No comments:

Post a Comment