Linux Tutorial (Command Line)

Posted by Firebird on Sept. 28, 2006, 7:40 a.m.

When I read flashback's tutorial on creating the 'perfect' Linux box, I thought it needed something extra: a basic tutorial on using the Linux Command Line, since it is one of the features of Linux you must know. Well, you don't have to, but eh. It's a lot easier if you know it.

For this, I'll be using DSL (Damn Small Linux), and bash (Bourne-again shell). You can grab a copy of DSL from http://damnsmalllinux.org, and if you want to try it out, here is a windows-embedded version - http://distro.ibiblio.org/pub/linux/distributions/damnsmall/current/dsl-embedded.zip.

Okay, let's get started!

First, boot into DSL. When you are greeted with the Desktop, double-click the Terminal icon, or right click and choose it from the menu (XShells). So now you've got a terminal window open… but you don't know where you are! So we'll print the working directory -

pwd

You should see a $ sign (dollar) next to where you type your commands. This signifies that you are logged in as a normal user. If you want to switch to a super user (root), you'll have to log out, or use commands like su and sudo. If you are logged in as root, you should see a hash (#), not a dollar sign ($).

So, now we know where we are, we might want to find out what is in our working directory. Like so -

ls

That lists all the files/dirs in the current working directory. If you're looking for something a bit more readable (in your opinion) and informative, you might try this -

ls -l

If you're in a directory with a lot of files, you can use a feature called piping. It works like this -

ls -l | less

So that pipes the output of ls -l into the program, less, which allows you to navigate through the file.

Now we'll create our own directory for testing purposes -

mkdir tests

That creates a directory called tests in the current working directory. Now we'll change our position to the directory -

cd tests

If you want, you can print the working dir again using pwd, or list the things in there by ls. But the problem is, there is nothing in there! So we'll solve that problem by creating a simple text file -

echo "Hello" > helloworld.txt

echo repeats whatever you tell it to to the screen, but in this case, we're using it to create a file called helloworld.txt. Now we'll copy it.

cp helloworld.txt helloworld2.txt

That copies the first file and copies it to the second file. Now, we could rename helloworld2.txt to something -

mv helloworld2.txt something.txt

Moving the file is the same as renaming it in Linux. So, print the list of files in the dir again, just for good measure -

ls -l

Now, you might want to delete a file. You can achive that, by doing this -

rm something.txt

But you might want to delete a whole directory. Change to the dir above the tests folder -

cd ..

And then try removing the tests directory -

rm tests

It returns an error, because the directory still has files in it. You can work around that like this -

rm -rf tests

Boom, and the directory is gone. You might want to edit a file now, and you can do this very simply via an editor called Vim.

Create a new text file (you should know how by now, if not, read back), and then do this -

vim filename.txt

This should open Vim. Now, Vim is a bare-bones text editor, and it can be complicated, but you can peform some complex things in a few keystrokes. To command vim, just type something in and press enter. Here is a list of some commands -

i - Enter insert mode

Escape - Exit insert mode

up, down, left, right - Move the cursor

w - Move the cursor right one word

b - Move the cursor left one word

^ - Move the cursor to the start of the line

$ - Move the cursor to the end of the line

x - Delete the character on the cursor

dd - Clear the line

:w - Save the file

ZZ - Save the file and exit

:q - Exit

:q! - Exit without saving

Play around with Vim for a bit. There are other text editors, like nano.

You may want to kill some frozen processes from the terminal. This is easy. First, use this command -

ps

To print a list of processes and their PID (Process IDentification) number. Once you have the PID of a process, you can kill it, like so -

kill [PID]

If you're in X windows (GUI), you can also use this, to click on a window, to end it's process -

xkill

Anyway, this is the endof this tutorial. Maybe I'll make another one. If you spot an error, just tell me in a comment or PM.

Keep L337,

Firebird out!

[GETLINUX]

Comments

Eternal 18 years, 1 month ago

Quote:

For this, I'll be using DSL (Damn Small Linux), and bash (Bourne-again shell). You can grab a copy of DSL from http://damnsmalllinux.org, and if you want to try it out, here is a windows-embedded version - http://distro.ibiblio.org/pub/linux/distributions/damnsmall/current/dsl-embedded.zip.

Firebird 18 years, 1 month ago

Quote:
When I read flashback's tutorial on creating the 'perfect' Linux box, I thought it needed something extra: a basic tutorial on using the Linux Command Line, since it is one of the features of Linux you must know. Well, you don't have to, but eh. It's a lot easier if you know it.

Oh sorry, did you get owned?

MahFreenAmeh 18 years, 1 month ago

Pwnt.

Haha, may us Linux users rise!

Tyranic-Moron 18 years, 1 month ago

Well, I downloaded Damn Small Linux. Not as good as Fedora Core, obviously, but it takes up less space, so I'll stick with it instead :D