Bash commands

 

Setting the time

If given an argument that does not start with `+', `date' sets the system clock to the date and time specified by that argument (as

described below). You must have appropriate privileges to set the system clock.

The `--date' and `--set' options may not be used with such an argument.

The `--universal' option may be used with such an argument to indicate that the specified date and time are relative to

Coordinated Universal Time rather than to the local time zone.

The argument must consist entirely of digits, which have the following meaning:

`MM' month

`DD' day within month

`hh' hour

`mm' minute

`CC' first two digits of year (optional)

`YY' last two digits of year (optional)

`ss' second (optional)

The `--set' option also sets the system clock;

 

[root@sds1 logdir]# date 050410142009

Mon May 4 10:14:00 CEST 2009

========================================

Terminal : Backspace scrambled characters

Opl.        stty erase ^?

========================================

 

Aliasssen

te vinden in /etc/.bashrc
  Indien niet :
  grep `whoami` /etc/passwd | awk -F: '{print $7}'
  the /bin/ksh and /bin/sh use ~/.profile
  the /bin/csh use ~/.login
  => [nsisc@leffe etc]$ grep `whoami` /etc/passwd | awk -F: '{print $7}'
/bin/bash
[nsisc@leffe etc]$ cd ~
[nsisc@leffe nsisc]$ pwd
/project/nsisc
[nsisc@leffe nsisc]$ ls -a
.bash_history 
.bash_profile 
.bashrc       
...

Kijk in : vim .bashrc

if [ -f ".nsisc_profile" ]; then
  . .nsisc_profile
fi

if [ -f /etc/bashrc ]; then
  . /etc/bashrc
fi

=> .nsisc_profile bevat een alias
De rest is in :
/etc/bashrc  (.. /etc/profile.d/*.sh)

========================================


format output of ls related to date/time

ll -rt --time-style=+%Y%t%m%t%d /tmp/
 
 =>
-rw-rw-rw- 1 root  root      39 2013    01      11 ProductName
-rw-rw-rw- 1 root  root      28 2013    01      11 Manufacturer

 

========================================

File descriptors

ls -l > out 2>& 1
Zal de output van het (stdout file descriptor nr. 1) listing cmd schrijven naar de file out.
Ook de output van de error (stderr file descriptor nr. 2) wordt geschreven naar dezelfde lokatie als van 1.

========================================

HISTORY

history | tail -10
!1059 : selecteert en executeert commando

~/.bash_history

!200 -> executes the command from history

========================================

CTAGS

ctags *  of ctags -R

========================================

GREP

Selecteer een groep bestanden en uit die groep sluit uit een selectie
ps -ef | grep mingetty | grep -v tty1
Dit gaat uit de processen die runnen alleen deze kiezen met de naam mingetty maar uitsluiten waarin tty1 voorkomt.

ps -ef | grep mingetty | grep -v tty1 | awk '{print $2}'
Dit gaat ook uit de processen die runnen alleen deze kiezen met de naam mingetty maar uitsluiten waarin tty1 voorkomt EN
zal alleen de tweede kolom weergeven.

grep -d recurse "zoekstring" /dir/subdir
Zoekt recursief naar de zoekstring in het gegeven path.

 

Search Multiple Words / String Pattern Using grep Command

How do I search multiple string using grep command? For example I'd like to search word1, word2, word3 and so on within /path/to/file. How do I force grep to search multiple words?

The grep command supports regular expression pattern. To search multiple words, use following syntax:
grep 'word1\|word2\|word3' /path/to/file
In this example, search warning, error, and critical words in a text log file called /var/log/messages, enter:
$ grep 'warning|error|critical' /var/log/messages
To just match words, add -w swith:
$ grep -w 'warning|error|critical' /var/log/messages

========================================

Built-in Shell Variables

$0   name of the command or script being executed
$n   positional parameters, that is, arguments given on the command line numbered 1 through 9
$#   number of positional parameters given on command line
$*   a list of all the command line arguments
$@   a list of all command line arguments individually double quoted
$?   The numeric exit status (that is, return code) of last command executed
$$   PID (process ID) number of current shell
$!   PID (process ID) number of last background command

========================================

Vergelijk folders.

diff -qr /project/nsisc nsisc
diff -qr /project/nsisc/bin/ nsisc/bin/
diff -qr /project/nsisc/bin/ nsisc/bin/|grep -v SX_ns
diff -qr /project/nsisc/bin/ nsisc/bin/|grep -v SX_ns|grep -v iscmain

========================================

FIND MODIFIED FILES SINCE A CERTAIN TIME

To find all files that are modified today only (since start of day only, i.e. 12 am), in current directory and its sub-directories:

touch -t `date +%m%d0000` /tmp/$$
find /tmefndr/oravl01 -type f -newer /tmp/$$
rm /tmp/$$

The first command can be modified to specify other date and time, so that the commands will return all files that have changed since that particular date and time.

========================================

uptime

=> laat zien info over hoelang het systeem actief is.

========================================

watch

bvb. watch "ls -l /root"
geeft online veranderingen weer,kan gebruikt worden voor alle commandos

=========================================

touch


touch -t 08071143 /data/nsisc/env/RtapSnapCtrl

 

=========================================

Remove entire line containing string in a file

Q I need to grep for a particular 'string' in a file and remove the entire line where the occurrence of the string is found. I want it to work across with a collection of files. Can you help?
 
A It is possible to use grep for this: grep -v string file will output all lines that do not contain the string. But sed is a more suitable tool for batch editing.
 sed --in-place '/some string/d' myfile

 will delete all lines containing 'some string' To process a collection of files, you need to use a for loop (or find) because sed 's --in-place option only works on single files.
 One of these commands will do it:
 
  for f in *.txt; do sed --in-place '/some string/d'
 "$f"; done
 find -name '*.txt' -exec sed --in-place=.bak '/some
 string/d' "{}" ';'
 
Adding =.bak in the latter example makes sed save a backup of the original file before modifying it.

 

=========================================

Nagaan welke libraries worden gebruikt door een applicatie.

ldd -v $(ls)

=> overzicht alle gebruikte libs..

=========================================

Vind alle soft links terug en verwijder alleen de soft links

1 => overzicht tonen:
ls -l `find -type l`

2 => verwijderen
rm `find -type l`

=========================================

folders/files vergelijken op verschillende servers

Op de server srv1 als voorbereidende stap :

Kopieer gewenste folder met files ,subdirs als inhoud naar /tmp/kl_dest

Op de andere server

Maak je eveneens een folder aan /tmp/kl_src

Waarvan je de inhoud van wilt vergelijken tss. beide servers:

vervolgens tik je in op srv1

rsync -r -a -v -e "ssh -l nsisc" --delete /tmp/kl_dest /ds2:/tmp/kl_src

zo ga je op srv2 inloggen en dan volgende actie uitvoeren:

diff -q ./tmp/kl_src /sourcefolder


en stel je de verschillen vast tss. fodlers op beide systemen

Echter deze methode is alleen bruikbaar als je in folders kan schrijven.

2)

Vergelijken van files op twee verschillende servers:

ssh ds2 "cat /folder/file" | diff - /folder/file


3) vergelijk files op 2 servers mbv md5sum :
find /etc/init.d/ -type f -exec md5sum {} \; | sort -k2 > ./kl_cmp/etcinitd_md5

=========================================

Uitleg ivm display / screen


Probably you have an X-server running and there are some processes you are not aware of.

The ":0.0" is a way in X-Windows to specify where output of a program (a "X-client") should go. This is what the $DISPLAY-variable is for.

The generic form is

DISPLAY=<hostname>:<display-number>.<screen-number>

<hostname> is a normal hostname, specifying the hostname (or directly the IP-adress) of the host which should receive the output to display it.

<display> is the number of the display on this host. A display is one (or more, see below) screen(s), a mouse and a keyboard. In most cases this is 0 because hosts (like PCs) tend to have only one display, but back then hosts were big systems and had several displays attached to them so that many users could work simultaneously. For these hosts there had to be a way to specify which display was to be adressed.

<screen> is the number of the screen. If you are sitting in front of a PC with only one monitor this is always 0, but suppose you would have several monitors. In this case you would still have one "display", but this display would consist of several "screens". (If you are using one of these graphic cards which can use several monitors you might still have one screen which spans several monitors, but this is just a workaround for Windoze systems which couldn't adress several screens originally.) You number these screens (again starting at 0) and can so decide where the output should go. For instance, if you have 3 monitors "localhost:0.0" would adress your left monitor, "localhost:0.1" would adress the middle one and "localhost:0.2" the right one.

=========================================

(Simpele )FTP installeren en service runnen op een linux server

Ter info:
Vsftpd geinstalleerd op 10.1.7.248
Gebruik: service vsftp start /stop als root

=========================================

Een (groot) tar archive splitsen in kleinere delen en terug opbouwen.

1. splitten
Vertrek van Rel415.tar
size = 23 Mb
doel : in kleinere stukken onderverdelen en terug samenstellen

"split"

split -d --line-bytes=5m --verbose ./Rel415.tar Rel415_part
=> -d = nummered suffixes
 --line-bytes=5m dwz in 5megabyte chunks
 Rel415_part = stamnaam
 
2.samenstellen
-------------------------

mbv 'cat':

cat Rel415_part_0* > Rel415.tar

=========================================


How to perform real number calculation in shell script and store result to third variable

lets say a=5.66, b=8.67, c=a+b?

SRC: http://www.freeos.com/guides/lsst/ch08.html#q10


#!/bin/bash
#
# Linux Shell Scripting Tutorial 1.05r3, Summer-2002
#
# Written by Vivek G. Gite <vivek@nixcraft.com>
#
# Latest version can be found at http://www.nixcraft.com/
#
# Q10
#
a=5.66
b=8.67
c=`echo $a + $b | bc`
echo "$a + $b = $c"

=========================================

ip adress in RH5

nmblookup -A ip_address

vb.
[kurtl@V-RHEL5-RTAP ~]$ w
 10:08:09 up 136 days, 23:12,  2 users,  load average: 2.03, 2.07, 2.02
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
ns       pts/4    10.1.12.63       09:34   24:46   0.97s  0.03s -bash
kurtl    pts/65   lpt00103         09:50    0.00s  0.02s  0.00s screen

[ns@V-RHEL5-RTAP ~]$ nmblookup -A 10.1.12.63
Looking up status of 10.1.12.63
        LPT00156        <00> -         M <ACTIVE>
        FCSNTDOMAIN     <00> - <GROUP> M <ACTIVE>
        LPT00156        <20> -         M <ACTIVE>
        FCSNTDOMAIN     <1e> - <GROUP> M <ACTIVE>

        MAC Address = 00-22-64-73-74-E2


nmap might be worth looking into as well.

e.g.
nmap --script smb-os-discovery.nse -p445 hostname

=========================================

sed / insert a line in a text file


sed '34i\test' file.txt

That will enter word test at the appropriate line.

=========================================

screen

not possible when logged in with a second user account
except: when to allow sudo..
-> see sudo enable for a user above

ex.

[kurtl@V-RHEL5-RTAP ~]$ w
 11:28:46 up 132 days,  6:00,  3 users,  load average: 0.02, 0.04, 0.01
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
nsisc    pts/13   10.1.12.110      11:26    2:36   0.04s  0.04s -bash
nsisc    pts/4    10.1.16.107      09:44    0.00s  0.11s  0.03s sshd: nsisc [priv]
nsisc    pts/11   10.1.12.110      11:25    3:33   0.05s  0.05s -bash
[kurtl@V-RHEL5-RTAP ~]$ screen
Cannot open your terminal '/dev/pts/4' - please check.
[kurtl@V-RHEL5-RTAP ~]$ chmod 777 /dev/pts/4
chmod: changing permissions of `/dev/pts/4': Operation not permitted
[kurtl@V-RHEL5-RTAP ~]$ sudo chmod 777 /dev/pts/4
[kurtl@V-RHEL5-RTAP ~]$ screen
[screen is terminating]
[kurtl@V-RHEL5-RTAP ~]$

