Vous êtes sur la page 1sur 3

Linux Commands

by Freshu

Ok, you start at the console and as a default you're either


in your home directory (every user has a home directory
which contains his personal configurations files). Now
you want to navigate to another directory. But wait, you
don't know any other directories! You'll a directory
listing for this, right? To do this type 'ls' at the prompt.
'ls' is the equivlant to 'dir' in MS-DOS, and stands for
list. You'll get a list of files and
folders. To make the list a bit more readable, try ls -Fla.
The -a showsfiles which start with a period (for example:
.Xclients-default). The -ldisplays file permissions and
displays everything in neat columns. The F option adds
a / after a directory and a * after an executable file. I
also suggest using ls -Fla --color to let the system colorcode different files (may not be available on some
systems).
Anyway, now that you what directories there are, you
need to know how to get into them. Luckily, you use the
same command as you you use in MS-DOS, the 'cd'
(change directory) command. Let's say you're at the
bottom directory, '/' and you want to get to '/root'. You
simply type 'cd root'. There is no need to type 'cd /root',
because you're already in '/'. Now let's say you want to
get to '/root/bin'. This would be done by
typing 'cd bin'. There is no need to type 'cd /root/bin'
(the "full path" of the directory), since you're already in
'/root'. Instead, you can use a "relative path", which is a
path that is relative to the current directory
you're in. Type pwd to find out where you are (pwd
stands for print working directory).

directory under '/usr'. Of course though, if you're in '/'


and you want to make a directory called
'stuff' under '/usr', you would simply type '/usr/stuff'.

Now let's say you're in '/root/bin' and you want to get to


'/usr'. You would type 'cd /usr'. This is to signify that the
'usr' directory is under '/', not '/root/bin', or even '/root'.
Got it? Ok, just one more thing. If you're in
a subdirectory, and you want to get to the top directory,
just type 'cd ..'. Let's say you're in '/root/bin', and you
want to get to '/root'. You could just type 'cd /root', but
hey, '/root' is five characters! If you want to
save precious miliseconds, just type 'cd ..', since '/root' is
the directory in which '/root/bin' is a subdirectory of. So
in other words, . is the current directory, .. is one
directory above, ... is two directories above
etc'.

To find a file, oyu use the 'find' command. It then


followed by the directory where you want to start
looking, then the '-name' arguement to say that you're
searching for a filename. Next you type the name of the
file. Let's say you're looking for the 'this.gif' in the '/usr'
directory, the context would look like this: find /usr
-name this.gif

The next command is the 'rm' command. It works with


files and direcotires and is used to delete some, it stands
for 'remove'. If you want to remove a file called
'this.gif', you would go to the directory where that file is
and type 'rm this.gif'. Or let's say again you're in '/' and
'this.gif' is in '/usr', you would type 'rm /usr/this.gif'. It
works the same way with a directory.
Next are the 'cp' and 'mv' commands. They're both
relativley simple, but we'll start with 'cp'. 'cp' stands for
copy, and is used to copy a file from directory to another.
The context is:
cp /directory_where_it_is/filename
/directory_where_you_want_to_copy_it
Of course if you're already in the directory where the file
is, all you need to type is:
cp filename /directory_where_you_want_to_copy_it
'mv' works the exact same way, except it moves the file
instead of copying it. This means it deletes in from the
original directory and puts it in the new one.
5.4 - Finding and Viewing Commands

The find command doesn't stop at filenames, it can also


search a file for a paticular string of text. It has the same
context as the find file command except you put quotes
and asteriks around the string of text. So
if you wanted to search the '/usr' directory for a file
containing the string 'hello', you would type
find /usr -name "*hello*"
Ok, once you find a file, you want to view it right? Well,
you could open the file with a text editor, but we haven't
learned to use tetx editors yet, and anyway if the file you
want to view is important you might
accidently change it and save it using a text editor.
That's what the 'cat' command is for. Let's say you want
to view a file called 'stuff.txt' in '/root'. You would
navigate to the '/root' directory and
type 'cat stuff.txt'. Or from any directory, type 'cat
/root/stuff.txt'

5.3 - Basic File and Directory Commands


There are lots of file and directory commands in Linux,
but we'll start with directory commands because they're
easier. First off, you have 'mkdir'. 'mkdir' stands for
make directory and the context is
mkdir the_directory_you_want_to_make
Some rulse apply. If you're '/', it will make the new
directory under '/'. If you're in '/usr', it will make the

