Jump to content


Tips for Linux Explorers


  • This topic is locked This topic is locked
375 replies to this topic

#51 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 28 April 2003 - 06:06 PM

FSCK
( filesystem check )  

Every 20 to 30 times you boot up your computer, after an improper shutdown or power-faillure, the system will perform a filesystem check.  

In most cases no problem, however, sometimes in rare cases it may ask you if you want to repair inconsistencies; you press "y" and "Enter" a few times and it will proceed booting.  

In some very rare cases it will tell you that you have to do a manual fsck and give you a prompt: ( Now you have to know what partition ( hda? ) was the critical one ! )
# fsck -p /dev/hda?
  (replace the "?" with the number of the partition ) The "-p" stands for repair automatically.

# e2fsck -f /dev/hda?
(replace the "?" with the number of the partition ) e2fsck is a modern, more powerfull version of fsck. The "-f" option forces a more elaborate check.

Sometimes however the system tells you to do the check without the "-p" argument, this just means you will have to say "y" a lot of times ! :)  

In some very, very rare cases an emergency console will come up, just do the above at the prompt and when done close the console with < Ctrl+d >, the system will continue booting.  

If you get these errors often:
# e2fsck -c /dev/hda?
  
( This will mark bad blocks on your HD and no more data will be written in those blocks. )  

( !!! fsck and e2fsck should only be performed on unmounted partitions !!!! )

In very, very, very rare cases a "Super-Block" might get damaged:  
( First make some strong coffee !  :) )  

A super-block is the first block of each ext2 or ext3 partition. It has important data about the file system, like size, free space, etc.  

A partition with a damaged super-block cannot be mounted. But, ext2 and ext3 keep several super-block backup copies scattered over the partition.  

Boot your system with a boot disk.  ( I hope you did make one ! ) The location of the super-block backup copies depends on the block size of the file system.  

For file systems with 1 KB block size it is at the beginning of each 8 KB (8192 bytes), for file systems with 2 KB sizes it is at the beginning of each 16 KB (16384 bytes) and so on.  

You can use
# mke2fs -n /dev/hda?

to find out at which byte positions the super-block copies are. With a 1 KB block size, the first backup copy is in byte number 8193 (  8192+1 ).  

To restore the super-block from this copy, do
# e2fsck -b 8193 /dev/hda?
  

If that block also happens to be damaged, try the next one at byte number 16385, and so on until you find a good one.  

Reboot to activate the changes.  

B) Bruno

#52 OFFLINE   quint

quint

    Linux Miner

  • Forum MVP
  • 3,898 posts

Posted 28 April 2003 - 06:38 PM

Quote

( !!! fsck and e2fsck should only be performed on unmounted partitions !!!! )
:unsure: How do you do this, Bruno? Just when I think that I'm starting to grasp a few things, I see that it's like grasping water (to me). :( Hope you don't mind, but I'm printing out this entire thread; by Christmas it should be enough for a novelette. :unsure:
~ Linux User # 314972 ~ Ubuntu User # 12930 ~

If you tell the truth you don't have to remember anything.
                -- Mark Twain



#53 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 28 April 2003 - 06:50 PM

Quint, no problem !In the cases mentioned above the partitions are not mounted yet ! The warning is just to let you know that once the system is finished booting and you are logged in, you might think: hey, let's open a console and try that filesystem-check stuff, to get used to the procedure, so that in case stuff goes bad I know what to do. See, that's a bad idea ! That was what I was warning for !:unsure: Bruno

#54 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 28 April 2003 - 06:54 PM

Quint, in addition to above:Printing is no bad idea, once your computer starts acting wierd you might be unable to read this on line !:unsure: Bruno

#55 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 29 April 2003 - 01:35 PM

TWEAKING THE PROMPT  

There is a big chance your command prompt will look like this: [localhost.localdomain:~]$ , or if your computer is on a network or has a name: [localhost.vector:~]$. It's functional, but if you're like me you won't be happy with it.  

You can customize the prompt into something short and fancy, like  [bruno:~]$ , ( ~  stands for the current directory and will change as the directory you are in changes ) here is how to do it:  

First backup the current prompt  
$ SAVE=$PS1

If after tweaking you want the old one back  
$ PS1=$SAVE

These are the codes we will use:  
\u = username of current user
\w = current directory
\h = first part of the hostname
\H = the full hostname
\d = the current date
= the current time 24hrs format
\T = the current time 12hrs format
@ = @  

Now we can edit the ".bashrc" file ( dot bashrc ):  
$ vi /home/bruno/.bashrc

< i >  ( insert mode )
Leave the first few lines as they are.
PS1="[\u:\w]$ " ( a space between the $ and " )  ( this will set the prompt like mine above )
< Esc >
< ZZ >
Close the console, open it again and you'll see the prompt has changed !  

Some examples:
PS1="[\H:\w]$ "   will give the old   [localhost.localdomain:~]$
PS1="[\u:\d @\w]$ "   will give   [bruno: Tue Apr 29 19:04:59 @~]$
PS1="[ \u@\w]$ "   will give   [19:04:59 bruno@~]$  

If all this was way to easy for you :) and you want something really different, with colors and shapes, have a look  Here
More basic info Here

Your 'root' prompt will not be changed, this makes it even more easy to notice the difference between being root and current user !

B) Bruno

