Showing posts with label General. Show all posts
Showing posts with label General. Show all posts

Saturday, November 14, 2009

Creating specific sized file

To create a specific sized file, dd command can be used. Example below will create a file named output with 10M size:


$ dd if=/dev/zero of=output bs=1M count=10
where bs is block size, and count is number of blocks to be created

The output:

$ ls -lh output
-rw-r--r-- 1 user user 10M 2009-11-14 06:21 output

Friday, November 13, 2009

Splitting big files

To split big files, split command can be used. Below is command used to split 400MB file named bigfile into 100MB chunk files named smallfile0*


$ split -b 100M -d --verbose bigfile smallfile
creating file 'smallfile00'
creating file 'smallfile01'
creating file 'smallfile02'
creating file 'smallfile03'
where -b is for byte size, -d is for numeric suffixes and smallfile is the prefix to be used

The output is:
$ ls
bigfile smallfile00 smallfile01 smallfile02 smallfile03

To recover back the splitted files into a file named newbigfile:
$ cat smallfile0* > newbigfile


Monday, August 18, 2008

Saving website on local machine

Sometimes you found a website that is very interesting, but you just do not have enough time to read it on that particular time. You wish you could save it so that you can view it offline without connecting to the internet. This can be done using wget;

$ wget -m -k -K -E http://www.tldp.org/HOWTO/LVM-HOWTO/index.html

where -m for mirror, -k for convert the links so that it will be suitable for local viewing, -K for backup converted files and -E for adding html extension to the files downloaded. This is the result of the above command;

$ ls
www.tldp.org

Use any web browser to view the files offline by opening the .html file inside the above folder

Wednesday, June 4, 2008

Displaying message of the day (motd)

When you have logged to your machine through ssh, this is what you will always see after each successful access:

Last login: Tue Jun 3 13:17:35 2008 from 10.20.20.171
[user@server ~]$

You can have additional message displayed like this, by using message of teh day (motd):

Last login: Wed Jun 4 14:59:13 2008 from 10.20.20.241
This is a my server!!!!!!
[user@server ~]$

Here are the steps to do it:

  1. Open /etc/motd using your favorite text editor. I will use vi
    • vi /etc/motd
  2. Append your message to the file and save
    • This is a my server!!!!!!
  3. Then, when this will be displayed when you access your machine again
    • Last login: Wed Jun 4 14:59:13 2008 from 10.20.20.241
      This is a my server!!!!!!
      [user@server ~]$
Have fun....:)

Friday, April 4, 2008

'Watch'ing your commands running

Sometimes when you run a command, you need to see the progress of the command, yet you do not want to keep refreshing the command by repeating it a few times. There is a useful command in linux that can do the job of refreshing for you which is watch. According to the watch man page: "watch - execute a program periodically, showing output fullscreen". By default watch will refresh the command in the interval of 2 seconds but this can be changed according to your needs.
For example, you want to see the memory usage of your computer every 2 seconds:

$ watch free -m

This kind of output will show:


(Click on the image for clearer view)

To set the interval(15 seconds) which watch will refresh, use -n option:

$ watch -n 15 free -m

The output:


(Click on the image for clearer view)

To see the differences of each refresh session, use -d. Watch will highlight the changes that happening on that particular moment:

$ watch -d free -m


(Click on image for clearer view)

To exit from watch, just use your trusty Ctrl-c

Tuesday, March 4, 2008

Getting help in linux

To remember every commands in linux is a very tough job. Even experienced user cannot boast that they have remembered every single command. To get help about commands in linux, a few commands can be used.

  1. # man command
    • format and display manual pages for commands
  2. # info command
    • information document about commands
  3. # command --help
    • help on commands
  4. # whatis command
    • search the whatis database for complete words
  5. # apropos string
    • search the whatis database for strings
  6. # man -k string
    • search manual pages for strings. similar to apropos
You have to change 'strings' to your desired strings and 'command' to your desired command

Thursday, February 28, 2008

Extracting tar into chosen directory

Extracting tar is a common thing to do and everybody familiar with unix and linux knows how to do it. Usually the files will be extracted to the current directory. There is although one small trick to do to send the files to the desired location. Use the below command:

# tar -xvzf filename.tar.gz -C /desired/path

This command will extract(-x) verbosely(-v) tar gz(-z) file(-f) to the desired location. Hope this will help. Cheers

Friday, February 1, 2008

Text viewer

To view text in linux, there are several tools that one can use. The purpose of the text viewer is to view the text file and not editing it. Some of it also equipped with search function to ease reading.
If you are using GUI, you can use gedit, which is available if you are using gnome desktop environment. Gedit works as both editor and viewer. If you are using KDE desktop, you can use KEdit.

In the absence of GUI, a few tools can be used, such as less and more. These 2 tools is quite similar with only the difference in name.
To use less:
# less filename

and similarly to use more:
# more filename

