next up previous contents
Next: Using Linux multitask system Up: How to use your Previous: Discovering the Bash shell   Contents

The Bash shell's basic commands

All the commands that are described here can be used in console mode or in a terminal-emulator in graphics mode (kvt, xterm). For more details, use ``man command''. Example:

man ls
The "su" command:

It enables you to log into a root account while you are in a user account. When you type "su", the shell asks your root password. Type it and then "enter": now, you are in the root account. Type "exit" to go back to the previous account.
The "cd" command:

This command enables you to change directory. It can handle both absolute and relative paths. For example, let's imagine that you are in your personal directory and you want to go to the docs/ subdirectory. Just type (relative path):

          cd docs/

To go to the /usr/bin directory, type (absolute path):

          cd /usr/bin/
Some of this command's options are:

cd ..
enables you to go back to the parent directory (beware of the space between cd and ..).

cd -
enables you to go back to the previous directory.

cd
leads you to your personal directory.

The "ls" command:

"ls" (-> list) gives you a list of files in the current directory. Two options are generally used: "-a" to view hidden files and "-l" to look at long filenames.
The "rm" command:

This is used to delete a file. Warning: once the file is deleted, you cannot get it back!

Syntax:

rm file_name

This command accepts parameters. The most frequent options are: "-i" which asks for confirmation before deleting a file and "-r" to erase directory files recursively.

For example:

rm -i ~/html/*.html

erases all the html files of your own html subdirectory.
The "mkdir" and "rmdir" commands:

The "mkdir" command enables you to create a directory, whereas the "rmdir" command deletes it if it is empty.

Syntax:

mkdir directory_name

rmdir directory_name

The "rmdir" command is often replaced by "rm -rf" which enables you to delete a directory, even if it is not empty.
The "more" and "less" commands:

"more" and "less" enable you to read text page by page.

Syntax:

more file_name

less file_name

It is very useful for looking at a file on your screen without modifying it.

Note: "more" is faster, but "less" is more powerful.

Press "q" to quit.
The "grep" command:

This command has many options and enables you to search for a character string in a file.

Syntax:

grep string file
The "ps" command:

It displays the list of the current processes. The command column gives the process's name and the PID column gives its number (this is the number you have to use to kill a program via the "kill" command).

Syntax:

ps arguments

The "u" argument gives you more information and "ax" enables you to recognize processes that do not belong to you (such as those that are launched at the time of booting).
The "kill" command:

If a program does not respond anymore, use this command to kill it.

Syntax:

kill PID_number

Sometimes you have to use "kill -9 PID_number" (when a simple "kill" has no effect). The PID number is obtained with the "ps" command.


next up previous contents
Next: Using Linux multitask system Up: How to use your Previous: Discovering the Bash shell   Contents

1999-01-27