#56 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 29 April 2003 - 04:13 PM

BASH HISTORY  

As we are doing more and more commands at the bash-prompt it's time to learn a neat little trick:

As you are at an empty prompt press the "arrow-up" key and you will see the previous command you typed in !  
Press again, and again, and again, see all the commands that were stored in the "bash-history"

As current user you will only see the commands you typed in, as root you will see the commands you typed in as root.

More fun, type in:  
$ history
  And you'll get a full numbered list of all stored commands

$ !8
  Will get you number 8 of that list

$ !v
And you will get the last command that started with v

Ctrl+R will let you do a search in the history Bash history won't be lost at reboot or shutdown, clever isn't it ?  

B) Bruno

#57 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 29 April 2003 - 06:30 PM

BASH SCRIPT

Keeping it simple: You know by now that < rm > removes a file, permanently !
Wouldn't it be nice if we could move it to the recycle bin with a simple command instead ?

We're gonna make that command and call it: < del >  
( YES ! making our own commands ! :D )  

First a little script:  
$ vi /usr/bin/del

< i >
Here is the text for the script:
#!/bin/bash
mv $1 ~/Desktop/Trash
#End script

< Esc >
< ZZ >

Make it executable
# chmod 0775 /usr/bin/del

Now if we do
$ del tessst
( It will execute the script and do the same as: )

$ mv tessst /home/bruno/Desktop/Trash
  

Sure this was a very short example, a 3 line script, it only holds one command, but you could put as many lines in the script as you want and execute it with a four letter word. :)
If there are more commands in the script it will execute them in the order that they are noted down.  

Because /usr/bin is in your "path" you only have to type "del" to execute it.  

If you have to do complicated commands in a certain order on a regular basis, make a little bash script, put it in your "path" and give it a name that's easy to remember.  

Next time we'll make a simple backup script, to backup and gzip the contents of your /home directory.  

More about bashscripts see: Introduction to bash Shell Scripting

B) Bruno

#58 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 30 April 2003 - 01:46 PM

SIMPLE BACKUP SCRIPT  

Be one step ahaid and backup your /home directory from time to time.
There are many different ways to do this, in Mandrake you can go to the Mandrake Control  Center and use drakx to do this automated on a regular basis.  

However we could also make a simple script: :)
$ su < password ># vi /usr/bin/backup
< i >  
Now, this is the text in that script:
#!/bin/bash
rm ~/backup.tar.gz  #( removes old backup if there is one )
BACKUP_DIRS=$HOME
tar -cvzf backup.tar.gz $BACKUP_DIRS
#end script
< Esc >
< ZZ >

Make it executable:
# chmod 0755 /usr/bin/backup
  

And a script to restore the backup:  
# vi /usr/bin/restore

< i >  

The text in the script:
#!/bin/bash
BACKUP_SOURCE_DIR="backup.tar.gz"	
tar -xvzf $BACKUP_SOURCE_DIR
#end script
< Esc >
< ZZ >

Make it executable:
# chmod 0755 /usr/bin/restore
< Ctrl+d > ( return to normal user )  

Right, that's it, we have made two scripts!
Now if we type backup at the prompt it will create a tar.gz file in your home directory.
And restore will restore the backuped files.
Remember before making your next backup to delete the old one first !  

