Elvenware

LinuxFAQ

The index for LinuxFAQ:

Description Abbreviation Code
Execute xer 123

Linux FAQ

ApacheDir

To create a new directory in Apache go /etc/apache and change srm.conf or
access.conf

You can also just create a symbolic link to a directory from the /var/www
directory. Then you can access the symbolic link from the web. For instance
create a link to /charlie1/wwwroot/links in /var/www/links. 

BashProfileBashRC

Here is a good reference if you want the PATH and environment 
variables to show up in the GUI:

Persitent enviornment variables on Ubuntu

The suggestion for the best place to put environment variables
would be either ~/.profile or ~/.pam_environment. If you just want
to set things for the command line session, then .bashrc.

The .bash_profile file controls the environment settings, but it uses 
file called .bashrc to set the path.

In .bashrc:

# Set JAVA_HOME:
export JAVA_HOME=/usr/lib/jvm/default-java

To test if it is set use either of the following:

{$JAVA_HOME:?}
echo $JAVA_HOME

Here is something you can put at the end of .bashrc to ensure **ssh-agent**
is loaded every time you open a shell. This means multiple copies can 
get loaded, but that may actually be the most useful approach in some
cases:

if [ -z "$SSH_AUTH_SOCK" ] ; then
    eval `ssh-agent`  
fi

BatteryTime

Find out how much time is left on the battery when you are not plugged in:

issue the command: apm

bootfloppy on Redhat

Creating a boot floopy

mkbootdisk --device /dev/fd0 2.23333

where 2.23333 is the kernal version found in /lib/modules

Sometimes disaster strikes. For instance, if you are dual booting, and
happen to reinstall Windows, then Bill will wipe out your Grub or Lilo
multiboot options. (Nice guy, right?) There is no need to worry, at least 
if you are using RedHat. Stick the first disk of the red hat CD ROM series 
in your CD and reboot. If your system is set up to boot from CDROM, then it 
will do so. Follow the instructions to get into rescue mode, or type linux 
rescue. This will boot you up into command line mode for linux. To set up 
the correct root, type chroot /mnt/sysimage. Now you can follow the 
directions above to create a boot floppy.

byte compile on el file in emacs

byte compile an el file from lisp in emacs

m-x byte-compile-file

Or choose it from the menu

Change Directory: cd

The cd and chdir commands do the same thing. For the man entry, use chdir.

This command changes the user's current directory. For example, to move from the current directory to
a directory called temp, you might type something like this:

cd /home/ubuntu/temp/

Remember that you can always find your current directory by typing pwd.

Copy: cp

The Linux command to copy a file is cp.

Usage:

    cp myfile.txt /home/charlie/.

This command copies myfile.txt from the current directory to the /home/charlie directory.

Copy with checking for date:
  cp -rpuvf

CronStuff

Keep a crontab file called crontab in your home directory.

Here is a sample line for running the script foo every minute:

* * * * * /root/bin/foo

Here is a sample line for running the script foo every hour on the hour

0 * * * * /root/bin/foo

Run it between 9 and 5 pm:

0 9-17 * * * /root/bin/foo

Run it at 10 after 20 after 40 after:

10,20,40 * * * * /root/bin/foo

Run it first day of month and every sunday at 2 am:

0 2 1 * 0 /root/bin/foo

Run it on Jan 1 at 2 am:

0 2 1 1 * /root/bin/foo

So its the

minute, hour, day of month, month, day of week, program name

DebianPackages

/usr/src/linux

  make xconfig

dpkg -i MyFile.deb

debug a perl program in ddd

debug a perl program in ddd

ddd --perl program

delphi debug with ddd

compile Delphi with dcc -b -v filename.dpr

then

xxgdb filename

DelphiInstall

gnu:/exports/latest

DelphiLibs

      You need to have qtintf.so in your LD_PATH. I created a symbolic
      link from /usr/lib to "the kylix install"/lib/qtintf.so.2.2.0. On
      my system "ln -s /kylix/qt/qtintf.so.2.0.2 /usr/lib/qtintf.so"
      You need to specify the unit directory. On my install "dcc
      -U/kylix/lib "  

DelphiSoFiles

Building so files

dcc -y -m -z -p System.pas

Copy the result dpu file to lib directory.

Create a library file.

library simple;

function GetNine: Integer;
begin
  result := 9;
end;

exports 
  GetNine;

begin
end.

Build the so file the same way you build System.pas. Copy the file to some
place on your LDPATH, such as /usr/lib.