Another tool that can be used is cat. Cat's purpose is to concatenate 2 file into one, but if used to a single file, cat will display the file to standard output. To use cat:
# cat filename

Tuesday, December 18, 2007

Sending message to users

To send message to a particular user, you have to know what is the user tty. You can do this by typing:

# w


This command is used to show who is logged on and what they are doing. The output of the above command is usually like below(Click to see the image clearly):



To send message to a specific user:

$ write username tty

Example, to send message to user user1:

$ write user1 pts/3


Write you messages, and then press Ctrl-d to exit 'write'

To send message to all connected user, use wall command:

$ wall

Type your message and Ctrl-d to exit 'wall'

Friday, July 20, 2007

Setting system clock and date

To set system clock and date using command, date command can be used.
This is how to do it:

-> date mmddttttyyyy.ss where;
mm - month
dd - day
tttt - time in hours and minutes
yyyy - year
ss - seconds

For example, to set the current date to 17 July 2007, 11:15 a.m., this command below can be used:

-> date 071711152007

To see the current date, the date command without argument can be used.

-> date

Wednesday, July 4, 2007

Understanding Linux Runlevels

Unlike most non-unix operating system, Linux have many runlevels. They are numbered from 0-6 like below.

0 - halt
1 - Single user mode
2 - Multiuser, without NFS (The same as 3, if you do not have networking)
3 - Full multiuser mode
4 - unused
5 - X11
6 - reboot

This list is taken from /etc/inittab file where init will find its configuration setting. The default runlevel usually is set to runlevel 5 where it is the graphical mode of linux. Halt means shutdown and runlevels 1-3 are non graphical mode. You can switch your runlevel by using;

-> init

To check your current runlevel, you can use;

-> runlevel

To view this list;

-> vi /etc/inittab

Friday, June 22, 2007

Amarok cannot play mp3

If after you have installed media player amarok, and the player cannot play mp3 files, you have to install one more library: libxine-extracodecs

Run
-> sudo apt-get install libxine-extracodecs

or
use synaptic package manager to install the library

Tuesday, June 19, 2007

To search for string in files

To search for a string in all files from the given directory, grep command can be used. Type:
-> grep -R "string" /path

For example, to search for string "default" in /tmp directory, use this command:
-> grep -R "default" /tmp

Monday, June 18, 2007

Changing default editor for your linux machine

Below are the steps to be taken to change your default editor. Usually for Ubuntu, the default editor is pico and for Centos is vi.

  1. To change your default editor to vi, type:
    • -> export VISUAL=/usr/bin/vi
  2. To make it permanent for current user, add the above line to /home/user/.bash_profile
  3. To make it permanent globally, add the above line to /etc/profile

How to format your flash drive

This is how you can format your flash drive(thumbdrive, pendrive) in any linux machine

1. To see what is the filesystem for your flashdrive

  • type -> df



2. Type -> mkfs /dev/sdb1
(The /dev/sdb1 is according to your outcome of the df command previously: refer above diagram)
This command will format the flash drive to ext3 format which is the default.
To format it to fat;
type -> mkfs -t vfat /dev/sdb1

Friday, June 15, 2007

Installing flash player to mozilla firefox on x86 64 bit machine

  1. Download nspluginwrapper here
  2. Once dowloaded, extract it.
  3. Open the folder extracted and the folder inside it, double-click on "GetFlash". Select "Run in Terminal".
  4. When finished, restart firefox.

Thursday, June 14, 2007

How to view the content of iso image

Sometimes we have an iso image in our computer. One of the way to view it is to burn it on a cd and then we can view it. The other method is we can use mount command.
Type this command on terminal:

-> mount -o loop filename.iso /path/to/directory

where;
/path/to/directory - directory where you want to deploy the iso

filename.iso - name of the iso file

Wednesday, May 30, 2007

Mounting cdrom

If you are using a pc with linux that does not have automount feature, here are the steps that you can do to mount it on linux terminal.

  • After inserting the cd, create a folder. Usually we create a folder inside folder /mnt. Type --> mkdir /mnt/cdrom.
  • To mount it, type --> mount /dev/cdrom /mnt/cdrom. This step will mount the content of the cdrom to the folder /mnt/cdrom
  • After you finish, just type --> umount /mnt/cdrom to unmount it from the folder.
You can also use this steps for other devices such as flash drive. To check where is the folder containing the device, type --> df.
This command is for the user to see disk space usage.

Wednesday, May 9, 2007

how to check your kernel version

Sometimes you want to know the particulars about the kernel of your linux. This can be done using uname command.
To check kernel version:
->uname -v
To check kernel release:
->uname -r
To check kernel name:
->uname -s

Tuesday, April 17, 2007

Viewing system's running processes

To view running processes, you can use ps command to list out the running processes.
To see every process on the system:
ps -e
ps -ef
ps -eF
ps -ely
To find the process that you want to see:
-> ps -e | grep nameoftheprocess

example: -> ps -e | grep httpd
The above command will print only the httpd process.