=========================================

histtimeformat

nagaan wanneer welke commandos zijn ingegeven :
bvb. wanneer de laatste keer het commando DTCL -i werd uitgevoerd:

export HISTTIMEFORMAT=”%F %T  “
history | grep DTCL -i

=========================================

Which linux distro are you using?

From the Boot Time messages     Fire up your favourite terminal program and type in the following

dmesg | head -1

The output would be similar to

Linux version 2.6.13-15-default (geeko@buildhost) (gcc version 4.0.2 20050901 (prerelease) (SUSE Linux)) #1 Tue Sep 13 14:56:15 UTC 2005

Using /proc/version     In the terminal type

cat /proc/version

The output would be like

Linux version 2.6.13-15-default (geeko@buildhost) (gcc version 4.0.2 20050901 (prerelease) (SUSE Linux)) #1 Tue Sep 13 14:56:15 UTC 2005

Using /etc/issue     This method gives the most appropriate answer

cat /etc/issue

The output should be like

Welcome to SUSE LINUX 10.0 (i586) - Kernel \r (\l).

 

Given a Linux harddisk, how can I find out the brand and version of the Linux OS installed?


Some distros put a '*-release' or '*-version' file
in /etc. Here are some examples:

/etc/redhat-release

=========================================

ls      Display or list all directories

