Linux
Last edited November 21, 2008
More by {joey} »
#!/bin/sh rm -fr CD.WD mkdir CD.WD cd CD.WD ln -s ../isolinux ...
ping.windowsdream.com/ping/old/2.01.14/Do.ISO.CD
PING-2.01.iso . cd .. rm -fr CD.WD. md5sum PING-2.01.iso > PING-2.01.iso.md5. md5sum PING-2.01-WithAddons.iso > PING-2.01-WithAddons.iso.md5.

nohup Command

Purpose

Runs a command without hangups.

Syntax

nohup Command Arg ... ] [ ]

Description

The nohup command runs the command specified by the Command parameter and any related Arg parameters, ignoring all hangup (SIGHUP) signals. Use the nohup command to run programs in the background after logging off. To run a nohup command in the background, add an & (ampersand) to the end of the command.

Whether or not the nohup command output is redirected to a terminal, the output is appended to the nohup.out file in the current directory. If the nohup.out file is not writable in the current directory, the output is redirected to the $HOME/nohup.out file. If neither file can be created nor opened for appending, the command specified by the Command parameter is not invoked. If the standard error is a terminal, all output written by the named command to its standard error is redirected to the same file descriptor as the standard output.

Exit Status

This command returns the following exit values:

126 The command specified by the Command parameter was found but could not be invoked.
127 An error occurred in the nohup command or the command specified by the Command parameter could not be found.

Otherwise, the exit status of the nohup command is that of the command specified by the Command parameter.

Examples

  1. To run a command in the background after you log off, enter:
    $ nohup find / -print &
    After you enter this command, the following is displayed:
    670
    $ Sending output to nohup.out
    The process ID number changes to that of the background process started by & (ampersand). The message Sending output to nohup.out informs you that the output from the find / -print command is in the nohup.out file. You can log off after you see these messages, even if the find command is still running.
  2. To run a command in the background and redirect the standard output to a different file, enter:
    $ nohup find / -print >filenames &
    This example runs the find / -print command and stores its output in a file named filenames. Now only the process ID and prompt are displayed:
    677
    $
    Wait before logging off because the nohup command takes a moment to start the command specified by the Command parameter. If you log off too quickly, the command specified by the Command parameter may not run at all. Once the command specified by the Command parameter starts, logging off does not affect it.
  3. To run more than one command, use a shell procedure. For example, if you write the shell procedure:
    neqn math1 | nroff > fmath1
    and name it the nnfmath1 file, you can run the nohup command for all of the commands in the nnfmath1 file with the command:
    nohup sh nnfmath1
  4. If you assign execute permission to the nnfmath1 file, you get the same results by issuing the command:
    nohup nnfmath1
  5. To run the nnfmath1 file in the background, enter:
    nohup nnfmath1 &
  6. To run the nnfmath1 file in the Korn shell, enter:
    nohup ksh nnfmath1
General

