Some Linux Tips


1) How to export DISPLAY on windows comp from a linux comp which is accessible from some router linux comp(for windows users only)

Suppose you are working on 10.8.11.1 and you go to 10.8.11.3 via 10.8.11.2, then to open graphical applications of 10.8.11.3 on 10.8.11.1, follow these steps:

1. start Xwin32 (on 10.8.11.1)
2. ssh to 10.8.1.2
3. export DISPLAY=10.8.11.1:0.0
4. vncserver (it will promt for a passwd, set the passwd)
5. start remote destop connection as server 10.8.11.2:1
6. xhost + (on 10.8.11.2)
7. ssh to 10.8.11.3 from 10.8.11.2
8. export DISPLAY=10.8.11.2:1 (on 10.8.11.3)
9. start any application.

2) How to get access of windows partitions in linux

As root, edit the file /etc/fstab e.g. let your windows C drive partition is /dev/hda1 and it is 'fat 32' file system. So to mount the C partition in /windows/C directory, in the /etc/fstab file, make an entry as
/dev/hda1     /windows/C    vfat   umask=0000  0 0
Note that umask=0000 will give write permissions to every user. To give write permission only to root, replace by
umask=0002

3) How to use mount command

a) To mount a hard disk partition
$mount -t <filesystem> -o <options> <device> <dir>
e.g. If you want to mount C partition as above, type as root
$mount -t vfat -o rw /dev/hda1 /windows/C

b) To mount an already visible directory to another place, type
$mount --bind <old-dir> <new-dir>

c) How to mount or extract .iso file in linux
As super user type
$mount -o loop -t iso9660 isofile mount_place

d) To mount nfs filesystem, e.g. mount /windows/C of 10.8.1.22 on your machine at /piyush/c, type
$mount -t nfs 10.8.1.22:/windows/C /piyush/c
For this, the comp 10.8.1.22 should have given you the permissions.

3)How to change encoding of media files

Use mencoder
$mencoder <input-file> -oac <audio-output-format> -ovc <video-output-format> -o <output-filename>

audio-output-format option is given as

    -oac copy     no encoding, just streamcopy
    -oac pcm     encode to uncompressed PCM
    -oac mp3lame     encode to MP3 (using Lame)


video-output-format is given as

     -ovc copy       no encoding, just streamcopy
     -ovc divx4       encode to DivX4/DivX5
     -ovc rawrgb       encode to uncompressed RGB24
     -ovc lavc       encode with a libavcodec codecs

To cut a movie file give the following command
$mencoder <input-file> -ss <start-position> -endpos <end-position> -o <output-filename>-oac <audio-output-format> -ovc <video-output-format> -o <output-file>

here end-postion can be given as
     -endpos 56       encode only 56 seconds
     -endpos 01:10:00       encode only 1 hour 10 minutes
     -endpos 100mb       encode only 100 MBytes
for start-position
     -ss 56       encode from 56 sec
other options are similar as above.

for more option type
$man mplayer

5) How to set an environmental variable/How to add path

$ PATH=$PATH:<path you want to set>
So if you want to set this path for all users then put this line in
/etc/rc.local in redhat and
/etc/init.d/boot.local in suse.

6)To send message from linux to windows

$ smbclient -M <hostname> -I <ip-address>
And to find hostname
$ nmblookup -A <ip-address>

7) How to build an rpm

a) from SRPM
Install the .src.rpm file this way:
$ rpm -i somepackage-1.0-1.src.rpm

This will create files in /usr/src/redhat/SOURCES and a .spec file in /usr/src/redhat/SPECS.
Then go the SPECS directory and give the command to build the RPM:
$ cd /usr/src/redhat/SPECS
$ rpmbuild -bb somepackage.spec

b) from source package

When a source archive (e.g., somepackage-1.0.tar.gz) contains a .spec file, one can give the following command to build the RPM without having to deploy the archive:

$ rpmbuild -tb somepackage-1.0.tar.gz

Give the -ta option instead if you also want to build the SRPM.

8) How to install fonts

One can install fonts in various ways.
a) type

$ xset fp+ <directory-path-of-font>
$ xset fp rehash

in this case u should have fonts.dir file in the directory.
this is a temporary way of installing fonts. u have to give these commands every time u start ur X-server.

b) Use font installer in control centre(not available in redhat)

c) Type as root
$ /usr/sbin/chkfontpath --add $ fc-cache
this doesn't work with suse but works well in redhat.

d) in /etc/X11/XF86Config file (in redhat XF86Config-4 file), in Section "Files" add the line

FontPath "<dir-path>"

and restart ur X-server. this works well in suse.