Type the following command:
$ ls -l | egrep '^d'

Display or list only files
Type the following command:
$ ls -l | egrep -v '^d'

Task: Create aliases to save time
You can create two aliases as follows to list only directories and files.
alias lf="ls -l | egrep -v '^d'"
alias ldir="ls -l | egrep '^d'"

Put above two aliases in your bash shell startup file:
$ cd
$ vi .bash_profile

Append two lines:
alias lf="ls -l | egrep -v '^d'"
alias ldir="ls -l | egrep -v '^d'"
Save and close the file.

Now just type lf - to list files and ldir - to list directories only


=> To get just file names without the long list data:

* ls -l | grep '^d' | awk '{ print $9 }'
* find . -type d -maxdepth 1
* ls -d */
  or for hidden directories
  ls -d .*/

= >To get just the subdirectories names

  find . -type d -maxdepth 1 -exec basename {} \;

  However, in this case you also get the directory itself! To avoid this, add mindepth 1:

  find . -type d -maxdepth 1 -mindepth 1 -exec basename {} \;

=>
  (folders)
  ls -F | grep /
  (files)
  ls -F | grep -v /

=> Lists all the subdirectories in the current directory..

  ls -R | grep ./

=========================================

du / df

How to get total size of directory in shell?

du -s /dir
 