B) Bruno

#59 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 30 April 2003 - 02:22 PM

GKRELLM MAILCHECK and SOUND  

The mail configuration file of the Gkrellm system monitors ( giga cool ! ) could give you a major headache, particularly with the sound notification.  

It's surprisingly simple though.  

On the setup tab of the mail section:
- Mail reading program  =  evolution ( or whatever program you prefer )
- Notify ( sound ) program  =  /usr/bin/play  /home/bruno/sounds/newmail.wav ( needles to say: the path to your soundfile is up to you ) If "/usr/bin/play" gives problems you can use "/usr/bin/artsplay" too.
- Check local mailboxes  =  300 sec - Do remote checks every  = 2 minutes  

On the mailboxes tab:
- Select "remote mailbox" and you can fill in the pop server, username and password. Press add and do the next one if you've got more then one mail address to be checked.  

The rest of the tabs won't give you any problems.  

Now sit back and wait for the mail to arrive !  

B) Bruno

#60 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 30 April 2003 - 03:38 PM

UGLY FONTS IN OPEN OFFICE.org  

Lot's of people complain about the ugly fonts in the OpenOffice.org menu's.
They don't bother me, but then . . . . . . I changed them  B)  

Here is how to do it:
Go to  --> Tools --> Options --> OpenOffice.org --> Font replacement
Click on "Andale Sans UI" and you will see "Andale Sans UI" appear in the "Font" box, in the "Replace" box choose "Helvetica" and apply.

No more squinting eyes !  

B) Bruno

#61 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 30 April 2003 - 06:22 PM

DISABLE THE OPEN OFFICE.org SPLASH SCREEN

Here is another really simple one:  

$ su < password ># mcedit /usr/lib/openoffice/program/sofficerc
set the Logo to " 0 "

NOTE: for OpenOffice 2.0 the sofficerc is in "/usr/lib/ooo-2.0/program/sofficerc" or "/opt/openoffice.org2.0/program/sofficerc"

If only life itself was sOOo simple . . . . . . . :)

B) Bruno

#62 OFFLINE   LilBambi

LilBambi

    Australisches Googler

  • Forum Admins
  • 21,441 posts

Posted 30 April 2003 - 06:54 PM

Bruno -Wow, You have been busy!Lots of great tips!  B)
Bambi
AKA Fran

Posted Image
My Public Key for Email :: BambisMusings Blog :: Fran's Computer Services Blog :: MyPassionIsBooks Blog :: 5BuckReview :: CNIRadio
"The Net interprets censorship as damage and routes around it." ~John Gilmore (Time Magazine, Dec 6, 1993)

#63 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 30 April 2003 - 08:14 PM

LilBambi:  Just giving you all some work-out for the brain, ;)  My Mandrake 9.1 PowerPack will come in any day now and I'll have to take the system down for a day. New software, new hardware, network set-up, major tweakwork on this box. So while I'm bussy, I don't want all of you to get bored. :D B)  Bruno

#64 OFFLINE   LilBambi

LilBambi

    Australisches Googler

  • Forum Admins
  • 21,441 posts

Posted 30 April 2003 - 08:30 PM

Cool Bruno ... would love to hear how it goes when you do your new 9.1 PowerPack installed B)
Bambi
AKA Fran

Posted Image
My Public Key for Email :: BambisMusings Blog :: Fran's Computer Services Blog :: MyPassionIsBooks Blog :: 5BuckReview :: CNIRadio
"The Net interprets censorship as damage and routes around it." ~John Gilmore (Time Magazine, Dec 6, 1993)

#65 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 01 May 2003 - 04:58 PM

IMPORTANT CONFIG FILES AND DIRECTORIES  

They say that Linux is tweaker's heaven, here is why:
All of the configuration files are readable and quiete easy to understand, here is a list of the most common files and  a short description what they are about. ( go on, do have a look with "cat" )  

/etc/bashrc =settings for the bash shell trough the system  

/etc/crontab =setting for the cron-jobs ( remember the jobs that run in the middle of the night ? )

/etc/cups =the printer settings ( if you use lpr instead of cups: /etc/printcap )  

/etc/fstab = filesystem table  