Then create the file to use it:

program test;

function GetNine: Integer; external 'simple.so' name 'GetNine';

begin
  WriteLn(GetNine);
end.

DiskFree

df gives you are reading of the space left on your drives. df -h makes 
it human readable

du gives you all the directories benearth the current one.

How much space does this directory take up?

du is the command to get a list of the current directory and all
directories under it

Here is the command for the record of all the files in the home
directory. This command sends all errors to dev null, and only
reports the total, not the suptotal for each directory:

du --summarize --one-file-sytem /home 2 > /dev/null

Here is the result of running du in my /home/ccalvert/.gimp
directory:

4   ./brushes
4   ./gradients
168 ./palettes
4   ./patterns
4   ./plug-ins
4   ./gfig
4   ./tmp
4   ./scripts
4   ./gflares
408 .

Here is the result of running the summarize command in the 
same directory:

du --summarize /home/ccalvert.gimp 2 > /dev/null
408    /home/ccalvert/.gimp

Note that if you put the -one-file-system flag in you would get no result 
at all on the .gimp directory. 

DNSLookup

To see what the DNS server things is the name of a particular IP address

NSLOOKUP 10.143.13.126

to pump in a domain name: ./pump -i eth0 -h theshire

To restart the network, go into init.d and type network restart

pump

Find DNS Servers

What are the DNS servers for a particular machine?

Look in /etc/resolv.conf

FTP Server

Setting up the FTP Server on RedHat 7.2

Use the PackageManager (kpackage) to make sure both anonftp and wu-ftpd are installed

rpm -Uvh wu-ftpd* anonftp*

Now go to your /etc/xinitd directory and open up wu-ftp and make sure that
disable is set to no. By default, it is set to yes.

EmacsFont

add this to your bashrc to start emacs with a bigger font:

alias emacs='emacs -font -adobe-courier-medium-r-normal--14-100-100-100-m-90-iso8859-1'

FileOwner

Give ccalvert permissions to own a file:
  chmod -o=rw FileName.txt

File Permissions

This command gives the group the same rights as the owner:
  chmod g=u

u   User  Owner of the file
g   Group Group to which the owner belongs
o   Other All other users
a   All   Same as ugo

This command gives the owner rights:
  chmod u+r

This command gives the group rights:
  chmod g+r

This comand gives others rights:
  chmod o+r

To see the octal numbers associated with a file (755 or 777, etc) use stat,
passing in requests to see the File Permissions in human readable form (%A),
in octal form (%a), and to see the file name (%n):

  stat -c '%A %a %n' * 

The stat command above yields output like this:

  -r-xr--r-- 544 file.txt

Here is a short session with chmod and stat. First we use stat see the octal number,
then we use chmod to change the file permissions, then we use stat view the changes:

  $ stat -c '%A %a %n' bar.txt
  -rw-rw-r-- 664 bar.txt
  $ chmod 600 bar.txt
  $ stat -c '%A %a %n' bar.txt
  -rw------- 600 bar.txt
Description Abbreviation Code
Execute x 1
Write w 2
Read r 4
Read and Execute rx 5
Read and Write rw 6
Read, Write & Execute rwx 7

Other:

Name Location
owner -rwx------
group ----rwx---
other -------rwx

Link to TuxFiles Linux Permissions

find a directory or file

if you have lost a file, you can search across the entire system for it. The command you use is called find.

To look for files in the current directory and all sub-directories:

find -name my-file.txt

If you want to look across the entire system:

find / -name my-file.txt 

That command says: starting at the root (/) look across the whole system for simple-python.py.

If you start looking across the entire system, and you are not root (sudo), you will get error messages about directories that you don't have permissions to search through. To get rid of the errors and see only the found files:

find / -name my-file.txt 2>/dev/null

That's not a typo, you should write 2>/dev/null.


To find directory name type:

 find . -type d -iname dirname

fdisk

And (sudo fdisk -l)

gnome

You can run gnome and unity on the same Ubuntu machine. Install either unity or gnome:

sudo apt-get install gnome-shell
sudo apt-get install unity

Now reboot either through the GUI, or like this:

sudo shutdown -r now

At the login prompt there is a little Ubuntu icon. Click it, and you will be able to choose
whether you want to use gnome or unity.

grep

You want grep to search through multiple directories. Use backticks to run find in place:

grep "Find this string" `find . -iname "*"` 

This will find the string "Find this string" if it appears in any file ("*") in the current
directory or one of the current directory's subdirectories.

Java

Open JDK on Ubuntu:

sudo apt-get install openjdk-7-jdk 

I got that from here: http://openjdk.java.net/install

Oracle Sun JDK on Ubuntu:

sudo add-apt-repository ppa:webupd8team/java 
sudo apt-get update 
sudo apt-get install oracle-java7-installer

Set up the environment variables JAVA_HOME and PATH: sudo apt-get install oracle-java7-set-default

I got that from here:

Jobs

Type jobs to see the list of running jobs
Use fg to switch back to a job.
If you are in nano, and want to get to the prompt to do some task, press Ctrl+Z. Then fg to get back.

You don't have permission to access / on this server

You try to browse to your server on your machine and get an error about permisisons. The
problem might be that linuxconf has screwed up your httpd.conf file. Look for <files ~> and
replace with:

<Files ~ "^\.ht">

library browsing

run nm on it to see the symbols in a library
  nm libc.

MountCD

Mount the CDROM drive
  mount /mnt/cdrom

MountDosFloppy

command line for mounting a flopping on red hat
mount -t vfat /dev/fd0 /mnt/floppy 

Move

Use the mv to move a file from one location to another, or to rename a file. This is like copy,
but the original file is deleted after it is copied.

Usage:
    mv [OPTIONS] source directory
    mv [OPTIONS] source dest

Example:
    mv myFile.txt /home/ubuntu/
    mv myFile.txt myBigFile.txt
    mv --update myFile.txt /home/ubuntu/.

The second example renames a file. The third uses an option that specifies that the file
should only be moved if the destination file does not exist or if the source is newer than
the destination. There many other options, of course. Type man mv to see all the options.   

NetWorkPing

Getting the network to ping other machines in your LAN:
 etc/sysconfig/network-scripts/ifcfg-eth0

 BOOT_PROTO="dhcp"
 DHCP_HOSTNAME="Merlin"
 PUMP="yes"

 dns,hosts

NetworkStuff

Network stuff:
  ifconfig
  netcfg
  route
  cardctl ident
  cardctl status

  Check /var/log/messages for reports on errors

Here are some important files
  /etc/sysconfig/network-scripts/ifcfg-eth0
  /etc/sysconfig/network-scripts/ifup
  /etc/sysconfig/network                  // Not as sure about this one


/etc/rc.d/int.d/network restart

NFS Stuff

Here is the command ot start nfs:

/etc/rc.d/init.d/nfs start

You can also stop it, or check its status

Here is how to mount a drive on remote machine:

mount 192.168.1.1:/home/ccalvert /mnt/foo

You can specify what to export from your machine in the file:

/etc/exports

For instance:

/home 

here is how to export your home directory as read only from
/etc/exports:

/home (ro)

Here is how to export as read write from /etc/exports. 

/home/ccalvert (rw)

To make the above statement work properly, you may need to be signed
on as ccalvert on the client machine.

Here is a line you can add to your fstab file to make it so you an
mount more easily:

192.168.1.30:/home/ccalvert /mnt/foo                nfs     noauto,user,rw     0 0

After adding this line, you can mount with this command:

mount /mnt/foo

To see what's going on on another machine:

rpcinfo -p 192.168.1.1

NovelLogin

LOGIN TO NOVEL SERVER

modprobe ncpfs
ipx_interface add -p eth0 802.3
ncpmount -s SV5 -U ccalvert.Mkt.HQ.Inprise /mnt/foo

ncpmount -S SV5 -U ccalvert.mkt.hq.inprise /mnt/foobar

PathSetup

In your ~/.profile file:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

You can also use ~/.pam_environment:

JAVA_HOME=/some/folder
PATH DEFAULT=${PATH}:${HOME}/bin

See this:

Persitent enviornment variables on Ubuntu

PingYourself

Clean up the problem with ping yourself 

in this file
/etc/sysconfig/network 

DHCP_HOSTNAME=theshire

/etc/hosts

delete the reference to theshire or whatever host name you have

Remote Login Stuff

rlogin -l ccalvert hostname

RestartApache

Restart Apache

etc/rc.d/init.d/httpd restart

rpm and the F for Freshen option

Freshening is different than updating in that you will only Freshen packages that 
are already installed, while update will update or install an uninstalled package.
I have found that freshen works well when you get in to conflicts between different
versions of packages that are already installed. Freshen just seems to get around
that issue.

RedHat Notes on RPM       

rpm-glibc

rpm -Fvh glibc*.rpm

RedHat Notes on RPM                    

Remove or delete a directory/folder

