Monday, November 10, 2008
HOWTO: Use dpkg to Install .deb Files.
I’ve written about using apt-get to get and install debian packages. However, a recent comment by a reader brought the fact that I hadn’t written anything on what to do with a .deb file that exists on your system already either by download or other media.
Using the apt-get application is the quickest way to find and install debian packages. The installation part is done by an application
named dpkg. Dpkg doesn’t have to be used by apt-get, you can use it manually as well.
From the man dpkg command:
dpkg - a medium-level package manager for Debian
Whatever that means.
In keeping with GNU/Linux system security, only the superuser can use the dpkg application. Dpkg is a typical GNU/Linux application that is controlled by command-line switches. Possibly the most common use of dpkg is to install a local .deb file.
To install a .deb file, become root and use the command:
dpkg -i filename.deb
Dpkg can also be used to:
* dpkg –unpack: unpacks the file but does not install it
* dpkg –configure: presents whatever configuration options are available for the package
* dpkg –remove: removes a package
Some of the package manipulation commands are actually carried out by an application called dpkg-deb. In those cases, dpkg just acts as a front end to dpkg-deb and passes the commands to it.
Dpkg-deb can also be used to manipulate .deb files. Some of the more useful commands of dpkg-deb are:
dpkg-deb –show filename.deb
This will display the information for filename.deb. Normally, this is boring information like the application version (which is normally evident from the filename), but in some cases more interesting and useful information is displayed.
Consult the dpkg man page for information on the more arcane uses for dpkg.
Sunday, October 12, 2008
10 keyboard shortcuts to improve your Linux experience
A few simple keyboard shortcuts can make your work in Linux far more efficient. Jack Wallen runs through 10 of his favorites, for both desktop environments and window managers.
Many Linux users are keyboard cowboys, breaking out in a cold, cold sweat when their nimble fingers have to leave the keyboard for the mouse. But even if you’re not like that, you can still employ some of those fantastic keyboard shortcuts that help make Linux commuting efficient. To get you started, here are my 10 favorite Linux keyboard shortcuts. Disclaimer: Some of these shortcuts will be desktop environment- or window manager-specific.
Note: This information is also available as a PDF download.
1: Ctl + Alt + Backspace
Use this shortcut when X isn’t responding or a program has locked up your desktop and you can’t get anything to respond. This combination instantly logs you out of X, taking you back to the login screen. It works with all desktop environments and window managers.
2: Ctrl + Alt + Delete
This is the big kahuna. If all else fails and you just need to reboot, you can hit this combination to instantly start the reboot process. All data will be lost, so use it wisely. This combination works in all desktop environments and all window managers.
3: Alt + Tab
This handy shortcut allows you to cycle through all open windows, stopping on the window you want to have focus. In other words, you don’t have to grab your mouse and click (or hover, depending upon your focus configuration) to give a window focus. To cycle through the windows, hold down the Alt key and then press the Tab key until you land on the window you want. This shortcut works in most desktop environments and window managers.
4: Ctrl + Alt + F*
This is one of those mack-daddy shortcuts you very well might need to use. It switches to various virtual terminals. The default terminal you’re working in is 6. So you can switch to another terminal by holding down Ctrl + Alt and hitting F1, F2, F3, F4, F5, F7, etc. Now these are virtual terminals, so if you already have a graphical interface going, you’ll only be able to work in a text-based terminal window. This is really good for debugging problems with the desktop or killing frozen applications when you don’t want to kill X completely.
(My note: At least in Ubuntu, with Ctrl + Alt + F7 you can return to the X environment from any of the virtual terminals. The virtual terminals are only from F1 to F6. The F8 shows you the last messages before going into X.)
5: Alt + Arrow key
If you’re using Linux, you probably know about the pager that allows you to have multiple desktops at one time. Instead of having to move your mouse to the edge of a screen, you can hit Alt and either the left or right arrow key to move from one desktop to another. This works in all desktop environments and window managers.
The following apply only to terminal (aka console) windows
6: Ctrl + a and Ctrl + e
If you are working in a text editor like Nano (from within a terminal window), you can get to the beginning of a line with Ctrl + a and the end of a line with Ctrl + e. These do not work in GUI applications. In a GUI application (such as OpenOffice), these combinations will work as they would in a normal desktop world. (For example, Ctrl + a will highlight all the text on a page.)
7: Ctrl + c
When you have a process running in a terminal window (say you’re following a process with the tail + f command), you can kill that process with the Ctrl + c combination.
8: Ctrl + z
This will zombie an application. If you have a process running in a terminal and you want the terminal back but don’t want to kill the application, you can hit Ctrl + z to send the process to the background. To get the process back, type fg.
9: Arrow up or Arrow down
The up or down arrow key, when in a terminal window, cycles through the history of commands you have issued in the terminal window. This is helpful for two reasons: You don’t have to retype commands all the time and you can more easily recall what commands have been run recently.
10: Ctrl + r
This is a handy command search tool. When you hit Ctrl + r, you are prompted to enter a character (or string of characters). You’ll have returned to you any previously issued command with that character or combination within. This is helpful because it does not discriminate between commands and switches. So if you can only remember a switch you used, you can enter that and the command will appear. When the command shows up you want, hit Enter to execute.
The keyboard advantage
These 10 simple Linux keyboard shortcuts will help you make your work in Linux far more efficient. Yes, there are plenty more beyond this list. Some shortcuts are specific to a particular environment, and many desktops or window managers allow you to create your own keyboard shortcuts. Use that feature, and you’ll find yourself working far more efficiently without having to move your hand from key to mouse and back.
Linux Shortcuts and Commands:
Linux Newbie Administrator Guide
by Stan and Peter Klimas (link)
This is a practical selection of the commands we use most often. Press
Legend:
<> = single special or function key on the keyboard. For example
italic = name of the file or variable you probably want to substitute with your own.
fixed width = in-line Linux commands and filenames.
Notes for the UNIX Clueless:
1. LINUX IS CASE-SENSITIVE. For example: Netscape, NETSCAPE and nEtscape are three different commands. Also my_filE, my_file, and my_FILE are three different files. Your user login name and password are also case sensitive. (This goes with the tradition of UNIX and the "c" programming language being case sensitive.)
2. Filenames can be up to 256 characters long and can contain letters, numbers, "." (dot), "_" (underscore), "-" (dash), plus some other not recommended characters.
3. Files with names starting with "." are normally not shown by the ls (list) or dir commands. Think of these files as "hidden". Use ls -a (list with the option "all") to see these files.
4. "/" is an equivalent to DOS "\" (root directory, meaning the parent of all other directories).
5. Under Linux, all directories appear under a single directory tree (there are no DOS-style drive letters).
6. In a configuration file, a line starting with # is a comment.
7.1 Linux essential shortcuts and sanity commands
Switch to the first text terminal. Under Linux you can have several (6 in standard setup) terminals opened at the same time.
Switch to the nth text terminal.
tty
Print the name of the terminal in which you are typing this command.
Switch to the first GUI terminal (if X-windows is running on this terminal).
Switch to the nth GUI terminal (if a GUI terminal is running on screen n-1). On default, nothing is running on terminals
8 to 12, but you can run another server there.
(In a text terminal) Autocomplete the command if there is only one option, or else show all the available options.
THIS SHORTCUT IS GREAT! It even works at LILO prompt!
Scroll and edit the command history. Press
Scroll terminal output up. Work also at the login prompt, so you can scroll through your bootup messages.
Scroll terminal output down.
(in X-windows) Change to the next X-server resolution (if you set up the X-server to more than one resolution). For multiple resolutions on my standard SVGA card/monitor, I have the following line in the file /etc/X11/XF86Config (the first resolution starts on default, the largest determines the size of the "virtual screen"):
Modes "1024x768" "800x600" "640x480" "512x384" "480x300" "400x300" "1152x864"
(in X-windows) Change to the previous X-server resolution.
(in X-windows) Kill the current X-windows server. Use if the X-windows server crushes and cannot be exited normally.
Shut down the system and reboot. This is the normal shutdown command for a user at the text-mode console. Don't just press the "reset" button for shutdown!
Kill the current process (mostly in the text mode for small applications).
Log out from the current terminal. See also the next command.
Send [End-of-File] to the current process. Don't press it twice else you also log out (see the previous command).
Stop the transfer to the terminal.
Resume the transfer to the terminal. Try if your terminal mysteriously stops responding.
Send the current process to the background.
exit
Logout. I can also use logout for the same effect. (If you have started a second shell, e.g., using bash the second shell will be exited and you will be back in the first shell, not logged out.)
reset
Restore a screwed-up terminal (a terminal showing funny characters) to default setting. Use if you tried to "cat" a binary file. You may not be able to see the command as you type it.
Paste the text which is currently highlighted somewhere else. This is the normal "copy-paste" operation in Linux. (It doesn't work with Netscape and WordPerfect which use the MS Windows-style "copy-paste". It does work in the text terminal if you enabled "gpm" service using "setup".) Best used with a Linux-ready 3-button mouse (Logitech or similar) or else set "3-mouse button emulation").
~
(tilde) My home directory (normally the directory /home/my_login_name). For example, the command cd ~/my_dir will change my working directory to the subdirectory "my_dir" under my home directory. Typing just "cd" alone is an equivalent of the command "cd ~".
.
(dot) Current directory. For example, ./my_program will attempt to execute the file "my_program" located in your current working directory.
..
(two dots) Directory parent to the current one. For example, the command cd .. will change my current working directory one one level up.
7.2 Common Linux commands--system info
Print working directory, i.e., display the name of my current directory on the screen.
hostname
Print the name of the local host (the machine on which you are working). Use netconf (as root) to change the name of the machine.
whoami
Print my login name.
id username
Print user id (uid) and his/her group id (gid), effective id (if different than the real id) and the supplementary groups.
date
Print or change the operating system date and time. E.g., I could change the date and time to 2000-12-31 23:57 using this command:
date 123123572000
To set the hardware (BIOS) clock from the system (Linux) clock, use the command (as root) setclock
time
Determine the amount of time that it takes for a process to complete + other info. Don't confuse it with the date command. E.g. I can find out how long it takes to display a directory content using:
time ls
who
Determine the users logged on the machine.
rwho -a
(=remote who) Determine all users logged on your network. The rwho service must be enabled for this command to run. If it isn't, run setup as root to enable "rwho".
finger user_name
System info about a user. Try: finger root
last
Show listing of users last logged-in on your system.
history | more
Show the last (1000 or so) commands executed from the command line on the current account. The "| more" causes the display to stop after each screenful.
uptime
Show the amount of time since the last reboot.
ps
(=print status) List the processes currently run by the current user.
ps axu | more
List all the processes currently running, even those without the controlling terminal, together with the name of the user that owns each process.
top
Keep listing the currently running processes, sorted by cpu usage (top users first). In KDE, you can get GUI-based Ktop from "K"menu under "System"-"Task Manager" (or by executing "ktop" in an X-terminal).
uname -a
(= Unix name with option "all") Info on your (local) server. I can also use guname (in X-window terminal) to display the info more nicely.
free
Memory info (in kilobytes).
df -h
(=disk free) Print disk info about all the filesystems (in human-readable form)
du / -bh | more
(=disk usage) Print detailed disk usage for each subdirectory starting at the "/" (root) directory (in human legible form).
cat /proc/cpuinfo
Cpu info--it show the content of the file cpuinfo. Note that the files in the /proc directory are not real files--they are hooks to look at information available to the kernel.
cat /proc/interrupts
List the interrupts in use.
cat /proc/version
Linux version and other info
cat /proc/filesystems
Show the types of filesystems currently in use.
cat /etc/printcap
Show the setup of printers.
lsmod
(As root. Use /sbin/lsmod to execute this command when you are a non-root user.) Show the kernel modules currently loaded.
set|more
Show the current user environment.
echo $PATH
Show the content of the environment variable "PATH". This command can be used to show other environment variables as well. Use "set" to see the full environment.
dmesg | less
Print kernel messages (the content of the so-called kernel ring buffer). Press "q" to quit "less". Use less /var/log/dmesg to see what "dmesg" dumped into this file right after the last system bootup.
7.3 Basic operations
any_command --help |moreDisplay a brief help on a command (works with most commands). "--help" works similar to DOS "/h" switch. The "more" pipe is needed if the output is longer than one screen.
man topic
Display the contents of the system manual pages (help) on the topic. Try man man first. Press "q" to quit the viewer. The command info topic works similar and may contain more up-to-date information. Manual pages can be hard to read. Try any_command --help for short, easy to digest help on a command. If more info needed, have a look to the directory /usr/doc. To display manual page from a specific section, I may use something like in this example: man 3 exit (this displays an info on the command exit from section 3 of the manual pages).
apropos topic
Give me the list of the commands that have something to to do with my topic.
help command
Display brief info on a bash (shell) build-in command.
ls
List the content of the current directory. Under Linux, the command "dir" is an alias to ls. Many users have "ls" to be an alias to "ls --color".
ls -al |more
List the content of the current directory, all files (also those starting with a dot), and in a long form. Pipe the output through the "more" command, so that the display pauses after each screenful.
cd directory
Change directory. Using "cd" without the directory name will take you to your home directory. "cd -" will take you to your previous directory and is a convenient way to toggle between two directories. "cd .." will take you one directory up.
cp source destination
Copy files. E.g., cp /home/stan/existing_file_name . will copy a file to my current working directory. Use the "-r" option (for recursive) to copy the contents of whole directories, e.g. , cp -r my_existing/dir/ ~ will copy a subdirectory under my current working directory to my home directory.
mcopy source destination
Copy a file from/to a DOS filesystem (no mounting necessary). E.g., mcopy a:\autoexec.bat ~/junk . See man mtools for related commands: mdir, mcd, mren, mmove, mdel, mmd, mrd, mformat ....
mv source destination
Move or rename files. The same command is used for moving and renaming files and directories.
ln source destination
Create a hard link called destination to the file called source. The link appears as a copy of the original files, but in reality only one copy of the file is kept, just two (or more) directory entries point to it. Any changes the file are automatically visible throughout. When one directory entry is removed, the other(s) stay(s) intact. The limitation of the hard links are: the files have to be on the same filesystem, hard links to directories or special files are impossible.
ln -s source destination
Create a symbolic (soft) link called "destination" to the file called "source". The symbolic link just specifies a path where to look for the file. In contradistinction to hard links, the source and destination don't not have to tbe on the same filesystem. In comparison to hard links, the drawback of symbolic links are: if the original file is removed, the link is "broken", symbolic links can also create circular references (like circular references in spreadsheets or databases, e.g., "a" points to "b" and "b" points back to "a").
rm files
Remove (delete) files. You must own the file in order to be able to remove it. On many systems, you will be asked or confirmation of deleation, if you don't want this, use the "-f" (=force) option, e.g., rm -f * will remove all files in my current working directory, no questions asked.
mkdir directory
Make a new directory.
rmdir directory
Remove an empty directory.
rm -r files
(recursive remove) Remove files, directories, and their subdirectories. Careful with this command as root--you can easily remove all files on the system with such a command executed on the top of your directory tree, and there is no undelete in Linux (yet). But if you really wanted to do it (reconsider), here is how (as root): rm -rf /*
cat filename | more
View the content of a text file called "filename", one page a time. The "|" is the "pipe" symbol (on many American keyboards it shares the key with "\") The pipe makes the output stop after each screenful. For long files, it is sometimes convenient to use the commands head and tail that display just the beginning and the end of the file. If you happened to use "cat" a binary file and your terminal displays funny characters afterwards, you can restore it with the command "reset".
less filename
Scroll through a content of a text file. Press q when done. "Less" is roughly equivalent to "more" , the command you know from DOS, although very often "less" is more convenient than "more".
pico filename
Edit a text file using the simple and standard text editor called pico.
pico -w filename
Edit a text file, while disabling the long line wrap. Handy for editing configuration files, e.g. /etc/fstab.
find / -name "filename"
Find the file called "filename" on your filesystem starting the search from the root directory "/". The "filename" may contain wildcards (*,?).
locate filename
Find the file name of which contains the string "filename". Easier and faster than the previous command but depends on a database that normally rebuilds at night.
./program_name
Run an executable in the current directory, which is not on your PATH.
touch filename
Change the date/time stamp of the file filename to the current time. Create an empty file if the file does not exist.
xinit
Start a barebone X-windows server (without a windows manager).
startx
Start an X-windows server and the default windows manager. Works like typing "win" under DOS with Win3.1
startx -- :1
Start another X-windows session on the display 1 (the default is opened on display 0). You can have several GUI terminals running concurrently. Switch between them using
xterm
(in X terminal) Run a simple X-windows terminal. Typing exit will close it. There are other, more advanced "virtual" terminals for X-windows. I like the popular ones: konsole and kvt (both come with kde) and gnome-terminal (comes with gnome). If you need something really fancy-looking, try Eterm.
xboing
(in X terminal). Very nice, old-fashioned game. Many small games/programs are probably installed on your system. I also like xboard (chess).
shutdown -h now
(as root) Shut down the system to a halt. Mostly used for a remote shutdown. Use for a shutdown at the console (which can be done by any user).
halt
reboot
(as root, two commands) Halt or reboot the machine. Used for remote shutdown, simpler to type than the previous command.
Network apps
(in X terminal) Run netscape (requires a separate Netscape installation). The current versions of Netscape (4.x) are known to be big and buggy. They occasionally crash by vanishing (no other harm done). Also, when not connected to the network , Netscape likes to refuse to do anything (looks like it hanged)-it revives when you connect.
netscape -display host:0.0
(in X terminal) Run netscape on the current machine and direct the output to machine named "host" display 0 screen 0. Your current machine must have a permission to display on the machine "host" (typically given by executing the command xhost current_machine_name in the xterminal of the machine host. Other X-windows program can be run remotely the same way.
lynx file.html
View an html file or browse the net from the text mode.
pine
A good text-mode mail reader. Another good and standard one is elm. Your Netscape mail will read the mail from your Internet account. pine will let you read the "local" mail, e.g. the mail your son or a cron process sends to you from a computer on your home network. The command mail could also be used for reading/composing mail, but it would be inconvenient--it is meant to be used in scripts for automation.
elm
A good tex-mode mail reader. See the previous command.
mutt
A really basic but extremally useful and fast mail reader.
mail
A basic operating system tool for e-mail. Look at the previous commands for a better e-mail reader. mail is good if you wanted to send an e-mail from a shell script.
licq
(in X term) An icq "instant messaging" client. Another good one is kxicq. Older distributions don't have an icq client installed, you have to do download one and install it.
talk username1
Talk to another user currently logged on your machine (or use "talk username1@machinename" to talk to a user on a different computer) . To accept the invitation to the conversation, type the command "talk username2". If somebody is trying to talk to you and it disrupts your work, your may use the command "mesg n" to refuse accepting messages. You may want to use "who" or "rwho" to determine the users who are currently logged-in.
mc
Launch the "Midnight Commander" file manager (looks like "Norton Commander" for Linux).
telnet server
Connect to another machine using the TELNET protocol. Use a remote machine name or IP address. You will be prompted for your login name and password--you must have an account on the remote machine to login. Telnet will connect you to another machine and let you operate on it as if you were sitting at its keyboard (almost). Telnet is not very secure--everything you type goes in open text, even your password!
rlogin server
(=remote login) Connect to another machine. The login name/password from your current session is used; if it fails you are prompted for a password.
rsh server
(=remote shell) Yet another way to connect to a remote machine. The login name/password from your current session is used; if it fails you are prompted for a password.
ftp server
Ftp another machine. (There is also ncftp which adds extra features and gftp for GUI .) Ftp is good for copying files to/from a remote machine. Try user "anonymous" if you don't have an account on the remote server. After connection, use "?" to see the list of available ftp commands. The essential ftp command are: ls (see the files on the remote system), ASCII, binary (set the file transfer mode to either text or binary, important that you select the proper one ), get (copy a file from the remote system to the local system), mget (get many files at once), put (copy a file from the local system to the remote system), mput (put many files at once), bye (disconnect). For automation in a script, you may want to use ncftpput and ncftpget, for example:
ncftpput -u my_user_name -p my_password -a remote.host.domain remote_dir *local.html
minicom
Minicom program (looks like "Procomm for Linux").
File (de)compression
tar -zxvf filename.tar.gz(=tape archiver) Untar a tarred and compressed tarball (*.tar.gz or *.tgz) that you downloaded from the Internet.
tar -xvf filename.tar
Untar a tarred but uncompressed tarball (*.tar).
gunzip filename.gz
Decompress a zipped file (*.gz" or *.z). Use gzip (also zip or compress) if you wanted to compress files to this file format.
bunzip2 filename.bz2
(=big unzip) Decompress a file (*.bz2) zipped with bzip2 compression utility. Used for big files.
unzip filename.zip
Decompress a file (*.zip) zipped with a compression utility compatible with PKZIP for DOS.
unarj e filename.arj
Extract the content of an *.arj archive.
uudecode -o outputfile filename
Decode a file encoded with uuencode. uu-encoded files are typically used for transfer of non-text files in e-mail (uuencode transforms any file into an ASCII file).
7.4 Process control
ps(=print status) Display the list of currently running processes with their process IDs (PID) numbers. Use ps axu to see all processes currently running on your system (also those of other users or without a controlling terminal), each with the name of the owner. Use "top" to keep listing the processes currently running.
fg PID
Bring a background or stopped process to the foreground.
bg PID
Send the process to the background. Opposite to fg. The same can be accomplished with
any_command&
Run any command in the background (the symbol "&" means "run the proceeding command in the background").
batch any_command
Run any command (usually one that is going to take more time) when the system load is low. I can logout, and the process will keep running.
at 17:00
Execute a command at a specified time. You will be prompted for the command(s) to run, until you press
kill PID
Force a process shutdown. First determine the PID of the process to kill using ps.
killall program_name
Kill program(s) by name.
xkill
(in an xwindow terminal) Kill a GUI-based program with mouse. (Point with your mouse cursor at the window of the process you want to kill and click.)
lpc
(as root) Check and control the printer(s). Type "?" to see the list of available commands.
lpq
Show the content of the printer queue. Under KDE (X-Windows), you may use GUI-based "Printer Queue" available from "K"menu-Utilities.
lprm job_number
Remove a printing job "job_number" from the queue.
nice program_name
Run program_name adjusting its priority. Since the priority is not specified in this example, it will be adjusted by 10 (the process will run slower), from the default value (usually 0). The lower the number (of "niceness" to other users on the system), the higher the priority. The priority value may be in the range -20 to 19. Only root may specify negative values. Use "top" to display the priorities of the running processes.
renice -1 PID
(as root) Change the priority of a running process to -1. Normal users can only adjust processes they own, and only up from the current value (make them run slower).
7.5 Basic administration commands
printtool(as root in X-terminal) Configuration tool for your printer(s). Settings go to the file /etc/printcap.
setup
(as root) Configure mouse, soundcard, keyboard, X-windows, system services. There are many distibution-specific configuration utilities, setup is the default on RedHat. Mandrake 7.0 offers very nice DrakConf .
linuxconfig
(as root, either in text or graphical mode). You can access and change hundreds of setting from it. Very powerful--don't change too many things at the same time, and be careful with changing entries you don't understand.
xvidtune
(in X-terminal). Adjust the settings of the graphical display for all resolutions so as to eliminate black bands, shift the display right/left/up/down, etc. (First use the knobs on your monitor to fit your text mode correctly on the screen.) To make the changes permanent, display the frequencies on the screen and transfer them to the setup file /etc/X11/XF86Config.
alias ls="ls --color=tty"
Create an alias for the command "ls" to enhance its format with color. In this example, the alias is also called "ls" and the "color" option is only envoke when the output is done to a terminal (not to files). Put the alias into the file /etc/bashrc if you would like the alias to be always accessible to all users on the system. Type "alias" alone to see the list of aliases on your system.
adduser user_name
Create a new account (you must be root). E.g., adduser barbara Don't forget to set up the password for the new user in the next step. The user home directory is /home/user_name.
useradd user_name
The same as the command " adduser user_name ".
userdel user_name
Remove an account (you must be a root). The user's home directory and the undelivered mail must be dealt with separately (manually because you have to decide what to do with the files).
groupadd group_name
Create a new group on your system. Non-essential but can be handy even on a home machine with a small number of users.
passwd
Change the password on your current account. If you are root, you can change the password for any user using: passwd user_name
chmod perm filename
(=change mode) Change the file access permission for the files you own (unless you are root in which case you can change any file). You can make a file accessible in three modes: read (r), write (w), execute (x) to three classes of users: owner (u), members of the same group as the owner (g), others on the system (o). Check the current access permissions using:
ls -l filename
If the file is accessible to all users in all modes it will show:
rwxrwxrwx
The first triplet shows the file permission for the owner of the file, the second for his/her group, the third for others. A "no" permission is shown as "-".
E.g., this command will add the permission to read the file "junk" to all (=user+group+others):
chmod a+r junk
This command will remove the permission to execute the file junk from others:
chmod o-x junk
Also try here for more info.
You can set the default file permissions for the news files that you create using the command umask (see man umask).
chown new_ownername filename
chgrp new_groupname filename
Change the file owner and group. You should use these two commands after you copy a file for use by somebody else.
su
(=substitute user id) Assume the superuser (=root) identity (you will be prompted for the password). Type "exit" to return you to your previous login. Don't habitually work on your machine as root. The root account is for administration and the su command is to ease your access to the administration account when you require it. You can also use "su" to assume any other user identity, e.g. su barbara will make me "barbara" (password required unless I am a superuser).
kernelcfg
(as root in X terminal). GUI to to add/remove kernel modules. You can do the same from the command line using the command "insmod", but "insmode" is less "newbie-friendly".
lsmod
List currently loaded kernel modules. A module is like a device driver--it provides operating system kernel support for a particular piece of hardware or feature.
modprobe -l |more
List all the modules available for your kernel. The available modules are determined by how your Linux kernel was compliled. Every possible module/feature can be compiled on linux as either "hard wired" (fast, non-removable), "module" (maybe slower, but loaded/removable on demand), or "no" (no support for this feature at all).
insmod parport
insmod ppa
(as root) Insert modules into the kernel (a module is roughly an equivalent of a DOS device driver). This example shows how to insert the modules for support of the external parallel port zip drive (it appears to be a problem to get the external zip drive to work in any other way under RH6.0 ).
rmmod module_name
(as root, not essential). Remove the module module_name from the kernel.
setserial /dev/cua0 port 0x03f8 irq 4
(as root) Set a serial port to a non-standard setting. The example here shows the standard setting for the first serial port (cua0 or ttyS0). The standard PC settings for the second serial port (cua1or ttyS1) are: address of i/o port 0x02f8, irq 3. The third serial port (cua2 or ttyS2): 0x03e8, irq 4. The forth serial port (cua3 or ttyS3): 0x02e8, irq 3. Add your setting to /etc/rc.d/rc.local if you want it to be set at the boot time. See man setserial for good a overview.
fdisk
(as root) Linux hard drive partitioning utility (DOS has a utility with the same name).
cd /usr/src/linux-2.0.36
make xconfig
(as root in X terminal). Nice GUI front-end for configuration of the kernel options in preparation for compilation of your customized kernel. (The directory name contains the version of your Linux kernel so you may need to modify the directory name if your Linux kernel version is different than 2.0.36 used in this example. You also need the "Tk" interpreter and the kernel source code installed. ) The alternatives to "make xconfig" are: "make config" (runs a scripts that asks you questions in the text mode) and "make menuconfig" (runs a text-based menu-driven configuration utility). Try: less /usr/doc/HOWTO/Kernel-HOWTO for more information.
After the configuration, you may choose to proceed with kernel compilation of the new kernel by issuing the following commands:
make dep
make zImage
The last command will take some time to complete (maybe 0.5 h, depending on your hardware). It produces the file "zImage", which is your new Linux kernel. Next:
make modules
make modules_install
Read: /usr/doc/HOWTO/Kernel-HOWTO for information on how to install the new kernel. You will probably also find it useful to read "man depmode". Configuration, compilation and installation of a new kernel is not difficult but it CAN lead to problems if you don't know what you are doing.
Compilation of a kernel is a good way to test your hardware, because it involves a massive amount of computing. If your hardware is "flaky", you will most likely receive the "signal 11" error (read the beatiful /usr/doc/FAQ/txt/GCC-SIG11-FAQ). See this for details on kernel upgrade.
depmod -a
(as root) Build the module dependency table for the kernel. This can, for example, be useful after installing and booting a new kernel. Use "modprobe -a" to load the modules.
ldconfig
(as root) Re-create the bindings and the cache for the loader of dynamic libraries ("ld"). You may want to run ldconfig after an installation of new dynamically linked libraries on your system. (It is also re-run every time you boot the computer, so if you reboot you don't have to run it manually.)
mknod /dev/fd0 b 2 0
(=make node, as root) Create a device file. This example shows how to create a device file associated with your first floppy drive and could be useful if you happened to accidentally erase it. The options are: b=block mode device (c=character mode device, p=FIFO device, u=unbuffered character mode device). The two integers specify the major and the minor device number.
fdformat /dev/fd0H1440
mkfs -c -t ext2
(=floppy disk format, two commands, as root) Perform a low-level formatting of a floppy in the first floppy drive (/dev/fd0), high density (1440 kB). Then make a Linux filesystem (-t ext2), checking/marking bad blocks (-c ). Making the files system is an equivalent to the high-level format.
badblocks /dev/fd01440 1440
(as root) Check a high-density floppy for bad blocks and display the results on the screen. The parameter "1440" specifies that 1440 blocks are to be checked. This command does not modify the floppy.
fsck -t ext2 /dev/hda2
(=file system check, as root) Check and repair a filesystem. The example uses the partition hda2, filesystem type ext2.
dd if=/dev/fd0H1440 of=floppy_image
dd if=floppy_image of=/dev/fd0H1440
(two commands, dd="data duplicator") Create an image of a floppy to the file called "floppy_image" in the current directory. Then copy floppy_image (file) to another floppy disk. Works like DOS "DISKCOPY".
Program installation
rpm -ivh filename.rpm(=RedhatPackageManager, install, verbose, hashes displayed to show progress, as root.) Install a content of RedHat rpm package(s) and print info on what happened. Keep reading if you prefer a GUI installation.
rpm -qpi filename.rpm
(=RedhatPackageManager, query, package, list.) Read the info on the content of a yet uninstalled package filename.rpm.
rpm -qpl filename.rpm
(=RedhatPackageManager, query, package, information.) List the files contained in a yet uninstalled package filename.rpm.
rpm -qf filename
(=RedhatPackageManager, query, file.) Find out the name of the *.rpm package to which the file filename (on your hardrive) belongs.
rpm -e packagename
(=RedhatPackageManager, erase=uninstall.) Uninstall a package pagckagename. Packagname is the same as the beginning of the *.rpm package file but without the dash and version number.
kpackage
gnorpm
glint
(in X terminal, as root if you want to be able to install packages) GUI fronts to the Red Hat Package Manager (rpm). "glint" comes with RH5.2, "gnorpm" with RH6.0, "kpackage" comes with RH6.1 or must be installed separately but is the best of the three. Use any of them to view which software packages are installed on your system and the what not-yet-installed packages are available on your RedHat CD, display the info about the packages, and install them if you want (installation must be done as root).
Accessing drives/partitions
mountSee here for details on mounting drives. Examples are shown in the next commands.
mount -t auto /dev/fd0 /mnt/floppy
(as root) Mount the floppy. The directory /mnt/floppy must exist, be empty and NOT be your current directory.
mount -t auto /dev/cdrom /mnt/cdrom
(as root) Mount the CD. You may need to create/modify the /dev/cdrom file depending where your CDROM is. The directory /mnt/cdrom must exist, be empty and NOT be your current directory.
mount /mnt/floppy
(as user or root) Mount a floppy as user. The file /etc/fstab must be set up to do this. The directory /mnt/floppy must not be your current directory.
mount /mnt/cdrom
(as user or root) Mount a CD as user. The file /etc/fstab must be set up to do this. The directory /mnt/cdrom must not be your current directory.
umount /mnt/floppy
Unmount the floppy. The directory /mnt/floppy must not be your (or anybody else's) current working directory. Depending on your setup, you might not be able to unmount a drive that you didn't mount.
7.6 Network administration tools
netconf(as root) A very good menu-driven setup of your network.
pingmachine_name
Check if you can contact another machine (give the machine's name or IP), press
route -n
Show the kernel routing table.
nslookup host_to_find
Query your default domain name server (DNS) for an Internet name (or IP number) host_to_find. This way you can check if your DNS works. You can also find out the name of the host of which you only know the IP number.
traceroute host_to_trace
Have a look how you messages trave to host_to_trace (which is either a host name or IP number).
ipfwadm -F -p m
(for RH5.2, seen next command for RH6.0) Set up the firewall IP forwarding policy to masquerading. (Not very secure but simple.) Purpose: all computers from your home network will appear to the outside world as one very busy machine and, for example, you will be allowed to browse the Internet from all computers at once.
echo 1 > /proc/sys/net/ipv4/ip_forward
ipfwadm-wrapper -F -p deny
ipfwadm-wrapper -F -a m -S xxx.xxx.xxx.0/24 -D 0.0.0.0/0
(three commands, RH6.0). Does the same as the previous command. Substitute the "x"s with digits of your class "C" IP address that you assigned to your home network. See here for more details. In RH6.1, masquarading seems broken to me--I think I will install Mandrake Linux:).
ifconfig
(as root) Display info on the network interfaces currently active (ethernet, ppp, etc). Your first ethernet should show up as eth0, second as eth1, etc, first ppp over modem as ppp0, second as ppp1, etc. The "lo" is the "loopback only" interface which should be always active. Use the options (see ifconfig --help) to configure the interfaces.
ifup interface_name
(/sbin/ifup to it run as a user) Startup a network interface. E.g.:
ifup eth0
ifup ppp0
Users can start up or shutdown the ppp interface only when the right permission was checked during the ppp setup (using netconf ). To start a ppp interface (dial-up connection), I normally use kppp available under kde menu "internet".
ifdown interface_name
(/sbin/ifdown to run it as a user). Shut down the network interface. E.g.: ifdown ppp0 Also, see the previous command.
netstat | more
Displays a lot (too much?) information on the status of your network.
Music-related commands
cdplay play 1Play the first track from a audio CD.
eject
Get a free coffee cup holder :))). (Eject the CD ROM tray).
play my_file.wav
Play a wave file.
mpg123 my_file.mp3
Play an mp3 file.
mpg123 -w my_file.wav my_file.mp3
Create a wave audio file from an mp3 audio file.
knapster
(in X terminal) Start the program to downolad mp3 files that other users of napster have displayed for downloading. Really cool!
cdparanoia -B "1-"
(CD ripper) Read the contents of an audio CD and save it into wavefiles in the current directories, one track per wavefile. The "1-"
means "from track 1 to the last". -B forces putting each track into a separate file.
playmidi my_file.mid
Play a midi file. playmidi -r my_file.mid will display text mode effects on the screen.
sox
(argument not given here) Convert from almost any audio file format to another (but not mp3s). See man sox.
Graphics-related commands
kghostview my_file.psDisplay a postscript file on screen. I can also use the older-looking ghostview or gv for the same end effect.
ps2pdf my_file.ps my_file.pdf
Make a pdf (Adobe portable document format) file from a postscript file.
gimp
(in X terminal) A humble looking but very powerful image processor. Takes some learning to use, but it is great for artists, there is almost nothing you can't do with gimp. Use your mouse right button to get local menus, and learn how to use layers. Save your file in the native gimp file format *.xcf (to preserve layers) and only then flatten it and save as png (or whatever). There is a large user manual /usr/
gphoto
(in X terminal) Powerful photo editor.
pnmtopng my_file.pnm > my_file.png
Convert the propriatory giff graphics into a raw, portable pnm file. Then convert the pnm into a png file, which is a newer and better standard for Internet pictures (better technically plus there is no danger of being sued by the owner of giff patents).
Monday, September 15, 2008
R project
You can install it in Linux Ubuntu with:
sudo apt-get install r-base
Then type R (in big case) and like in Python, you get a console for commands. Also you can write a program and save it in a file and call it for execution:
R -f myfile.r
a <- read.table("compofdistances.dat", header=T, sep="\t")
#this will read the data from a file, header is true (it has a header) and the separations are by tabs.
plot(a[,1],a[,2])
#this will plot the first column against the other. One is plotted on X axis and the other on Y axis as reference. In other words, if the first column is the vector (1,2,3) and the second column is the vector (4,5,6), then the points in the graph will be 1,4 ; 2,5 and 3,6.
b <- read.table("compofdistances.dat", header=T, sep="\t")
plot(a[,1],b[,2],col=c("red","blue"))
#This will plot the point alternately in red and blue.
#Another example, suppose we have the next file called triangle_areas.txt:
0 36267.2574608
1 12386.1343796
2 6417203.85229
3 6616673.58732
4 6417203.85229
5 6417203.85229
6 63352.669897
7 12386.1343796
8 188188.032427
9 6417203.85229
.
.
.
1920 39008.7753129
1921 12386.1343796
1922 156563.806249
1923 83012.3642354
1924 29033.6398076
1925 67316.811118
1926 36147.5333869
1927 6616673.58732
1928 14443.5575429
1929 12386.1343796
#Then in R we write the next command:
a<-read.table("triangle_areas.txt")
b<-a[a[,2]<10000,2]
#this is recursive, the second part inside the square brackets (the number 2) indicates that we are refering to the second column from the file. In the first part we are referring only to those less than 10000, and we put them in b.
plot(b)
#To plot the results
> length(b)
[1] 972
#To know the length of "b".
> b
[1] 36267.257 12386.134 12386.134 36540.916 19763.353 36267.257 19763.353
[8] 15872.262 30528.117 36540.916 2292.506 2292.506 14199.754 12386.134
[15] 12386.134 32088.702 36540.916 15378.449 36540.916 29033.640 1167.037
[22] 12386.134 15378.449 20265.898 1167.037 33405.568 36540.916 9910.127
[29] 15378.449 45617.156 1167.037 28488.625 1167.037 17056.617 12386.134
[36] 29033.640 32088.702 29033.640 32088.702 12365.535 19763.353 19763.353
[43] 20265.898 14443.558 12386.134 36540.916 28581.609 28488.625 19763.353
[50] 32088.702 12386.134 32088.702 1799.776 25689.556 1167.037 12386.134
[57] 36540.916 30528.117 1062.624 9021.118 25325.056 29033.640 19763.353
[64] 19763.353 19763.353 25689.556 15378.449 12386.134 19763.353 32088.702
[71] 36267.257 9910.127 15378.449 1062.624 36540.916 25689.556 1167.037
[78] 33217.250 12386.134 29033.640 32088.702 45417.858 8887.827 48636.615
[85] 29033.640 48636.615 9910.127 12386.134 32088.702 1167.037 1167.037
[92] 32088.702 12386.134 12386.134 36267.257 36540.916 36540.916 12386.134
[99] 19763.353 8887.827 32088.702 12386.134 36267.257 32088.702 36540.916
> a<-read.table("triangle_areas.txt", header<-F)
#Here, I guess we are saying that the header part is FALSE. In other words, that the file does not have a header.
Link to some examples.
http://www.harding.edu/fmccown/R/
In 4shared.
How to make a bootable MSDOS CD from a floppy image
http://www.bootdisk.com/
http://sharkysoft.com/
http://mandrivausers.org/
http://www.troubleshooters.
==============================
Archiving Floppy Disks Using Images
We all have a stack of floppies sitting around that none of us ever use, but which we can't bare to throw away because we know that as soon as we do, we will miss them. On top of that, we also know that the lifetime of a floppy is very short; even if you do have a place to store all your floppies, odds are good that eventually the bits on them will go bad anyway. This mini-tutorial offers a technique you can use to archive your floppies onto more durable media, such as your hard drive or a CD-ROM, in a manner that allows you to reconstruct any of the floppies at a later time.
Often, it is not enough just to back up the files on a floppy. Sometimes the exact arrangement of data blocks on the disk are important. When backing up a commercial floppy, for example, it is usually best if you can create a bit-for-bit copy of the original. The techniques illustrated in this document achieve this goal.
Floppy disk images
All of the data on your floppy, including the files, the directory tables, etc. can be represented in a single file called an "image." Images are useful because they encapsulate the entire structure of a disk without regard to what is actually on the disk. Thus, images can be used to represent disks of various formats.
Unfortunately, the techniques described in this document work only with 31/2 inch high density (1.44 Mb) disks. However, they can be adapted for other types of disks if you know the correct parameters. Some formats that might not work with the techniques described in this document include Macintosh and the special format Microsoft used to distribute copies of Windows 95. (If you figure out the correct parameters for these formats, let me know so that I can include them here.)
Reading imagesThere are various commercial utilities available for DOS and Windows that can read floppy disk images. Unfortunately, I have not been able to find any of them that are free. If you use Linux, however, the process is quite easy and no commercial software is required. Simply put your disk in the drive and execute the following command:
dd if=/dev/fd0 of=floppy.img count=1 bs=1440k
Of course, you can replace floppy.img with the file name that you want the extracted image to have.
When the command completes, you will have a single file on your hard drive representing the entire disk. This file, called an "image," can be used to reconstruct the floppy at any given time. From this point, you just need to keep the file on your hard drive, write it a CD-ROM or tape, or preserve it in any other way you feel appropriate. Note that you can fit more than 400 floppy images on a single CD_ROM. (That'll save a lot of space!) As long as you can keep the images safe, you can dispose of the original floppies, and reconstruct them later if it ever turns out you need them.
Writing images
Red Hat, Inc. has published a DOS utility you can use to write floppy disk images back to floppy disks. It's call rawrite.exe and is included on any Red Hat Linux CD-ROM. Since it is freely redistributable, I am happy to offer you a copy of the program and its documentation. It's really quite simple to use. Just run it and follow the prompts.
If you are running Linux, the command to restore an image to the floppy is:
dd if=floppy.img of=/dev/fd0 count=1 bs=1440k
where floppy.img is, of course, the name of your archived image file.
Acknowledgements
Thanks to Alen Peacock for teaching me most of the knowledge embodied in this tutorial.
==============================Executive Summary:
A big thank you goes out to LEAP member Mark Alexander for supplying much of the technical information in this document...If you're old enough to remember IT in the 1980's, you remember a time when floppies were reliable. They had to be. For most PC type computers, floppies were the preferred software distribution media. and the preferred backup media. Skip ahead 20 years, and floppies are almost never used for these purposes. My observation using floppies is that manufacturers of floppy media and drives no longer insist on high quality. Why bother -- the last use of floppies is boot media for computers.
My experience indicates you might need to try 5 or 6 floppies before you get a good boot floppy. This is a hardship, to say the least.
Meanwhile, CD media and drives have gotten better and better over the years. Wouldn't it be nice if you could burn that floppy image as a bootable CD, and then use the CD as installation media? Keep in mind that most computers made in the last 5 years can boot to CD.
This document describes how to burn a floppy image file onto a CD.
For this exercise we'll use /scratch/linuxinst/m91inst/
Mastering And Burning It the Easy way
Assuming the floppy image file to be turned into a bootable CD is /scratch/linuxinst/m91inst/mkisofs -pad -b floppy.img -R -o /tmp/cd.iso \Note the following:
/scratch/linuxinst/m91inst/images/floppy.img
Command parameter or part | Functionality |
-pad | Add padding to the end to make it readable on all CD players |
-b floppy.img | -b tells mkisofs which *floppy image* to use for booting. If the floppy image boots as a floppy, it will boot as a CD. Note that there is no path prepended to floppy.img. The floppy.img bootable image is assumed to be relative to the file being imagized, in this case /scratch/linuxinst/m91inst\ |
-R | Include Rock-Ridge extensions for readability everywhere |
-o /tmp/cd.iso | This defines the output file, an ISO9660 image ready for burning |
/scratch/linuxinst\ | This is the file to put on the CD. |
Your next step is to actually burn it. Use the following command:
cdrecord dev=0,3,0 speed=12 blank=fast -pad -v -eject /tmp/cd.iso
Command parameter or part | Functionality |
dev=0,3,0 | The CD burner device. If you don't know it, use the cdrecord -scanbus command to find out. |
-speed=12 | Set this to the fastest speed supported by your burner/media combination. |
-blank=fast | Use this ONLY if burning a rewriteable. This erases the current CD contents, but does it fast rather than thoroughly. |
-pad | Add padding to the end to make it readable on all CD players. Without this, the CD will error out when read on many Linux boxes |
-v | Verbose |
-eject | Eject when finished |
/tmp/cd.iso | The ISO image you're burning. In this case it's the ISO you just made with mkisofs. |
Remove the CD, and boot it on a machine known able to boot CD's. You should get a bootable version of whatever boot floppy image you used. The advantage to a boot CD is CD media are much more reliable, so you needn't go through several floppies finding just the right one to burn properly.
Mastering and Burning it the Complete Way
The easy CD boots and installs just like the floppy, but it does not contain the floppy's files in the root of the CD. To get all the files visible in the root, you need to create a temporary directory, copy all the floppy image files to it, copy the floppy image to it, and run mkisofs. The cdrecord step is the same as described in the Mastering and Burning it the Easy Way article:- As root, make sure there's a /mnt/test directory
- As root, mount -o loop,ro /scratch/linuxinst/m91inst/
images/floppy.img /mnt/test - The remainder of the steps are done as a regular user
- mkdir /tmp/floppycopy
- cp -Rp /mnt/test/* /tmp/floppycopy
- cp -p /scratch/linuxinst/m91inst/
images/floppy.img /tmp/floppycopy - mkisofs -pad -b floppy.img -R -o /tmp/cd.iso /tmp/floppycopy
- cdrecord dev=0,3,0 speed=12 blank=fast -pad -v -eject /tmp/cd.iso
NOTE As mentioned before, you must determine your device number based on cdrecord -scanbus, and your speed based on media and drive. |
How to make a bootable MSDOS USB key
*NOTE: A USB key will boot only if the BIOS in your computer explicity supports that feature.
http://www.bootdisk.com/
http://www.abxzone.com/forums/
http://www.weethet.nl/english/
http://www.laptopvideo2go.com/
http://www.hardforum.com/
Wednesday, June 25, 2008
Opening CSV or Text Files as Calc Spreadsheets--and Vice Versa
When I worked at Sun, there were a few things people always asked, that were hard to figure out.
- How do you print the same rows or columns on every page of a spreadsheet? (See this post. )
- How do you print handouts for a presentation? (See this post.)
- How do you get a blank paragraph line above a table that's at the top of a document? (You now simply have to press Return in the upper left cell of the table.)
Another very common question was:
How in the world do you open a perfectly good .txt or .csv file (comma-separated values) in a spreadsheet? Basically, you've got data in rows and columns, but separated by tabs or commas rather than columns in a spreadsheet, and you want it in a spreadsheet. Comma-delimted files are a common way to get data out of a spreadsheet or database and into another.
The trouble is, in OpenOffice.org, if you just choose File > Open, the .txt or .csv file opens in Writer. Not what you want.
Here's how to open it in a Calc spreadsheet.
Opening a .txt or .csv File in a Calc Spreadsheet
1. Start OpenOffice.org. You can be in Writer, Draw, Calc—it doesn't matter.
2. Choose File > Open. (Click the picture to see a larger version of it, if you want.)
3. In the File Type list, select Text CSV. It's about a third of the way down the list of types, or you can click in the file type list and press T four times.
4. The window should now look like this, so just click Open.
5. You'll get a window where you specify how the file was created: what separates the data into columns, etc. (Click the picture to see a larger version, if you want.)
6. Also in the same window, if you have date-format data or other formats you want to specify, you can do that column by column.
7. When you're done, just click OK. You'll see the data in a spreadsheet.
8. You'll want to save it as a spreadsheet at some point. Choose File > Save As and select the standard OpenSpreadsheet .ods format.
9. Click Save.
Saving a Calc Spreadsheets as a .txt or .csv File
1. Let's say it's the other way around—you've got a spreadsheet and you want it to be in a nice neutral .txt or .csv file. Be sure the file is open.
2. Choose File > Save As and select the same Text CSV format in the file format list. This time you can click T just once.
3. Click Save.
4. You'll probably see this message. Click Yes.
5. In the next window, specify the type of character you want to separate columns, commas or tabs or another character.
6. Click OK; you're done.
HowTo: Copy and Paste A Text File into Another Text File via Terminal
Yes, you read correct. This time around, we are going to paste data content of one text file into another text file and we are going to approach this issue using linux command via terminal. This one could be easily done inside X or GNOME, but let us assume we are going to do it from a linux system without X, say server or remote non-X linux box, something like that.
Let's start.
Let us view two example of text files namelyh textfile1.txt and textfile2.txt
# cat textfile1.txt
RedHat
Fedora
CentOS
# cat textfile2.txt
Enterprise Version
Core Version 9
Linux Distro
Now, let us merge or combine two text files using the linux paste command
# paste textfile1.txt textfile2.txt
result:
RedHat Enterprise Version
Fedora Core Version 9
CentOS Linux Distro
Making it permanent as file would be as easy as
# paste textfile1.txt textfile2.txt > output.txt
Did you noticed that the contents of textfile2.txt was merged with the data contents of textfile1.txt? Noticed also the fixed columnar width making the 2nd column word vertically aligned.
Merging two text file using paste could be very useful on specific scenarios of merging related data contents.
Here's another scenario.
# cat test1.txt
Citybank
Citybank
BPI Bank
Citybank
# cat test2.txt
New York, USA
San Francisco, USA
Manila, Philippines
London, UK
Again, using paste to merge contents of first file and second text file
# paste test1.txt test2.txt
result:
Citybank New York, USA
Citybank San Francisco, USA
BPI Bank Manila, Philippines
Citybank London, UK
If you want to insert a delimeter character between two columnar data or data field, that could be done using the same linux paste command like so
# paste -d", " test1.txt test2.txt
result:
Citybank,New York, USA
Citybank,San Francisco, USA
BPI Bank,Manila, Philippines
Citybank,London, UK
Neat and nice, isn't it? Hope you enjoy it, and oh, it was an old idea reminded to me by pinoyskull.
Merging two text files with a common field or column marker would be my next post, so watch out for it. And sorry for late updates, been very busy these past few weeks.
Related Posts:
Merging Linux Non-Text and Binary Files
Concatenating Multiple Linux Files
Simple Linux Text Line Formatter
Math the Beauty and Linux the Beast
Retrieve MySQL data via Bash Shell
===============================
To add text to the end of a file:
$ cat footnotes.txt >> file
If you're appending only a single line instead of multiple lines or an entire file, you can use echo
instead of cat
:
To append lines of text that are itemized beginning with 1, use cat
's -n
option; lines are preceded with the line number (offset with up to five space characters) and a tab character. Add the -b
option to suppress the numbering of blank lines:
This line is numbered
And so is this
Another numbered line Ctrl-D
$ cat file
1 This line is numbered
2 And so is this
3 Another numbered line
$
Wednesday, June 18, 2008
SUDO PASWORD IN UBUNTU
One way to gain root prompt is to launch a shell as root. Therefore, using sudo you can type:
:~$ sudo sh
Password:
sh-3.1#
And there you are, you have a root shell.
If you want to be able to login as root, you need to define a password for root:
:~$ sudo passwd
Password:
Enter new UNIX password:
Retype new UNIX password:
Now you can login as root with su.
Re-disabling your root account
If for some reason you have enabled your root account and wish to disable it again, open a terminal and issue the following command:
sudo passwd -l root
Monday, June 02, 2008
inadyn
Install the inadyn package using Synaptic Package manager, then:
The following will allow your Ubuntu Linux machine to be accessible anywhere that you are given an externally-accessible IP address. This includes most ISPs but excludes many office LANs.
First edit the file /etc/inadyn.conf:
gksudo gedit /etc/inadyn.conf
It should contain something like to the following:
--username myusername
--password mypassword
--update_period 60000
--alias myhost.dyndns.org
--background
Now test that it works by typing
sudo /usr/sbin/inadyn
Next, add inadyn to your 'crontab':
export EDITOR=gedit
sudo crontab -e
Edit the file to add the following additional line:
@reboot /usr/sbin/inadyn
Then save and exit the editor. Verify using
sudo crontab -l
When you reboot, you should see indyn listed when you type
ps -A | grep inadyn
You should be able to log in to your Dynamic DNS provider's website and verify that the DNS entry is being updated. Certainly this is possible with www.dyndns.org, in any case. Alternatively you can type your hostname into a service like [WWW] http://www.dnsstuff.com/.
===========//////
Through DynDns website can be generated the inadyn.conf file which is something like this:
# Basic configuration file for inadyn
#
# /etc/inadyn.conf
update_period_sec 600 # Check for a new IP every 600 seconds
username "mylogin"
password "mypassword"
dyndns_system dyndns@dyndns.org
alias test.homeip.net
Tuesday, April 29, 2008
How to know your Ubuntu release version
2. Type cat /etc/issue.net
OR
lsb_release -a
OR
go to your desktop, system->about ubuntu->version and release numbers
Friday, April 11, 2008
Saturday, March 29, 2008
Saturday, March 08, 2008
rc.local
In this example it runs inadyn to update the dyndns.org service.
#!/bin/sh -e
#
# /etc/rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
inadyn
exit 0
Thursday, March 06, 2008
Ubuntu (Gutsy): DynDNS Client Setup
Hello again, this time we’re going to setup a DynDNS client so your computer/server can be reached from anywhere.
Step 1
First, you need to create an account with DynDNS to do so follow this howto: https://www.dyndns.com/services/dns/dyndns/howto.html.
Step 2
First we’ll install ssh and ssh-socket so we can send our DynDNS user and password encrypted instead clear text:
$ sudo apt-get install ssh libio-socket-ssl-perl
Step 3
Install ddclient:
$ sudo apt-get install ddclient
Step 4
The installation will prompt you some questions. For the first one it ask for your dynamic DNS provider, select www.dyndns.com:
Then, put your fully qualified domain name(s):
Now, your DynDNS requistered username and password:
And finally, type “web” as the DynDNS interface to use:
Ok, so long we’ve finished installing ddclient but there’s still more work to do in order to get it working properly.
Step 5
We, need to change the ddclient configuration file (/etc/ddclient.conf
) in order to use ssh to send the username and password, and to properly check the IP adrress. From the command line open ddclient configuration:
$ sudo vim /etc/ddclient.conf
In the generated configuration file you’ll probably see something like the following (The parts in italics will be different, the bold parts are going to change so special attention on this):
# Configuration file for ddclient generated by debconf
#
# /etc/ddclient.conf
pid=/var/run/ddclient.pid
protocol=dyndns2
use=if, if=web
server=members.dyndns.org
login=your-dyndns-username
password=‘your-dyndns-password’
your-host-name.homelinux.net
Step 6
We need to change the configuration so ddclient get our public IP address properly, and to send our username and password over ssh.
DynDNS has a web interface to get your public IP address, this is equivalent to manually invoking http://checkip.dyndns.com/. But we need to properly configure this interface, so change the line use=if, if=web
for the following:
use=web, web=checkip.dyndns.com/, web-skip='IP Address'
Second, add to your configuration file just below the initial comments the following:
ssl=yes
daemon=300
The above two lines tells ddclient to use ssl for its connection and to update your public IP address every 5 minutes (specified in secconds).
Step 7
Now, we must make sure that ddclient is set to run as a deamon. Edit /etc/default/ddclient
:
$ sudo vim /etc/default/ddclient
And make sure that:
# Configuration for ddclient scripts
# generated from debconf on Tue Jan 29 20:23:32 CST 2008
#
# /etc/default/ddclient
# Set to “true” if ddclient should be run every time a
# new ppp connection is established. This might be useful,
# if you are using dial-on-demand
run_ipup=”false”
# Set to “true” if ddclient should run in daemon mode
run_daemon=”true”
# Set the time interval between the updates of the dynamic DNS name in seconds.
# This option only takes effect if the ddclient runs in daemon mode.
daemon_interval=”300″
Step 8
Finally, restart your ddclient and if no error is printed you’re good to go:
sudo /etc/init.d/ddclient restart
Port Forwarding
In order to deliver services on the net, you must open the corresponding ports for the services that your computer/server will provide, this is called Port Forwarding. Unfortunately this howto does not cover that topic. To do so you can visit http://www.portforward.com/routers.htm, where you can read how to port forwarding for your specific model of modem/router.
Happy hacking!