or

du -sh /dir

>> How to find - Size of a directory & Free disk space
 

http://www.codecoffee.com/tipsforlinux/articles/22.html


This article explains 2 simple commands that most people want to know when they start using Linux. They are finding the size of a directory and finding the amount of free disk space that exists on your machine. The command you would use to find the directory size is ' du '. And to find the free disk space you could use ' df '.

All the information present in this article is available in the man pages for du and df. In case you get bored reading the man pages and you want to get your work done quickly, then this article is for you.

-

'du' - Finding the size of a directory

$ du
Typing the above at the prompt gives you a list of directories that exist in the current directory along with their sizes. The last line of the output gives you the total size of the current directory including its subdirectories. The size given includes the sizes of the files and the directories that exist in the current directory as well as all of its subdirectories. Note that by default the sizes given are in kilobytes.


$ du /home/david
The above command would give you the directory size of the directory /home/david


$ du -h
This command gives you a better output than the default one. The option '-h' stands for human readable format. So the sizes of the files / directories are this time suffixed with a 'k' if its kilobytes and 'M' if its Megabytes and 'G' if its Gigabytes.


$ du -ah
This command would display in its output, not only the directories but also all the files that are present in the current directory. Note that 'du' always counts all files and directories while giving the final size in the last line. But the '-a' displays the filenames along with the directory names in the output. '-h' is once again human readable format.


$ du -c
This gives you a grand total as the last line of the output. So if your directory occupies 30MB the last 2 lines of the output would be

30M .
30M total

The first line would be the default last line of the 'du' output indicating the total size of the directory and another line displaying the same size, followed by the string 'total'. This is helpful in case you this command along with the grep command to only display the final total size of a directory as shown below.


$ du -ch | grep total
This would have only one line in its output that displays the total size of the current directory including all the subdirectories.

Note : In case you are not familiar with pipes (which makes the above command possible) refer to Article No. 24 . Also grep is one of the most important commands in Unix. Refer to Article No. 25 to know more about grep.


$ du -s
This displays a summary of the directory size. It is the simplest way to know the total size of the current directory.


$ du -S
This would display the size of the current directory excluding the size of the subdirectories that exist within that directory. So it basically shows you the total size of all the files that exist in the current directory.


$ du --exculde=mp3
The above command would display the size of the current directory along with all its subdirectories, but it would exclude all the files having the given pattern present in their filenames. Thus in the above case if there happens to be any mp3 files within the current directory or any of its subdirectories, their size would not be included while calculating the total directory size.

-

'df' - finding the disk free space / disk usage