/etc/inittab = the default runlevel  

/etc/lilo.conf = the configuration of the boot loader ( /boot/grub if you use grub instaed of lilo )  

/etc/modules.conf = the modules to load at boot  

/etc/profile = programs started at boot  

/etc/rc.d = the different runlevels and shotcuts to programs to load at that level  

/etc/ssh = the ssh settings for secure remote acces  

/etc/X11/XF86Config = the X configuration ( GUI )  

~/.bash_profile = aliases and variables for the bash shell  

~/.bashrc = personal settings for the bash shell  

~/evolution = your mail, adresses and settings for evolution  

~/.galeon = you bookmarks and settings for galeon  

~/.gnome = your personal gnome settings  

~/.gnome2 = more gnome settings  

~/.kde = your peronal settings for kde  

~/Mail = here are your mail and mail settings if you use kmail  

~/.mozilla = personal mozilla settings, bookmarks etc.  

~/.ssh = personal ssh settings  

~/.exrc = your settings for the vi editor  

We will have a good look at these files and what clever tricks we can do with some of them, later in the thread !

B)  Bruno

#66 OFFLINE   havnblast

havnblast

    Discussion Deity

  • Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 4,878 posts

Posted 02 May 2003 - 11:50 AM

Quote

Be one step ahaid and backup your /home directory from time to time. There are many different ways to do this, in Mandrake you can go to the Mandrake Control Center and use darkx to do this automated on a regular basis.
Should darkx be drakx?  - I just want to verify that?

#67 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 02 May 2003 - 12:53 PM

havnblast:Oeps, typo . . . . . . . . . . changed it ! Thanks havnblast, I knew I could count on you people to get the typo's ouwt  ;) oeps, out. ! :unsure: Bruno

#68 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 02 May 2003 - 04:23 PM

RUNLEVELS  

As your system boots-up it goes through several "run-levels"
We're going to shed some light on how all this works, not changing anything yet, just having a quick peek.  

There are 7 different run-levels:  

0.) Shutdown, complete stop  

1.) Single user mode, only for troubleshooting and system recovery  

2.) Multi-user mode, without networking  

3.) Multi-user mode, with networking  

4.) Not used, you could create your own runlevel here ( ! In Slackware like 5 ! )

5.) Multi-user mode with GUI, your normal X desktop  ( ! Not in Slackware ! )

6.) Restart  

O.K. we're starting the tour, not using the console this time but by simply clicking a few icons
Home --> /etc --> /rc.d  ( rc.d ! not the other rc's !! )  

Now, here you'll see them: "/rd0" to "/rc6" and some special files like "rc.local" and "rc.sysinit".
Click on "rc5" to open it; here you'll see a bunch of symbolic-links ( shortcuts ) they all are linked to a program to start or stop in runlevel 5. Have a good look, you will notice they start with a "K" or" S" and a number. The number gives the order of execution the "K" stands for Kill the "S" for Start. ( some services started earlier or in other runlevels are stopped here, because the only had to run to boot the system. )  

We go one step back to /etc/rc.d and have a look at the "rc.local" file, right-click on it and choose "Preview in Embedded KDE Advanced Text Editor Component" that's a safe way to have see the file.  
"rc.local" is a script where you could add your own lines of code at the bottom in order to get a program started at boot in the last runlevel. ( see the "#!/bin/sh" on the first line ? This is no bash script but a shell script !   )  

NOTE: remember the Multi Media key's ? There we did put a script in "~/.kde/Autostart", in order to startup with KDE. This is useless if you run a more exotic window manager ! In that case "rc.local" is the place to add the code.  

The file "rc.sysinit" also located in /etc/rc.d controls the runlevel procedure and is the first file loaded at boot, so you better don't fidddle around with this one !!!  Preview in the "Embedded KDE Advanced Text Editor Component" can't hurt though ! The "rc.sysinit" look familiar and starts with "#!/bin/bash"  we know that one already ! While you're at it look at the "rc" and "rc.modules" too, they speak for themselves.  

Now you know what's going on as you boot your system !  

B) Bruno

#69 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 04 May 2003 - 07:59 AM

NOTE FROM THE EDITOR:

It looks like some commands given in the text Multi Media Key's text don't work anymore in Mandrake 9.1 ( they did in 9.0 ).  These were the old commands for "Reboot" < shutdown - r now > and "Stop" < shutdown - h now >. In the case of "Reboot" the solutions is simple: < reboot >, for the command of "Stop"

I'm still scratching my head, "sudo" does not seem to work nor does "-su", but as soon as I find the trick it will be added in the text.

B)  Bruno

#70 OFFLINE   charlie

charlie

    Message Mogul

  • Members
  • PipPipPipPipPip
  • 428 posts

Posted 04 May 2003 - 01:10 PM

Hi  Thanks to all who contributed to the execellent information on the linux commands .  Copied and pasted it into a text editor and have quite a few printed pages , Now to digest all the material.     I have used the text editor vi before and some of my PC friends have suggested that it is the Linux equlivent of the dos text editor edlin , but it works and is always there when you need it I have found out during installation of Linux with a high speed connection that if the siginal is looped through a router  it picks up all the information and after installation and reboot you are connected to the net .  Also a good hard ware fire wall.    An associate and I spent quite an amount of time getting tar to work , using the man and help files , we still didn't figure out how to eliminate the iso file in the backup  Keep yp the execellent work there are many who are unhappy with Windows and from the experince I have had it is an excellent alternativePS excuse the typos , have the same problem in the command line  :D charlie

#71 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 04 May 2003 - 01:23 PM

Hi Charlie, thanks for your input. Always great to hear some feedback.Could you be a bit more clear on:

Quote

we still didn't figure out how to eliminate the iso file in the backup
Sugestion: start up a new thread explaining us the probelm, we'll be glad to help.PS never mind the typo's I make plenty of them and correct them the next day :D :D  Bruno

#72 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 04 May 2003 - 03:49 PM

FILE PERMISSIONS  

In Linux we talk about "users" and "groups" I'm sure you know about this.
They have different permissions regarding access to files. There is a clever way to see how permissions are set.  

Remember the command  "ls" it gave a list of all files in the directory you"re in, "ls -a" even did show all the hidden files as well.  
$ ls -l
  
( Will give you the files in "long" format, try: )
$ ls -l /etc/gnome/gnomerc
  

This is what you will get:  

Quote

-rwxr-xr-x    1 root root   484 Feb 25 14:08 /etc/gnome/gnomerc

This does look a bit complicated but it really isn"t. The first 10 characters are built up like this:  
- | rwx | r-x | r-x  

The first one tells you whether it is a file ( - ) a directory ( d ) or a link ( l )
The next three are for the "user" "r"ead "w"rite and e"x"ecute. The next three for the "group" and the last three for all "others"  

The next 1 stands for the number of links to the file. The owner. The group. The size in bytes. The date and time of the last modification to the file.  And the name of the file.  
$  ls -al /home/bruno

Will give a long list of all the files in your home directory and their permissions.
The list is even to long for your screen:
"ls -al /home/bruno >permissions"
Places a textfile called permissions in your home directory, do print it out for further inspection, there is a lot to learn there.

B)  Bruno

#73 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 04 May 2003 - 05:47 PM

CHANGING FILE PERMISSIONS  

Changing the permissions can be done with names and numbers, I like the numbers:
( do you remember the chmod 755 command from a few posts ago ? )  
# chmod 754 filename
( Will put the file to rwx r-x r-- )

Here is why:  
4=read 2=write 1=execute.
The three numbers in the chmod above are for the "user" ( the first number ), "group" ( the second number ) and "others" ( the third number )  

So if I want to give the user all permissions: 4+2+1=7
and i give the group read an execute permissions: 4+1=5
and all others only read permission 4=4  

Chown and chgrp are two commands also related to permissions:  
# chown
( Changes the owner of the file. )

# chown anna tessst
  
( Changes the owner of the file tessst from bruno to anna )

# chgrp
( Changes the group ownership of a file - if you did change the user and the user belongs to another group - ).

If you want to change both user and group at the same time you can do it this way:
# chown anna:anna tessst
( This changes the owner to anna and the group to anna )

You want to do the same but for a directory full of files:  
# chown -R anna:anna tessst

Well, this will give you enough exercise for this sunday, tomorrow we will go into hardlinks and symlinks, another little brain-teaser

B) Bruno

NOTE: Next to the method described above there is a second way to change permissions:

Quote

chmod takes either the decimal representation of the permissions or a symbolic representation. The symbolic representation is [ugoa][+-][rwx]. This is one of the letters u (user=file owner), g (group), o(others), a(all=u and g and o) followed by + or - to add or remove permissions and then the symbolic representation of the permissions in the form of r(read) w(write) x(execute). To make the file "file.txt" writable for all you type: "chmod a+w   file.txt"


#74 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 05 May 2003 - 11:05 AM

TWEAK EVOLUTION  
( what browser should open as you click on a link in an email )  

I had this problem, I really do like Evolution for my mail and it used to open the links send to me in an email in Galeon, a nice fast browser.
Suddenly with the new Mandrake 9.1 it opened the links in Mozilla, that's a much slower browser.
So I found the tweak :  
$ gnome-control-center

A window will pop up, go to the "Preferred Applications" and there set the default browser to the one you prefer.

Start or restart Evolution and notice the difference

B)  Bruno

#75 OFFLINE   Bruno

Bruno

    Le Professeur Pingouin

  • Admin Emeritus
  • 37,904 posts

Posted 05 May 2003 - 02:35 PM

HARDLINKS AND SYMLINKS

Today we will test your virtual imagination capabilities !

The main difference between hardlinks and symlinks ( symbolic or softlinks ) are:
1.) You cannot make a hardlink to a directory.
2.) If you remove the original file of a hardlink the link will still show you the content of the file.
3.) A symlink can link a directory
4.) The symlink is useless as you remove the original file.

All this might seem hard to grasp, but let's explain:

Hardlinks

A little experiment to show the case.
$ mkdir Test
( Making a new directory for our test )

$ cd Test
( Move in the directory )

$ vi fileA
( Make a file called fileA )

< i >
Type in some funny lines of text
< Esc >
< ZZ > ( save the file )

So, we made a "fileA" in a new directory called "Test" in your /home.
$ ln fileA fileB
  
( Making a hardlink )

$ ls -il fileA fileB
( The "i" argument will show the inode on the HD )

This is what you get:

Quote

1482256 -rw-r--r-- . . . 2 bruno . . bruno . . . . 21 May  5 15:55 fileA1482256 -rw-r--r-- . . . 2 bruno . . bruno . . . . 21 May  5 15:55 fileB

Here you can see that both fileA and fileB have the same inode number ( 1482256 ), also both files have the same file permissions and the same size, because that ´size´ is on the same inode it does not consume any extra space on your HD !

Now if we would remove the original "fileA"
$ rm fileA

and have a look at the content of the "link" fileB
$ cat fileB

you will still be able to read the funny line of text you typed. ( MAGIC ! )

Symlinks

Staying in the same test directory as above we make a symlink:
$ ln -s fileB fileC
$ ls -il fileB fileC

This is what you´ll get:

Quote

1482256 -rw-r--r-- . . . . . 1 bruno . . bruno . . . . 21 May  5 15:55 fileB1482226 lrwxrwxrwx . . . 1 bruno . . bruno . . . .  5 May  5 16:22 fileC -> fileB

You´ll notice the inodes are different and the link got a "l" before the rwxrwxrwx . The link has different permissions than the original file because it is just a symbolic link, its real content is just a string pointing to the original file. The size of the symlink ( 5 ) is the size of it´s string.
$ cat fileB

and
$ cat fileC

Will show the same funny text.

Now if we remove the original file:
$ rm fileB

and check the Test directory
$ ls

you will see the link fileC is still there, but if we do
$ cat fileC
it will tel you that there is no such file or directory !!

Though
$ ls -il fileC

will still give you:

Quote

1482226 lrwxrwxrwx . . . 1 bruno . . bruno . . . .  5 May  5 16:22 fileC -> fileB

But the link is obsolete ! ( hope you´re still with me )

O.K. The test is over, you can delete the Test directory

$ cd .. $ rm -rf Test
( "r" stands for recursive "f" is force )

WARNING: < rm -rf > is very powerfull, if ever someone wants to play a trick on you and tells you to do < rm -rf / > as root, you will loose all your files and directories on your / partition, thus have an empty HD !!! :(

Not dizzy yet ? Wait till next week when we come to the real stuff !

B) Bruno




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users