to check the list of installed fonts, type
$ xlsfonts

9) How to make an iso image

To make an ISO from your CD/DVD, place the media in your drive but do not mount it. If it automounts, unmount it.

$ dd if=/dev/dvd of=dvd.iso # for dvd
$ dd if=/dev/cdrom of=cd.iso # for cdrom
$ dd if=/dev/scd0 of=cd.iso # if cdrom is scsi

To make an ISO from files on your hard drive, create a directory which holds the files you want. Then use the mkisofs command.

$ mkisofs -o /tmp/cd.iso /tmp/directory/

This results in a file called cd.iso in folder /tmp which contains all the files and directories in /tmp/directory/.
10) How can I find certain words in files on my system?

Just type:

$ find DirectoryName -type f -printf "%p"  | xargs egrep -i "String" | less

where DirectoryName is the directory in which the files are located and
String is the string to be searched.

11) How can I find and replace certain words in files?

$ perl -e "s/old_string/new_string/g;" -pi.save $(find DirectoryName -type f)


12) How do I ignore system messages at login?

$ touch ~/.hushlogin

13) I cat a binary file and now my terminal is unreadable. How do I fix it?

Just do at your terminal:
<Ctrl>+v <Esc>+c

14) How can I count number of lines in a file?

At your promt type:
$ wc -l <file-name>


15) How to remove blank lines from a file?

$ sed -e '/^$/d' <file-with-blank-lines> <new-file>

16) How can I get number of files in all directories in the current directory?

$ find . -xdev -type d -exec /bin/echo -n {} \; -exec sh -c "ls {} | wc -l" \;

17) How can I unalias a command?

eg. if u alias the command as
alias ls='ls -l'

to unalias this permanently type
$ unalias ls

to unalias it temporarily just precede pico by a backslash

$ \ls

18) How to turn up num lock at bootup?

for t in 1 2 3 4 5 6 7 8
do
setleds +num < /dev/tty$t > /dev/null
done

19) How to see a movie from others comp?

$ ssh <login>@<address> cat <movie-path> | mplayer -

</ DIRECTORY-PATH-OF-FONT>eg.
$ ssh [email protected] cat /home/amit/f.mpg | mplayer -


20
) How to enable java in mozilla/konqueror?

You can make a softlink from /opt/mozilla/plugins to /usr/lib/j2re1.4.0/plugin/i386/ns610/libjavaplugin_oji140.so
by
$ ln -s
/usr/lib/j2re1.4.0/plugin/i386/ns610/libjavaplugin_oji140.so /opt/mozilla/plugins/
 

21)Creating Virtual Users in pure-ftpd


First download and install pure-ftpd from source using --with-everything as compile option. Now while running pure-ftpd use following flags
-lpuredb:/etc/pureftpd.pdb -l unix
Now use command pure-pw for adding/deleting virtual users
All this is explained in detail here.
Export sound using artsd
Just like one can use export DISPLAY=ip-addr:0 for viewing x-apps of a diffrent machine on his machine he can use artsd to do same with sound. Suppose a user working on machine APPLE connects to remote machine TRINITY he can just use command
$ export ARTS_SERVER=<ip-of-APPLE>:port
where port can be any number say 5001 in this case to listen to sound apps running on TRINITY on APPLE. But for this he will have to configure arts. Go to APPLE's Control Center->Sound->Sound System. Select Enable network transparency. Then in Sound I/O tab select other custom options and enter say -p 5001 -u . Now just press OK.
note :: 5001 is the port and can be set to any value.
Warning :: option -u given to arts is insecure and anybody can export sound to APPLE and play audio without any authentication


22)How to cut videos using Mplayer


Try mencoder, syntax is
$ mencoder <inputfilename> -forceidx -oac <audiotype> -ovc <videotype> -ss <starttime> -endpos <cliplength> -o <outputfiiile>
videotype can be lavc : For divx format
copy : just copy, same codec as input file
audiotype can be copy : use same codec as input file
mp3lame : mp3 format, but you need to have lame installed for that
There are many more options. Just check out manpages.

23)Mplayer to play VCD


Easiest way is to start gmplayer and right click on it and select play VCD Alternatively you can also use $mplayer -vcd <trackno> where trackno is a integer say 0,1,2.


24)Java in Mozilla


Just make a link to /usr/java/j2re*/plugin/i386/ns610/libjavaplugin_oji.so in /usr/lib/mozilla-1.0.1/plugins/ I am presently using BlackDownJava2 with Mozilla 1.4. (note: all versions of JAVA dont work properly)

 

1

Hosted by www.Geocities.ws

1