Linux Commands

by Freshu
There, now just go into file manager and click on the
directory you created and you will have all the files that
are on your windows partition. When you're done, don't
forget to unmount the drive by typing:
umount /dev/xxxx /yyyyyyy
Each time you want to access your windows files, just
mount the partition (unless they're set for automount.
Edit /etc/fstab, find the line that represents your
Windows partition and look for a place with says noauto.
If you find the word noauto, change it into defaults. If
you don't, your Windows partition will probably get
automounted whenever you boot-up Linux). When
you're done with them, just unmount the partition.

5.5 - linuxconf
There are lots of commands in Linux for configuring
everything to user passwords, networks, and the message
that comes up when you start Linux. With so many
things to configure, luckily there is one program that
does it all. Just type 'linuxconf' at the command prompt,
and you'll be brought to the Linux Configuration
program.
5.6 - Mounting
5.61 - Mounting Drives
In Linux, drives not only have to be physically mounted
to the computer, but mounted in software too. In the
KDE and GNOME GUIs, you can easily mount a CDROM or disk drive by clicking on the 'CD-ROM' or
'Disk Drive' icons on the desktop.

5.7 - Runlevels
While Windows is booting, have you ever pressed the F8
key? Well, if you have, you're probably familiar with a
screen that pops up giving you a list of ways you can
load Windows. There's safe mode, command prompt,
step-by-step confirmation, etc. Linux has something just
like that, and they're called 'runlevels'. There are six
runlevels in all, and some are pretty much the same. A
runlevel is a list of commands to load-up as soon as you
start up Linux (there's a mini-tutorial about runlevels at
blacksun.box.sk/byteme.html). Your default runlevel is
probably 5. If you configured the GUI to start up when
you boot the system, and if your default runlevel is 5,
then that is the runlevel configured to boot the GUI when
it
starts up...simple, right?

5.62 - How to mount


Remember earlier in this tutorial when we went over
how a hard drive partition is almost like a separate hard
drive? Well, just like a separate drive, partitions also
have to be mounted. The main use in this is being able
to mount Windows partition and access Windows files in
Linux. Obviously, Windows
software will not run under Linux but there is still a use
for accessing Windows files in Linux.
Let's say you can't use the internet in Linux. You ISP
only allows to dialup with software and they don't make
it for Linux, you're not used to Linux yet so you don't
want to use the net in it yet. This is a down
point, but it doesn't mean you can't download Linux files
to use. All you have to do is download the files in
Windows and access them in Linux.
To mount a windows partition in Linux, yhe first
thing you must do is create a directory in Linux where
you will mount the windows partition to reside. Go into
file manager (it should be under utilities no matter what
distribution you're using) and create a new directory
under '/'. Call anything, I suggest calling it 'windows'.
Now exit file manager and go into 'terminal' (should also
be under utilities). Terminal will give you a command
prompt just like MS-DOS. This is what you would have
to do everything from if there were no X Windows GUI.
The command to use is simply enough- 'mount'. But
don't type it just yet, you need to give the system more
info. The full command is
mount -t vfat /dev/xxxx /yyyyyyy (yes there
is a space between 'xxxx' and '/')
Or
mount -t vfat32 /dev/xxxx /yyyyyyy in case
this is a FAT32 partition.
Where 'yyyyyyy' is the directory you just created, and
'xxxx' is the device name of the partition where Windows
resides. It is usually hda1 or something.

Well anyway, if you use linuxconf to change your default


runlevel to 2 or 3 or something, then you change it so
that the GUI won't start as soon as the system boots....all
without touching the actual runlevel. When you want to
change it back, just use linuxconf to set the default
runlevel
back to 5.
Now let's say you only want to load it without the GUI
coming up once. Instead of having to change the
configuration in linuxconf, and then changing it back,
you can load Linux into another runlevel. Suppose You
want to load runlevel 2...not for any paticular reason, just
because it's not configured to load the GUI when it boots
up, and well, you like the number 2. To do this, as soon
LILO comes up (whether it's on your computer, or your
boot disk), you have the option to type something next to
'boot:'. Just type 'linux x'. 'x' refers to the number of the
runlevel, in this case the number 2, so you type 'linux 2',
and press
enter. This will load Linux without loading the GUI.
When you restart
Linux, it will load the default runlevel again.

Linux Commands

by Freshu

Vous aimerez peut-être aussi