The Ultimate Linux Reference Guide for Newbies
blog.lxpages.com/ultimate_linux.html
ls List files/directories in a directory, comparable to dir in windows/dos.
ls -la Shows all files (including ones that start with a period), directories, and details attributes for each file.
cd Change directory (e.g cd /usr/local/bin)
cd ~ Go to your home directory
cd - Go to the last directory you were in
cd .. Go up a directory
cat Print file contents to the screen
cat filename.txt Print the contents of filename.txt to your screen
tail Similar to cat, but only reads the end of the file
tail /var/log/messages See the last 20 (by default) lines of /var/log/messages
tail -f /var/log/messages Watch the file continuously, while it's being updated
tail -200 /var/log/messages Print the last 200 lines of the file to the screen
head Similar to tail, but only reads the top of the file
head /var/log/messages See the first 20 (by default) lines of /var/log/messages
head -200 /var/log/messages Print the first 200 lines of the file to the screen
more Llike cat, but opens the file one screen at a time rather than all at once
more /etc/userdomains Browse through the userdomains file. hit Spaceto go to the next page, q to quit
less Page through files
od View binary files and data
xxd Also view binary files and data
gv View Postscript/PDF files
xdvi View TeX DVI files
nl Number lines
touch Create an empty file
touch /home/burst/public_html/404.html Create an empty file called 404.html in the directory /home/burst/public_html/
file Attempts to guess what type of file a file is by looking at it's content.
file * Prints out a list of all files/directories in a directory
cp Copy a file
cp filename filename.bak Copies filename to filename.bak
cp -a /etc/* /root/etc/ Copies all files, retaining permissions form one directory to another.
cp -av * ../newdirectory Copies all files and directories recurrsively in the current directory INTO newdirectory
mv Move a file command
mv oldfilename newfilename Move a file or directory from oldfilename to newfilename
rm delete a file
rm filename.txt deletes filename.txt, will more than likely ask if you really want to delete it
rm -f filename.txt deletes filename.txt, will not ask for confirmation before deleting.
rm -rf tmp/ recursively deletes the directory tmp, and all files in it, including subdirectories.
chmod

changes file access permissions. The set of 3 go in this order from left to right:
USER - GROUP - EVERONE

0 = --- No permission
1 = --X Execute only
2 = -W- Write only
3 = -WX Write and execute
4 = R-- Read only
5 = R-X Read and execute
6 = RW- Read and write
7 = RWX Read, write and execute

chmod 000 No one can access
chmod 644 Usually for HTML pages
chmod 755 Usually for CGI scripts
chown Changes file ownership permissions
The set of 2 go in this order from left to right:
USER - GROUP
chown root myfile.txt Changes the owner of the file to root
chown root.root myfile.txt Changes the owner and group of the file to root
stat Display file attributes
grep Llooks for patterns in files
grep root /etc/passwd Shows all matches of root in /etc/passwd
grep -v root /etc/passwd Shows all lines that do not match root
ln Create's "links" between files and directories
ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf Now you can edit /etc/httpd.conf rather than the original. changes will affect the orginal, however you can delete the link and it will not delete the original.
wc Word count
wc -l filename.txt Tells how many lines are in filename.txt
find Utility to find files and directories on your server.
find / -name "filename" Find the file called "filename" on your filesystem starting the search from the root directory "/".
locate filename Find the file name and path of which contains the string "filename". Run 'updatedb' to build index.
EDITORS Most popular editors available on UNIX platforms.
pico Friendly, easy to use file editor
pico /home/burst/public_html/index.html Edit the index page for the user's website.
vi Popular editor, tons of features, harder to use at first than pico
vi filename.txt

Edit filename.txt. All commands in vi are preceded by pressing the escape key. Each time a different command is to be entered, the escape key needs to be used. Except where indicated, vi is case sensitive. Fore more commands go to: http://www.intellink.net/vi-qref.htm

H --- Upper left corner (home)
M --- Middle line
L --- Lower left corner
h --- Back a character
j --- Down a line
k --- Up a line
^ --- Beginning of line
$ --- End of line
l --- Forward a character
w --- Forward one word
b --- Back one word
fc --- Find c
; --- Repeat find (find next c)

:q! --- This force quits the file without saving and exits vi
:w --- This writes the file to disk, saves it
:wq --- This saves the file to disk and exists vi
:LINENUMBER : EG :25 --- Takes you to line 25 within the file
:$ --- Takes you to the last line of the file
:0 --- Takes you to the first line of the file

emacs

Another popular editor. For more commands go to http://www.hsrl.rutgers.edu/ug/emacs_qref.html

C-\ t --- Tutorial suggested for new emacs users.
C-x C-c exit emacs

emacs filename.txt

Edit filename.txt. While you're in emacs, use the following quickies to get around:

C-x C-f --- read a file into emacs
C-x C-s --- save a file back to disk
C-x i --- insert contents of another file into this buffer
C-x C-v --- replace this file with the contents of file you want
C-x C-w --- write buffer to specified file

C-f --- move forward one character
C-b --- move backward one character
C-n --- move to next line
C-p --- move to previous line
C-a --- move to beginning of line
C-e --- move to end of line
M-f --- move forward one word
M-b --- move backword one word
C-v --- move forward one screen
M-v --- move backward one screen
M-< --- go to beginning of file
M-> --- go to end of file

 
 
NETWORK Some of the basic networking utilities.
w Shows who is currently logged in and where they are logged in from.
who This also shows who is on the server in an shell.
netstat Shows all current network connections.
netstat -an Shows all connections to the server, the source and destination ips and ports.
netstat -rn Shows routing table for all ips bound to the server.
netstat -an |grep :80 |wc -l Show how many active connections there are to apache (httpd runs on port 80)
top

Shows live system processes in a formatted table, memory information, uptime and other useful info.

While in top, Shift + M to sort by memory usage or Shift + P to sort by CPU usage

top -u root Show processes running by user root only.
route -n Shows routing table for all ips bound to the server.
nslookup yahoo.com Query your default domain name server (DNS) for an Internet name (or IP number) host_to_find.
traceroute yahoo.com Have a look how you messages travel to yahoo.com
ifconfig Display info on the network interfaces.
ifconfig -a Display into on all network interfaces on server, active or inactive..
ping Sends test packets to a specified server to check if it is responding properly
tcpdump Print all the network traffic going through the network.
arp Command mostly used for checking existing Ethernet connectivity and IP address
SYSTEM TOOLS Many of the basic system utilities used to get things done.
ps ps is short for process status, which is similar to the top command. It's used to show currently running processes and their PID.
A process ID is a unique number that identifies a process, with that you can kill or terminate a running program on your server (see kill command).
ps U username Shows processes for a certain user
ps aux Shows all system processes
ps aux --forest Shows all system processes like the above but organizes in a hierarchy that's very useful!
kill terminate a system process
kill -9 PID Immediately kill process ID
killall program_name Kill program(s) by name. For example to kill instances of httpd, do 'killall httpd'
du Shows disk usage.
du -sh Shows a summary of total disk space used in the current directory, including subdirectories.
du / -bh | more Print detailed disk usage for each subdirectory starting at the "/".
last Shows who logged in and when
last -20 Shows only the last 20 logins
last -20 -a Shows last 20 logins, with the hostname in the last field
pwd Print working directory, i.e., display the name of my current directory on the screen.
hostname Print the name of the local host. Use netconf (as root) to change the name of the machine.
whoami Print my login name.
date Print or change the operating system date and time
time Determine the amount of time that it takes for a process to complete + other info.
uptime Show the number days server has been up including system load averages.
uname -a Displays info on about your server such as kernel version.
free Memory info (in kilobytes).
lsmod Show the kernel modules currently loaded. Run as root.
dmesg | less Print kernel messages.
man topic Display the contents of the system manual pages (help) on the topic. Do 'man netstat' to find all details of netstat command including options and examples.
reboot / halt Halt or reboot the machine.
mount Mount local drive or remote file system.
mount -t auto /dev/fd0 /mnt/floppy Mount the floppy. The directory /mnt/floppy must exist.
mount -t auto /dev/cdrom /mnt/cdrom Mount the CD. The directory /mnt/cdrom must exist.
sudo The super-user do command that allows you to run specific commands that require root access.
fsck Check a disk for errors
COMPRESSION UTILITIES There are many other compression utilities but these are the default and most widely utilized.
tar Creating and Extracting .tar.gz and .tar files
tar -zxvf file.tar.gz Extracts the file
tar -xvf file.tar Extracts the file
tar -cf archive.tar contents/ Takes everything from contents/ and puts it into archive.tar
gzip -d filename.gz gzip -d filename.gz
zip Compress files into.zip
unzip file.zip Extracting .zip files shell command
compress Compress files. compress filename
uncompress Uncompress compressed files. uncompress filename.Z
bzip2 Compress files in bzip2 format
THE (DOT) FILES The good old dot files. Let's clear up some confusion here by defining each.
.bash_login Treated by bash like .bash_profileif that doesn't exist.
.bash_logout Sourced by bash login shells at exit.
.bash_profile Sourced by bash login shells after /etc/profile
.bash_history The list of commands executed previously.
.profile Treated by bash like ~/.bash_profile if that and .bash_login don't exist.
.vimrc Default "Vim" configuration file.
.emacs Read by emacs at startup
CONFIGURATION FILES Listing everything is beyond the scope of this article.
/etc This directory contains most of the basic Linux system-configuration Files.
/etc/init.d Contains the permanent copies of System V–style run-level scripts. These scripts are often linked to files in the /etc/rc?.d directories to have each service associated with a script started or stopped for the particular run level. The ? is replaced by the run-level number (0 through 6). (Slackware puts its run-level scripts in the /etc/rc.d directory.)
/etc/cron* Directories in this set contain files that define how the crond utility runs applications on a daily (cron.daily), hourly (cron.hourly), monthly (cron.monthly), or weekly (cron.weekly) schedule.
/etc/cups Contains files used to configure the CUPS printing service.
/etc/default Contains files that set default values for various utilities. For example, the file for the useradd command defines the default group number, home directory, password expiration date, shell, and skeleton directory
/etc/skel Any files contained in this directory are automatically copied to a user’s home directory when that user is added to the system.
/etc/mail Contains files used to configure your sendmail mail service.
/etc/security Contains files that set a variety of default security conditions for your computer.
/etc/sysconfig Contains important system configuration files that are created and maintained by various services (including iptables, samba, and most networking services).
/etc/passwd Holds some user account info including passwords (when not "shadowed").
/etc/shadow Contains the encrypted password information for users' accounts and optionally the password aging information.
/etc/xinetd.d Contains a set of files, each of which defines a network service that the xinetd daemon listens for on a particular port.
/etc/syslogd.conf The configuration file for the syslogd daemon. syslogd is the daemon that takes care of logging (writing to disk) messages coming from other programs to the system.
/var Contains variable data like system logging files, mail and printer spool directories, and transient and temporary files.
/var/log Log files from the system and various programs/services, especially login (/var/log/wtmp, which logs all logins and logouts into the system) and syslog (/var/log/messages, where all kernel and system program message are usually stored).
/var/log/messages System logs. The first place you should look at if your system is in trouble.
/var/log/utmp Active user sessions. This is a data file and as such it can not be viewed normally.
/var/log/wtmp Log of all users who have logged into and out of the system. The last command can be used to access a human readable form of this file.
Apache Shell Commands Some of the basic and helpful apache commands.
httpd -v Outputs the build date and version of the Apache server.
httpd -l Lists compiled in Apache modules
httpd status Only works if mod_status is enabled and shows a page of active connections
service httpd restart Restarted Apache web server
MySQL Shell Commands Some of the basic and helpful MySQL commands.
mysqladmin processlist Shows active mysql connections and queries
mysqladmin processlist |wc -l Show how many current open connections there are to mysql
mysqladmin drop database Drops/deletes the selected database
mysqladmin create database Creates a mysql database
mysql -u username -p password databasename < data.sql Restores a MySQL database from data.sql
mysqldump -u username -p password database > data.sql Backup MySQL database to data.sql
echo "show databases" | mysql -u root -p password|grep -v Database Show all databases in MySQL server.
mysqldump -u root -p password database > /tmp/database.exp Dump database including all data and structure into /tmp/database.exp
Tora with Oracle Support

1. Install Oracle Instant Client
You can get it from the Oracle Site
Get the RPM package and then convert it to debian package using alien.

# dpkg -i oracle-instantclient-basic_10.2.0.1-2_i386.deb
# dpkg -i oracle-instantclient-devel_10.2.0.1-2_i386.deb
# dpkg -i oracle-instantclient-sqlplus_10.2.0.1-2_i386.deb

Three steps above will instal OIC on /usr/lib/oracle
2. Create file named tnsnames.ora on /usr/lib/oracle and fill with lines like below :

CONSTR =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.23.154.8)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = servtest)
)
)

3. Add line below to /etc/ld.so.conf :
/usr/lib/oracle/10.2.0.1/client/lib
Tell ld to reload its cache with :

# ldconfig

4. Add lines below to /etc/profile :

LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.1/client/lib:$LD_LIBRARY_PATH
TNS_ADMIN=/usr/lib/oracle
export LD_LIBRARY_PATH TNS_ADMIN

5. Install Tora (tricky step in order to get all dependencies needed by tora )

# apt-get install tora

6. Get Tora source

# cd /usr/src
# apt-get source tora

7. Prepare rebuilding tora
Install several packages needed for rebuilding :

# apt-get install g++ gcc autoconf automake flex zlib1g-dev docbook-xsl
# apt-get install libqt3-mt-dev libqt3-compat-headers
# cd tora-1.3.18/

Edit file debian/rules. Find line like below :

./configure –prefix=/usr –without-oracle –without-rpath –disable-new-check –with-kde –enable-libsuffix=

Replace with line like below :

./configure –prefix=/usr –with-instant-client –without-rpath –disable-new-check –without-kde –enable-libsuffix=

8. Rebuild Tora

# debian/rules binary

or even easier

# sudo checkinstall

be sure to change the version number higher so that apt doesn't bug you to update the package.

9. If nothing wrong you will get the deb on /usr/src. Next, you can install it :

# cd ..

Remove Tora first :

# apt-get remove tora

Install a new one :

# dpkg -i tora_1.3.18-2_i386.deb

10. Test the connection with sqlplus. If you use console then you must start a new one or relogin.

# sqlplus user/userpass@CONSTR

(BILLPM according to example lines of tnsnames.ora above)

SQL*Plus: Release 10.2.0.1.0 - Production on Wed Dec 7 19:58:12 2005

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
With the Partitioning and Real Application Clusters options
JServer Release 9.2.0.3.0 - Production

SQL>

df

 df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda3              31G  6.9G   23G  24% /
varrun                506M  172K  506M   1% /var/run
varlock               506M  4.0K  506M   1% /var/lock
procbususb             10M  128K  9.9M   2% /proc/bus/usb
udev                   10M  128K  9.9M   2% /dev
devshm                506M     0  506M   0% /dev/shm
lrm                   506M   18M  489M   4% /lib/modules/2.6.17-10-386/volatile
/dev/hda1              23G   14G  9.4G  59% /media/windows
/dev/hda2              20G  2.1G   18G  11% /media/shared
/dev/hdb               16M   16M     0 100% /media/cdrom0
VIM

Cursor movement

  • h - move left
  • j - move down
  • k - move up
  • l - move right
  • w - jump by start of words (punctuation considered words)
  • W - jump by words (spaces separate words)
  • e - jump to end of words (punctuation considered words)
  • E - jump to end of words (no punctuation)
  • b - jump backward by words (punctuation considered words)
  • B - jump backward by words (no punctuation)
  • 0 - (zero) start of line
  • ^ - first non-blank character of line
  • $ - end of line
  • G - Go To command (prefix with number - 5G goes to line 5)

Note: Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines.

Insert Mode - Inserting/Appending text

  • i - start insert mode at cursor
  • I - insert at the beginning of the line
  • a - append after the cursor
  • A - append at the end of the line
  • o - open (append) blank line below current line (no need to press return)
  • O - open blank line above current line
  • ea - append at end of word
  • Esc - exit insert mode

Editing

  • r - replace a single character (does not use insert mode)
  • J - join line below to the current one
  • cc - change (replace) an entire line
  • cw - change (replace) to the end of word
  • c$ - change (replace) to the end of line
  • s - delete character at cursor and subsitute text
  • S - delete line at cursor and substitute text (same as cc)
  • xp - transpose two letters (delete and paste, technically)
  • u - undo
  • . - repeat last command

Marking text (visual mode)

  • v - start visual mode, mark lines, then do command (such as y-yank)
  • V - start Linewise visual mode
  • o - move to other end of marked area
  • Ctrl+v - start visual block mode
  • O - move to Other corner of block
  • aw - mark a word
  • ab - a () block (with braces)
  • aB - a {} block (with brackets)
  • ib - inner () block
  • iB - inner {} block
  • Esc - exit visual mode

Visual commands

  • > - shift right
  • < - shift left
  • y - yank (copy) marked text
  • d - delete marked text
  • ~ - switch case

Cut and Paste

  • yy - yank (copy) a line
  • 2yy - yank 2 lines
  • yw - yank word
  • y$ - yank to end of line
  • p - put (paste) the clipboard after cursor
  • P - put (paste) before cursor
  • dd - delete (cut) a line
  • dw - delete (cut) the current word
  • x - delete (cut) current character

Exiting

  • :w - write (save) the file, but don't exit
  • :wq - write (save) and quit
  • :q - quit (fails if anything has changed)
  • :q! - quit and throw away changes

Search/Replace

  • /pattern - search for pattern
  • ?pattern - search backward for pattern
  • n - repeat search in same direction
  • N - repeat search in opposite direction
  • :%s/old/new/g - replace all old with new throughout file
  • :%s/old/new/gc - replace all old with new throughout file with confirmations

Working with multiple files

  • :e filename - Edit a file in a new buffer
  • :bnext (or :bn) - go to next buffer
  • :bprev (of :bp) - go to previous buffer
  • :bd - delete a buffer (close a file)
  • :sp filename - Open a file in a new buffer and split window
  • ctrl+ws - Split windows
  • ctrl+ww - switch between windows
  • ctrl+wq - Quit a window
  • ctrl+wv - Split windows vertically


    from: http://worldtimzone.com/res/vi.html 
Bash

Showing a decent prompt in bash:

 PS1="[\u@\h:\w]\$ "
Sed

sed 's_0*_27_' rawData.csv > raw.csv

sed 's_0.*_27&_' rawData.csv > raw.csv

http://student.northpark.edu/pemente/sed/sed1line.txt
 
Replace all occurancces of "catch" with "send" in a file:

sed 's/catch/send/g' FILE > TMPFILE && mv TMPFILE FILE
search and replace » Linux by Examples
linux.byexamples.com/archives/129/search-and-repla...

search and replace

This is a very common needs, to search a keyword and replace it with another. Give you a simple example, when I want to perform a ubuntu distribution upgrade from dapper to edgy, I need to edit the file /etc/apt/sources.list.

To do that i can either uses vim, or simply uses sed.

The vim way.

sudo vim /etc/apt/source.list

When in vim, you can do this

:%s/dapper/edgy/g

%s ask vim to search for every line, and replace dapper to edgy. By default, it will only replace the first “dapper” it found in a line, the /g will indicate it replace all “dapper” in a line.

The sed way.

sudo sed -e 's/dapper/edgy/g' -i /etc/apt/sources.list

-e is the script function, it performs search and replace like vi, and -i is the edit the file in place.

The content on this page is provided by a Google Notebook user, and Google assumes no responsibility for this content.