span.fullpost {display:none;}

Wednesday, October 1, 2008

FILE PERMISSIONS in Linux

In Linux we talk about "users" and "groups" I´m sure 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.
CODE
$ ls -l


( Will give you the files in "long" format, try: )


CODE
$ ls -l /etc/gnome/gnomerc



This is what you will get:


QUOTE (Text @ Screen)
-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.


CODE
$ ls -al /home/deadmix


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/deadmix >permissions"
Places a textfile called permissions in your home directory, do print it out for further inspection, there is a lot to learn there.


Photobucket






Read more!

Ctrl+C ( Stop Processing Command )

Imagine you just typed in a command and hit the Enter-key . . . and
suddenly you realized it was the wrong command and it is copying the full
hda8 partition into a plugins directory . . . how do we stop the command
from processing ??

Crtl+C

And the command will stop its insane work instantly . . . . sure a bunch
of files will already have been copied, but you do not have to wait the
full 15 minutes until it has finished.

Any command given in the terminal can be stopped like this, a search for
rootkits, a virus scan, updatedb . .you name it, all things that take
long enough to give you time to think . . and say "Ouch ! I did it
wrong, I have to stop this !"


Photobucket






Read more!

TAB COMPLETION

This has been in The Tips before, but got lost at the end part of another tip: ¨searching¨ . . Just because it´s such a handy feature of the commandline and because many members are struggling to get the commands typed correctly . . . here it is again:
The Tab key autocompletes on the commandline, you type a few characters and press the Tab key and the command or the name of the file will be completed:
Try this, "cd /u" and press tab now add an "s" and press tab, give an "h" and press tab, now we have got "cd /usr/share/" OK lets go on, type a "f" "o" "n" tab "t" tab "d" tab. <> Now we are in /usr/share/fonts/ttf/decoratives. "ls" will give you a list of all the fancy ttf fonts on your system.

So next time you have to type a long command like this:


CODE
# cp synthesis.hdlist.update_source.cz /var/lib/urpmi/synthesis.hdlist.update_source.cz


You type:


CODE
# cp sy ( tab ) ( space ) /v ( tab ) li ( tab) u ( tab ) sy ( tab )



And you will see that the full command is on your screen ( This command works only if the file "synthesis.hdlist.update_source.cz" is in your /home direcotry )


More on the Tab key and commands:

If you don´t remember exactly how a command was written, type in the first character or two and hit the tab, you will get a list of all the commands that start with that character(s).

If you wish to know what a certain command does ( ex: mkmanifest ), type:


CODE
$ whatis mkmanifest


This is what you get back to the screen :


QUOTE (Text @ Screen)
mkmanifest (1) - makes list of file names and their DOS 8+3 equivalent


All Linux commands and their descriptions can be found at O'Reilly


Photobucket






Read more!

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 ! )

First a little script:


CODE
$ vi /usr/bin/del


"i"
Here is the text for the script:


QUOTE (Text @ Script)

#!/bin/bash
mv $1 ~/Desktop/Trash
#End script



<>
"ZZ"

Make it executable


CODE
# chmod 0775 /usr/bin/del



Now if we do


CODE
$ del tessst


( It will execute the script and do the same as: )


CODE
$ 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.


Photobucket






Read more!

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:


CODE
$ history


And you'll get a full numbered list of all stored commands


CODE
$ !8


Will get you number 8 of that list


CODE
$ !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 ?


Photobucket






Read more!

BASH in Linux

There are several shells available in Linux, the default shell is the Bourne Again SHell ---a pun on the name of Steve Bourne, who was author of the traditional Unix shell, the Bourne shell.
A shell is a program that takes commands from the user and passes them on to the kernel for processing.

Like all the other shells in Linux, the Bash shell is not only a great tool for the command line, but also a scripting language.
Shell scripting allows you to automate tasks that in a normal way would need typing in a lot of commands.
FYI: Some other shells are: the C shell, or Korn shell (the default on IBM's AIX operating system); the ASH shell ( ash is useful for testing scripts to be sh-compliant ), the TCSH shell ( completely compatible version of the Berkeley Unix C shell ) and the new ZSH shell ( ZSH most closely resembles KSH but includes many enhancements ).

As you open a terminal/console you actually open a shell and you are presented with a bash prompt. A Bash prompt typically ends with a $ to show you´re logged in as a normal user ( Only in SuSE it ends with > for the user ). A Bash prompt ending with # shows that we are logged in as root ( Same in SuSE this time ).


Photobucket






Read more!
Tutorialsland By - Templates4all | Free Blogger and web Templates