$ df
Typing the above, outputs a table consisting of 6 columns. All the columns are very easy to understand. Remember that the 'Size', 'Used' and 'Avail' columns use kilobytes as the unit. The 'Use%' column shows the usage as a percentage which is also very useful.


$ df -h
Displays the same output as the previous command but the '-h' indicates human readable format. Hence instead of kilobytes as the unit the output would have 'M' for Megabytes and 'G' for Gigabytes.

Most of the users don't use the other parameters that can be passed to 'df'. So I shall not be discussing them.

I shall in turn show you an example that I use on my machine. I have actually stored this as a script named 'usage' since I use it often.

Example :

I have my Linux installed on /dev/hda1 and I have mounted my Windows partitions as well (by default every time Linux boots). So 'df' by default shows me the disk usage of my Linux as well as Windows partitions. And I am only interested in the disk usage of the Linux partitions. This is what I use :

$ df -h | grep /dev/hda1 | cut -c 41-43

This command displays the following on my machine

45%

Basically this command makes 'df' display the disk usages of all the partitions and then extracts the lines with /dev/hda1 since I am only interested in that. Then it cuts the characters from the 41st to the 43rd column since they are the columns that display the usage in % , which is what I want.

Note : In case you are not familiar with pipes (which is used in the above command) then refer to Article No. 24 . 'cut' is another tool available in Unix. The above usage of cut gets the the characters that are present in the specified columns. If you are interested in knowing how to mount you Windows partitions under Linux, please refer to Article No. 3 .

=========================================

TAR

tar -cvf naam.tar * => zal een tar archive aanmaken (verbose,compress,file)

tar -cxf naam.tar * => zal een tar archive extracten (verbose,extract,file)

[nsisc@E-DBS2 tmp]$ tar -cvf test.tar cleanuprc.py Manufacturer  // Maakt een archief met 2 bestanden
cleanuprc.py
Manufacturer

[nsisc@E-DBS2 tmp]$ tar -tvf test.tar     // Toont de lijst waaruit het tar-archief is opgebouwd
-r-xr-xr-x root/root       353 2009-02-10 14:02:59 cleanuprc.py
-rw-rw-rw- root/root        25 2009-08-27 00:01:46 Manufacturer
[nsisc@E-DBS2 tmp]$ rm -f Manufacturer  

[nsisc@E-DBS2 tmp]$ tar -xvf test.tar  Manufacturer   // Haal slechts een file op uit het archief
Manufacturer

 

Introduction
In a recent tutorial I demonstrated how to backup your data files using Tar, but what happens when the resulting file is too big to fit onto your chosen backup media (e.g. Zip disk or CD-ROM). Well you can use Tar to split up the file into manageable sizes that will fit onto your media, and span the file across multiple media volumes.

Splitting the File
The two extra command line options you need to use over and above the standard syntax are -M (--multi-volume) which tells Tar you want to split the file over multiple media disks. You then need to tell Tar how big that media is, so that it can create files of the correct size. To do this you use the --tape-length option, where the value you pass is number x 1024 bytes.

The example below shows the syntax used. Lets say the largefile.tgz is 150 Meg and we need to fit the file on two 100 Meg Zip drives.

tar -c -M --tape-length=102400 --file=disk1.tar largefile.tgz

The value 102400 is 1024 x 100, which will create a 100 Meg file called disk1.tar and then Tar will prompt for volume 2 like below :-

Prepare volume #2 for disk1.tar and hit return:In the time of tape drives you would have taken the first tape out of the machine and inserted a new tape, and pressed return to continue. As we want Tar to create the remaining 50 Meg in a separate file, we issue the following command :-

n disk2.tarThis instructs Tar to continue writing the remaining 50 Meg of largefile.tgz to a file named disk2.tar. You will then be prompted with the line below, and you can now hit return to continue.

Prepare volume #2 for disk2.tar and hit return:You would repeat this process until your large file has been completely processed, increasing the disk number in the filename each time you are prompted.

Putting the File Back Together
The process is similar when putting the large file back together from its split-up files. Below is the syntax used to re-create the large file from the disk1.tar and disk2.tar images.


Verwijderen van een file uit een tar-archief
--------------------------------------------
C:\tar>tar -x -M --file=disk1.tar largefile.tgz
Prepare volume #2 for disk1.tar and hit return: n disk2.tar
Prepare volume #2 for disk2.tar and hit return:

[ns@V-RHEL5-RTAP RCI]$ tar --list --file=testcps_16082010.tar
./Poortbediening
./tabbladen
./tab_extra
./tab_normaal
./tabtest
./testcps.tar
./tstmsg
[ns@V-RHEL5-RTAP RCI]$ tar --delete --file=testcps_16082010.tar testcps.tar
tar: testcps.tar: Not found in archive
tar: Error exit delayed from previous errors
[ns@V-RHEL5-RTAP RCI]$ tar --delete --file=testcps_16082010.tar ./testcps.tar
[ns@V-RHEL5-RTAP RCI]$ tar --list --file=testcps_16082010.tar
./Poortbediening
./tabbladen
./tab_extra
./tab_normaal
./tabtest
./tstmsg


tar zonder de subdirectories mee te nemen:
-------------------------------------------

You could do something like


Code:
ls -l | grep '^[^d]' | awk '{print $9}' | xargs tar cvf foo.tar
to exclude subdirectories too (providing you execute this command from within the directory you want tar'd).

=========================================

RSA

• [nsisc@E-DBS2 .ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/project/nsisc/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /project/nsisc/.ssh/id_rsa.
Your public key has been saved in /project/nsisc/.ssh/id_rsa.pub.
The key fingerprint is:
e0:b5:4b:be:3e:0b:2b:c6:bd:0d:8b:b3:af:38:2e:78 nsisc@E-DBS2
[nsisc@E-DBS2 .ssh]$

=========================================

ssh zonder paswoord

*voor <user1> van <systeem1> naar <user2> van <systeem2>


http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/5/html/Deployment_Guide/s2-openssh-generate-keypairs.html

kort:
log in als <user1> op <systeem1>
                1 malig (voor <user1>/<systeem1>):
ssh-keygen -t rsa
opmerking: 'ssh-keygen -t rsa' NIET doen als id_rsa.pub al bestaat: bestaande 'keypairs' zullen niet meer werken…
chmod 755 ~/.ssh


bij volgende kommando zul je nog aantal keer paswoord van <user2>@<systeem2> moeten opgeven
                scp .ssh/id_rsa.pub <user2>@<systeem2>:wis ; ssh <user2>@<systeem2> "chmod 644 .ssh/authorized_keys ; cat wis >> .ssh/authorized_keys ; rm wis"
                test bv. Door onderstaand cmd als <user1> op <systeem1> uit te voeren. Als alles correct is, zou je geen paswoord moeten invoeren.
ssh <user2>@<systeem2> ls -l

 

=========================================

X11 forwarding

Situatie :

Werkplek : lpt00103
EDBS2 : inlog SRV
DS1 : X11 output wanted


Progress :  DS1 proberen RtapPtDisplay te runnen.
Slaagt niet:
[nsisc@E-DIS1 ~]$ xclock
X11 connection rejected because of wrong authentication.
X connection to localhost:11.0 broken (explicit kill or server shutdown).

De X11forwarding-flag  is gezet /etc/ssh/ssh_config nochtans.

OPL WB : inloggen als nsisc op edbs2 en vervlogens als nsisc op DS1,vruchteloos :

[nsisc@E-DIS1 ~]$ xclock
X11 connection rejected because of wrong authentication.
X connection to localhost:11.0 broken (explicit kill or server shutdown).

 .Xauthority file komt niet voor in homedir van user nsisc op DS1 ,daartoe kopieren:

[nsisc@E-DBS2 ~]$ scp .Xauthority nsisc@DS1:/~
nsisc@ds1's password:
profile.d done
[nsisc@E-DBS2 ~]$ ssh DS1
nsisc@ds1's password:
Last login: Fri Mar 27 15:38:42 2009 from e-dbs2.dt
/usr/bin/xauth:  timeout in locking authority file /project/nsisc/.Xauthority
[nsisc@E-DIS1 ~]$

=========================================

Linux/UNIX: Find Out If File Exists With Conditional Expressions

With the help of BASH shell and IF command it is possible to find out if file exists or not. Generally, this is known as conditional expressions. Conditional expressions are used by the [[ compound command and the test and [ builtin commands to test file attributes and perform string and arithmetic comparisons. General syntax:

[ parameter FILE ]
OR
test parameter FILE

Where parameter can be any one of the following:

-e: Returns true value if file exists
-f: Return true value if file exists and regular file
-r: Return true value if file exists and is readable
-w: Return true value if file exists and is writable
-x: Return true value if file exists and is executable
-d: Return true value if exists and is a directory
Examples

Find out if file /etc/passwd file exists or not
Type the following commands:
$ [ -f /etc/passwd ] && echo "File exists" || echo "File does not exists"
$ [ -f /tmp/fileonetwo ] && echo "File exists" || echo "File does not exists"
Find out if directory /var/logs exists or not
Type the following commands:
$ [ -d /var/logs ] && echo "Directory exists" || echo "Directory does not exists"
$ [ -d /dumper/fack ] && echo "Directory exists" || echo "Directory does not exists"
You can use conditional expressions in a shell script:

#!/bin/bash
FILE=$1
 
if [ -f $FILE ];
then
   echo "File $FILE exists"
else
   echo "File $FILE does not exists"
fi
 Save and execute the script:
$ chmod +x script.sh
$ ./script.sh /path/to/file
$ ./script.sh /etc/resolv.conf
You can use this technique to verify that backup directory and backup source directory exits


=========================================

Creeer/verwijder een softlink

[nsisc@V-RHEL5-RTAP tmp]$ mkdir folder
[nsisc@V-RHEL5-RTAP tmp]$ touch destfile
[nsisc@V-RHEL5-RTAP tmp]$ cat > ./destfile
testwoord
[nsisc@V-RHEL5-RTAP tmp]$ ll
total 21676
-rw-r--r-- 1 nsisc rtap       10 Dec 14 10:29 destfile
drwxr-xr-x 2 nsisc rtap     4096 Dec 14 10:27 folder
drwx------ 2 root  root     4096 Feb 26  2009 keyring-HgicQK
srwxrwxrwx 1 lian  rtap        0 Apr 12  2009 mapping-lian
srwxr-xr-x 1 root  root        0 Apr 15  2009 mapping-root
drwx------ 2 nsisc rtap     4096 Nov  4 13:05 orbit-nsisc
drwxr-xr-x 8 root  root    16384 May  1  2008 rh5_dvd
srwxr-xr-x 1 root  root        0 Mar 30  2009 sound-juicer.root.2934078116
drwxr-xr-x 8 nsisc rtap     4096 Dec  6 15:13 unl
-rw-r--r-- 1 nsisc rtap 22128640 Dec  6 14:35 unl_db_rapl_06DEC_2009.tar
[nsisc@V-RHEL5-RTAP tmp]$ ln -s ./destfile ./folder/srcfile
[nsisc@V-RHEL5-RTAP tmp]$ ll ./folder/
total 0
lrwxrwxrwx 1 nsisc rtap 10 Dec 14 10:30 srcfile -> ./destfile
[nsisc@V-RHEL5-RTAP tmp]$ ln -s /tmp/destfile ./folder/srcfile
ln: creating symbolic link `./folder/srcfile' to `/tmp/destfile': File exists
[nsisc@V-RHEL5-RTAP tmp]$ rm -f /tmp/folder/srcfile
[nsisc@V-RHEL5-RTAP tmp]$ ln -s /tmp/destfile ./folder/srcfile
[nsisc@V-RHEL5-RTAP tmp]$ ll ./folder/
total 0
lrwxrwxrwx 1 nsisc rtap 13 Dec 14 10:31 srcfile -> /tmp/destfile
[nsisc@V-RHEL5-RTAP tmp]$
[nsisc@V-RHEL5-RTAP tmp]$ cat /tmp/folder/srcfile
testwoord
[nsisc@V-RHEL5-RTAP tmp]$

=========================================

linux login history

How can I display the login history which shows the time and date of when any user logged in?

I know that 'history' shows all of the commands used ... etc but I want the user and log in times.

1)
type in:
last

2)
cd /var/log

#cat secure* | grep Accepted > login.txt
The * is to read from the backup logs also omit if you don't want to see those
this will show all successful logins
you can also use sshd in place of Accepted to show all attempts and Accepted

then
#pico login.txt
or nano or your other favorite text editor to read
winstonMay 25 2004, 11:42 AM
Aside from 'last' there's also 'who' which tells you who's on right now. You can use 'finger ' to get more information on a user.

=========================================

Probleem in de Unix omgeving

De regels worden op één lijn afgeprint,RtapPerfMon bvb. laat één outputregel zien.
Ook vi laat allerlei garbage tekens zien naast het feit ook één regel.

=> C-shell : setenv TERM vt100
=> KSH : export TERM=vt100

=========================================