Mandriva

Previous Page : The Ultimate Power Tool ; Terminals, xterms And Shells; First Steps On the Shell; Using The Shell I

Using the command-line editor (shell) II : the very first shell commands to experiment

Table of content :

Section index - Knowledge Base index

Introduction

If you're a beginner, have fun playing in a console with these first commands.

To open a console :

  • Press simultaneously Alt+Ctrl+Fn keys (n being between 1 and 6) : you come back to your classical graphical environment with Alt-F7
  • Or click on K Menu -> System -> Terminals and choose, for instance, Konsole.
Be careful not to be logged on as 'root' but as a simple user.

Knowing 'where you are'

  • The pwd command displays the name of the working directory (sometimes called current directory).
    To remember more easily : 'pwd' is the acronym of print working directory.

Creating an empty file

  • Use the command touch file_name.
    If file_name is an existing file, only its date and hour will be changed, its content will not be modified.

To add a line at the end of a file without removing its content

  • A combination between the 'echo' command and the redirection operator '>>' (be careful not to confuse with '>' described below) :
    echo "blah blah blah" >> file_name
    .

To read the content of a file

  • The command cat file_name displays the content of a text file.

To replace the content of an existing file with another content or to create a file with a specific content

  • Similar to the last-but-one command, but using this time the redirection operator '>' :
    echo "blah blah blah" > file_name
(if the file doesn't exist, it will be created, without using the 'touch' command)

To read the content of a file spreading across several pages

  • The command less file_name displays the content of a file and allows moving into it.

To change the name of a file or a directory

  • The command mv name1 name2 renames the file or directory name1 into name2.

To create a new copy of a file

  • The command cp file1 file2 creates file2 by copying the content of file1 into it.

To see what's inside a directory

  • The command ls -l lists the content of the working directory.
  • The command ls -la lists the content of the working directory and includes hidden files.
  • The command ls -l dir lists the content of the 'dir' directory.

To go elsewhere

  • The command cd directory changes the working directory.

To clean up

  • The command rm file removes a file.

To create or remove directories

  • The command mkdir directory creates a directory.
  • The command rmdir directory removes an empty directory.

To put a file somewhere else

  • The command mv file directory moves the file 'file' to the directory 'directory'.

To look for some text in a file

  • The command grep text_to_look_for file_name looks for a text in a file.
  • The command grep -i chaine_à_chercher nom_de_fichier does the same thing but do not care about uppercase and lowercase letters.

To know what is happening right now

  • The command top lists programs using the most your CPU (they will be up in the display). Use 'q' to quit.
  • The command ps ux lists all active programs belonging to the current user.
  • The command ps aux lists all active programs in the system.

To have a look at what you've done

  • You can recall and see the previous commands you've typed using up and down arrow keys on your keyboard.
  • The command history displays a list of the last commands used.

To become administrator and quickly go back under your standard identity

  • The command su - switch you to the administrator mode, i.e. you become 'root' (be careful : don't stay under root to experiment all these commands, a mistake can be made very quickly!).
  • The command exit bring you back to your previous identity.

Other resources


Next page : Auto-Completion ; Commandline History ; Commandline Editing ; Available Shell Shortcuts
Author : ptyxs (march 2006)

 


fr en

RSS

Creator: ptyxs on 2006/03/04 11:17
(c) Mandriva 2007
18888888