By default, ‘crontab -e’ uses vi without syntax highlights or nano.
to make it use vim, execute the following command:
> export EDITOR=/usr/bin/vim
By default, ‘crontab -e’ uses vi without syntax highlights or nano.
to make it use vim, execute the following command:
> export EDITOR=/usr/bin/vim
When you write a shell scripts you need to create filename with date in it. For example instead of log file name “bauson.log”, you can create a filename called “jan-02-06-bauson.log”.
The date in file will make it easy to find out all logs or reports. You can display the current date and time in the given FORMAT using date command. If you just type date command it will display in standard FORMAT:
$ date
Output:
Mon Nov 9 10:54:57 PHT 2009
To display date in MONTH-DAY-YEAR format you need to use date command as follows:
$ date +"%b-%d-%y"
Nov-09-09
As you can see I have used FORMAT as follows
date +”FORMAT”
Where, FORMAT can be any one of the following:
First obtained date:
$ NOW=$(date +"%b-%d-%y")
Create a file with date in filename:
$ LOGFILE="$NOW-bauson.log"
Display Filename
$ echo $LOGFILE
Usage:
10 7 * * * NOW=$(date +"%b-%d-%y"); LOGFILE="$NOW-bauson.log"; php my.php >log/$LOGFILE
To install yum in fedora just do these commands
1. Change directory
$ cd ~
2. Create directory called ‘yum’
$ mkdir yum
3. go into the yum directory you just created:
$ cd yum
4. download yum:
$ wget http://linux.duke.edu/projects/yum/download/2.0/yum-2.0.7.tar.gz
5. untar the file you just downloaded it:
$ tar -xvzf yum-2.0.7.tar.gz
6. go to the yum directory:
$ cd yum-2.0.7
7. run the configuration file:
$ ./configure
8. make the configuration:
$ make
9. Make install
$ make install
10. Now, its time to update your repository
$ yum update
I found mysql tuning is a pain. This script is a good tool to adjust your mysql variables. It evaluates the following variables:
slow query count
long_query_time
query_cache_size
% query cache actually used
max_connections
thread_cache
key_buffer_size
ratio of sort_merge operations to sorts (sort_buffer_size)
number of full joins
ratio of disk tmp tables vrs in memory tmp tables (tmp_table_size)
table_cache
ratio of table locks immediate to table locks waited
ratio of table scans (read_buffer_size)
To use the script add your user name and password to a [client] group in your ~/.my.cnf file
1. Tab
The most handy shortcut and time saver for the linux command line. This actually makes navigating directories faster in the CLI than the traditional GUI browser. Simply start typing the command, filename, or directory and hit tab. Bash will automatically complete what you are typing. It even works at the lilo prompt and in some X applications.
2. Ctrl + c
Stop that program dead in its tracks. This is the command line version of end task.
3. Ctrl + z
Send the current process to background. This is useful if you have a program running, and you need the terminal for awhile but don’t want to exit the program completely.
Type the command fg to get the process back.
4. Ctrl + d
Log out from the current terminal. If you use this in an X terminal emulator such as xterm it will usually close it after logging out.
5. Ctrl + u
Erase the current line. I use this one all the time when I type the wrong command in.
6. Ctrl + Alt + F1, (F1-F6)
Switch to the first virtual terminal. In Linux, you can have several virtual terminals at the same time. The default is 6. (Ctrl + Alt + F7 to get back to X)
7. Ctrl + l (lowercase L)
Clear the terminal.
8. Ctrl + Alt + Backspace
Kill the X server. Use this if X crashes and you can’t exit it normally. If you’ve configured GDM to start automatically at bootup, this restarts the server and throws you back to the graphical login screen.
9. Ctrl + a
Move the cursor to the beginning of the current line. Usefull for those times you navigated all the way through 20 directories and forgot to add ‘cp’ to the beginning. Use this instead of the arrow keys.
10. Ctrl + e
Last but not least get that cursor back to the end of the line.
This is a basic technique to download and split the file into chunks. I am using this to parse huge XML feeds.
<?php
system('wget http://www.bauson.com/PropertyOnlyPPL.xml',$output);
system('split PropertyOnlyPPL.xml -db 15m');
?>
mkdir – make directories
Usage
mkdir [OPTION] DIRECTORY
Options
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, mode=MODE set permission mode (as in chmod), not rwxrwxrwx – umask
-p, parents no error if existing, make parent directories as needed
-v, verbose print a message for each created directory
-help display this help and exit
-version output version information and exit
cd – change directories
Use cd to change directories. Type cd followed by the name of a directory to access that directory.Keep in mind that you are always in a directory and can navigate to directories hierarchically above or below.
mv- change the name of a directory
Type mv followed by the current name of a directory and the new name of the directory.
Ex: mv testdir newnamedir
pwd – print working directory
will show you the full path to the directory you are currently in. This is very handy to use, especially when performing some of the other commands on this page
rmdir – Remove an existing directory
rm -r
Removes directories and files within the directories recursively.
chown – change file owner and group
Usage
chown [OPTION] OWNER[:[GROUP]] FILE
chown [OPTION] :GROUP FILE
chown [OPTION] –reference=RFILE FILE
Options
Change the owner and/or group of each FILE to OWNER and/or GROUP. With –reference, change the owner and group of each FILE to those of RFILE.
-c, changes like verbose but report only when a change is made
-dereference affect the referent of each symbolic link, rather than the symbolic link itself
-h, no-dereference affect each symbolic link instead of any referenced file (useful only on systems that can change the ownership of a symlink)
-from=CURRENT_OWNER:CURRENT_GROUP
change the owner and/or group of each file only if its current owner and/or group match those specified here. Either may be omitted, in which case a match is not required for the omitted attribute.
-no-preserve-root do not treat `/’ specially (the default)
-preserve-root fail to operate recursively on `/’
-f, -silent, -quiet suppress most error messages
-reference=RFILE use RFILE’s owner and group rather than the specifying OWNER:GROUP values
-R, -recursive operate on files and directories recursively
-v, -verbose output a diagnostic for every file processed
The following options modify how a hierarchy is traversed when the -R option is also specified. If more than one is specified, only the final one takes effect.
-H if a command line argument is a symbolic link to a directory, traverse it
-L traverse every symbolic link to a directory encountered
-P do not traverse any symbolic links (default)
chmod – change file access permissions
Usage
chmod [-r] permissions filenames
r Change the permission on files that are in the subdirectories of the directory that you are currently in. permission Specifies the rights that are being granted. Below is the different rights that you can grant in an alpha numeric format.filenames File or directory that you are associating the rights with Permissions
u – User who owns the file.
g – Group that owns the file.
o – Other.
a – All.
r – Read the file.
w – Write or edit the file.
x – Execute or run the file as a program.
Numeric Permissions:
CHMOD can also to attributed by using Numeric Permissions:
400 read by owner
040 read by group
004 read by anybody (other)
200 write by owner
020 write by group
002 write by anybody
100 execute by owner
010 execute by group
001 execute by anybody
ls – Short listing of directory contents
-a list hidden files
-d list the name of the current directory
-F show directories with a trailing ‘/’
executable files with a trailing ‘*’
-g show group ownership of file in long listing
-i print the inode number of each file
-l long listing giving details about files and directories
-R list all subdirectories encountered
-t sort by time modified instead of name
cp – Copy files
cp myfile yourfile
Copy the files “myfile” to the file “yourfile” in the current working directory. This command will create the file “yourfile” if it doesn’t exist. It will normally overwrite it without warning if it exists.
cp -i myfile yourfile
With the “-i” option, if the file “yourfile” exists, you will be prompted before it is overwritten.
cp -i /data/myfile
Copy the file “/data/myfile” to the current working directory and name it “myfile”. Prompt before overwriting the file.
cp -dpr srcdir destdir
Copy all files from the directory “srcdir” to the directory “destdir” preserving links (-poption), file attributes (-p option), and copy recursively (-r option). With these options, a directory and all it contents can be copied to another dir
ln – Creates a symbolic link to a file.
ln -s test symlink
Creates a symbolic link named symlink that points to the file test Typing “ls -i test symlink” will show the two files are different with different inodes. Typing “ls -l test symlink” will show that symlink points to the file test.
locate – A fast database driven file locator.
locate -u
This command builds the slocate database. It will take several minutes to complete this command.This command must be used before searching for files, however cron runs this command periodically on most systems.locate whereis Lists all files whose names contain the string “whereis”. directory.
more – Allows file contents or piped output to be sent to the screen one page at a time
less – Opposite of the more command
cat – Sends file contents to standard output. This is a way to list the contents of short files to the screen. It works well with piping.
whereis – Report all known instances of a command
wc – Print byte, word, and line counts
bg
bg jobs Places the current job (or, by using the alternative form, the specified jobs) in the background, suspending its execution so that a new user prompt appears immediately. Use the jobs command to discover the identities of background jobs.
cal month year - Prints a calendar for the specified month of the specified year.
cat files – Prints the contents of the specified files.
clear - Clears the terminal screen.
cmp file1 file2 - Compares two files, reporting all discrepancies. Similar to the diff command, though the output format differs.
diff file1 file2 - Compares two files, reporting all discrepancies. Similar to the cmp command, though the output format differs.
dmesg - Prints the messages resulting from the most recent system boot.
fg
fg jobs – Brings the current job (or the specified jobs) to the foreground.
file files – Determines and prints a description of the type of each specified file.
find path -name pattern -print
Searches the specified path for files with names matching the specified pattern (usually enclosed in single quotes) and prints their names. The find command has many other arguments and functions; see the online documentation.
finger users - Prints descriptions of the specified users.
free – Displays the amount of used and free system memory.
ftp hostname
Opens an FTP connection to the specified host, allowing files to be transferred. The FTP program provides subcommands for accomplishing file transfers; see the online documentation.
head files - Prints the first several lines of each specified file.
ispell files – Checks the spelling of the contents of the specified files.
kill process_ids
kill – signal process_ids
kill -l
Kills the specified processes, sends the specified processes the specified signal (given as a number or name), or prints a list of available signals.
killall program
killall – signal program
Kills all processes that are instances of the specified program or sends the specified signal to all processes that are instances of the specified program.
mail – Launches a simple mail client that permits sending and receiving email messages.
man title
man section title – Prints the specified man page.
ping host – Sends an echo request via TCP/IP to the specified host. A response confirms that the host is operational.
reboot - Reboots the system (requires root privileges).
shutdown minutes
shutdown -r minutes
Shuts down the system after the specified number of minutes elapses (requires root privileges). The -r option causes the system to be rebooted once it has shut down.
sleep time – Causes the command interpreter to pause for the specified number of seconds.
sort files – Sorts the specified files. The command has many useful arguments; see the online documentation.
split file – Splits a file into several smaller files. The command has many arguments; see the online documentation
sync - Completes all pending input/output operations (requires root privileges).
telnet host - Opens a login session on the specified host.
top - Prints a display of system processes that’s continually updated until the user presses the q key.
traceroute host – Uses echo requests to determine and print a network path to the host.
uptime - Prints the system uptime.
w - Prints the current system users.
wall - Prints a message to each user except those who’ve disabled message reception. Type Ctrl-D to end the message.
I was thinking of application where I can split files through linux and join them in windows since I am most likely downloading huge file through linux server. Googling the problem was ended to this solution.
1. Download a copy of LX Split
2. Extract the file using tar by typing “tar zxf lxsplit-0.2.4.tar.gz” in command line
3. Go to the extracted folder by typing “cd lxsplit-0.2.4″
4. type “make” and “make install” after
5. Split the large file by typing “lxsplit -s hugefile.iso 15M” , this will split the file into 15Mb chunks
6. Transfer the files from Linux to Windows in anyway, in my case I transfer it through HTTP. You can use flash drive, ftp or other.
7. Download the java version or any kind of hjsplit for windows, I just used the HJSPLIT java version since I have the JVM installed.
8. Run the “jar” file and select the *.001 from the list of the chunks and click Join.
That’s it.
Recent Comments