To remove a directory use the rm command. To remove a directory that contains files or other directories, use rm -rf. 

Here is an example. First confirm a folder called bar exists and that it contains some content:

hadooper@WesternSeas:~/bin$ ls bar/
foo.txt

Now try to remove the directory without passing parameters to rm:

hadooper@WesternSeas:~/bin$ rm bar
rm: cannot remove `bar': Is a directory

The second line shows a failure. No try again with -rf. It will return without 
giving feedback, which means success. I then try to list the folder, which fails, 
proving that the folder has been deleted:

hadooper@WesternSeas:~/bin$ rm -rf bar
hadooper@WesternSeas:~/bin$ ls bar
ls: cannot access bar: No such file or directory

Working with Samba

SAMBA:

run this, or the result of cat /car/run/inetd.pid, which is a na a number:

kill -HUP `cat /var/run/inetd.pid`

Go to /etc/rc.d/init.d and run:
./smb start

You should then run:

./smb status 

to be sure it is running (two files)

To check smb.conf run testparm

Set security to either user or share

To create a public share called myshare:

[myshare]
   path = /home/ccalvert
   public = yes
   only guest = yes
   writable = yes
   printable = no

You probably want to set the security level to share, unless you have
domain controller.

Set the directory and the files in it to the group users

SambaInfo

Samba info

go to /etc/samba/smb.conf

and set the following:

   encrypt passwords = yes
   smb passwd file=/etc/samba/smbpasswd

also, you probably have to manually start nmbd

SeeProcesses

See all the current processes:
  ps aux
  ps aux | grep smb

Shutdown Ubuntu

From the command line. You have three options, of which the second shown is usually best:

    sudo shutdown now        // Go to single user mode for admin work
    sudo shutdown -h now     // Turn off the machine right now
    sudo shutdown -r now     // Reboot the machine now

There are other options, such as halt, poweroff and reboot, but shutdown is usally the
preferred option. Users are notified of what is about to happen.

If you to shut down in five minutes do this:

    sudo shutdown -h +5

SmbMount

smbmount //eastfarthing/cdrive -c "mount /Charlie" user%password

One corel:

  mkdir a directory in mnt. 

  smbmount //eastfarthing/cdrive /mnt/foo -U ccalvert

SSH

You can install it all in one go:

  sudo apt-get install ssh

Or you can install either half:

  sudo apt-get install openssh-client
  sudo apt-get install openssh-server


Assuming you have SSH installed on your Linux box, you should be able to use SSH to open
a shell on remote machine like this:

ssh charlie@ftp.somewhere.com

Or like this, if you want to use an ip address:

ssh charlie@192.168.0.22

Or like this if you want to specify a private key:

ssh -i MyPrivateKey charlie@192.168.0.22

See below on how to load a private key into memory with SSH-AGENT and SSH-ADD.


SSH comes in two parts. The server part is called sshd. 

To see if you have the server installed, type:

  which sshd

It should return the name of the ssh server executable, which might be something like:

  /usr/sbin/sshd

To see if sshd is running try any of the following:

  ps -A
  ps -C sshd
  pgrep sshd

After running these commands the word sshd should appear in the output if it is running.

You can start and stop the service this way:

  sudo service ssh stop  
  sudo service ssh start

Use a tool like PuttyGen to create a private/public key pair. The private key stays on your
current machine is a secret. Your public key goes on the remote server in the root of your 
home directory in this location: .ssh/authorized_keys file. 
The public key you put in authorized_keys need not stay a secret. If you don't associate a password
with your key pair then you will never be prompted for a password. If you do associate a 
password, you can only need to enter it once a day or so by using the Putty program called 
Pagaent, which keeps your password for your private key in memory. When you connect to the 
remote server, it finds your public key, matches it to your private
key, and let's you in without you having to type a password.

SSH-AGENT and SSH-ADD

These tools enable Linux users to load a private key into memory, much the way Pagaent allows you to load
private SSH keys into memory on Windows.

The simplest, but probably not best technique, is to do this:

eval `ssh-agent`
chmod 400 MyKey.pem
ssh-add MyKey.pem

Notice the back ticks on the call eval. In this example, MyKey.pem is your private key. It might have a name like id-rsa. 
I'm not crazy about this, because it appears I need to do it each time I log into my shell. Isn't there a better way?
Yes, there is, see SSH Keys below.

I like to put code to load ssh-agent in my .bashrc file:

if [ -z "$SSH_AUTH_SOCK" ] ; then
    eval `ssh-agent`  
fi

Assuming that I have already run **chmod 400 MyKey.pem**, then I can run this command alone to load my key:

ssh-add MyKey.pem

Frequently my private key is in the **.ssh** folder, so in practive I might type something like this instead:

ssh-add ~/.ssh/MyKey.pem

That path in that code goes points to a private key in my **.ssh** folder. As a result, I can use the command from anywhere on my system.     

Finally, you can add a command like that to your .bashrc folder.

Another technique, which is perhaps even more powerful, is to set up a config file in your **.ssh** folder:

Host myEc2Instance
    HostName 52.11.190.176
    Port 22
    User ubuntu
    IdentityFile ~/.ssh/MyKey.pem

Host bitbucket.org
    IdentityFile ~/.ssh/MyKey.pem

Host github.com
    IdentityFile ~/.ssh/MyKey.key

Now, when you want to connect to your EC2Instance, you just type:

ssh myEc2Instance

See also Git page and SSH.

Sudo

Temporarily become the superuser, or adminstrator. Technically, you can become
any user with this command, but by default, you become superuser.

Example:

    sudo apt-get update

In the example shown here, the command apt-get is run, and passed the argument update. 
To run apt-get you must be superuser, so we run two commands: the sudo command followed
by the command we wish to run. If you are not the superuser, and you try to run apt-get without first running
sudo, you will get an error. Often the error will be about files that you want to access being locked.

In ubuntu and other flavors of Linux, users typically do not become superuser. Instead, they invoke sudo
whenever they want to do something that a superuser would do. This is similar to the UAC (User Account
Control) works in Windows. When you want to install software, or invoke other privilaged commands, 
a dialog pops up to confirm that you want to do this. In some cases, you have to enter a password. The
sudo command in Linux is just a variation on this general theme. Or rather, since sudo was first created
in 1980, before Windows even existed, UAC is a variation on the sudo command.

The sudo command is configured by script found here: /etc/sudoers

Frequently, the users who are allowed to invoke sudo are the members of the adm (administrators)
group.

SwitchDesk

/opt/kde/bin/usekde ccalvert

Use this command to switch the desktop:
  switchdesk  
To createa symbolic link between two directories you can do the following:

  ln /charlie1/docs /home/ccalvert/docs

After you give this command, there will be a "file" in the home/ccalvert 
directory called docs that acts just like the directory /charlie1/docs.
If you are in /home/ccalvert and issue the command cd docs, then you
end up in the /charlie1/docs directory.

TarFiles

Create a tar file:
  tar -cvf FileName.tar FileName.txt

Create a tar zip (tgz) file
  tar -cvfz FileName.tar FileName.txt

Zip up a tar file:
  gzip FileName.tar

Unzip a tar file:
  gzip -d FileName.tar.gz

Untar a file and create directories:
  tar -xvf FileName.tar

Untar and unzip and create directories:
  tar -xvfz FileName.tar

VersionLinux

lsb_release -a

or

uname -a

or

file /sbin/init      

Wine

Use rpm packages to install wine, then get the winesetuptk from:

WriteFilePermission

Change writes on file so all (other) can write to it:
  chmod o+w MyFile.txt  

XLibConnection

Get XLib: connection refusted by server
XLib: client is not authorized to connect to server

Do this, when logged in as you:

xhost +strider.inprise.com

X Windows and root

can't use X from root

just copy your .Xauthority file from ccalvert to the root directory

The issue is that you started X as ccalvert, so root has no permissions
By copying the file over .Xauthority, you get permissions. You could
also use xauth to set up .Xauthority, but that is a bit tricky.

Zip Files or Folder

Create zip file called myZipFile and put all of contents of MyFolder
into it, including any sub-directories.

zip -r myZipFile MyFolder/*

Mounting Zip Disks

Most distributions, including Red Hat, set everything up for you ahead of 
time. All you need to do is the following: 

modprope ppa

You might also be able to use insmod ppa, but that might not work, and the 
above command is more reliable, as it sets up everything that ppa needs.

Put a disk in the drive. I think you have to have the disk in there or 
this won't work.

Assuming the directory /mnt/zip already exists, then 
enter:

mount -t vfat /dev/sda4 /mnt/zip 

If this doesn't work, then you need to rebuild the kernal. This isn't as 
bad as it seems. The zip drive mini HOWTO will talk you through it.

To make life easier, add this line to fstab:

/dev/sda4  /mnt/zip vfat noauto,owner 0 0

Now you can mount with:

mount /mnt/zip