w w w . T H E B I T S . c o . u k


I Need To Know The Most Useful Linux Commands

Home Contents Previous Next

This section contains the commands you are guaranteed to use time and time again. Memorizing these commands is the most important step you will take in getting to grips with Linux. In the near future a new section will appear, covering the less frequently used commands. And yes, I know 'mc' isn't technically a command, but what the hey (most command are mini-programs anyway).

Contents

Navigation

cd - change directory
ls - list directory
pwd - print working direcory
mc - Midnight Commander

Directory Management

mkdir - make directory
rmdir - remove directory

File Management

cp - copy file
mv - move file
rm - remove file

Miscellaneous

clear - clear screen
df - display free diskspace
info - display information
passwd - change password


Note

All of the following commands must be entered in lowercase.


^Navigation

cd

Description

Change directory i.e. move to another directory to work with it.

Examples

cd ..
Move up to the parent directory.

cd /usr
Move to the directory 'usr'.

cd my_work
Move down 1 directory to 'my_work' (a directory situated inside the current directory).

cd ~
Move to the user's home directory e.g. if the user logged on is 'laurence', then '~' is short for '/home/laurence'.

cd -
Move back to the last directory you were in.


ls

Description

Displays a directory listing.

Examples

ls
Display a listing of the current directory.

ls -al
The '-a' part displays all files i.e. including hidden files (those that start with a '.'. The 'l' part displays alongside each filename, from left to right: the file type; permissions; the number of hard links; the owner name; the group name; the size in bytes; and the date the file was last saved.

ls -F /etc
Display the 'etc' directory with '/' after a filename to indicate a directory, a '*' to indicate an executable and a '@' to indicate a symbolic link (the path to a program).

ls --color
Indicates different types of file using coloured text, as shown below:

+------------+---------------+
| grey       | regular file  | (often a text file)
+------------+---------------+
| dark blue  | directory     |
+------------+---------------+
| light blue | symbolic link |
+------------+---------------+
| green      | executable    |
+------------+---------------+

ls | less
Display the current directory screen by screen i.e. 'piped' (|) to the 'less' program.

ls -l /bin | less
Display the 'bin' directory (listing all file details (i.e. -l)), screen by screen i.e. 'piped' (|) to the 'less' program.

Note

The 'less' program is a great way to a long directory listing.

Keys

Down cursor = Down 1 line.
Up cursor   = Up 1 line.
Spacebar    = Down 1 screen.
b           = Back up 1 screen.
q           = Quit.
h           = Activate help screen.

ls > list.of.files
Either creates or overwrites the file 'list.of.files', with a redirected (>) listing of the current directory.

ls >> list.of.files
The same as above, except this time the listing is appended to the end of the file 'list.of.files'.

Note

If you prefer, you can use 'dir' instead of 'ls'.


pwd

Description

Prints the path of your current directory.

Example

pwd
Prints the path of the current directory.


mc

Description

Start Midnight Commander.

Example

mc
Start Midnight Commander.

Note

There are hundreds of switches you can add when opening Midnight Commander. To view them, enter: info mc


^Directory Management

mkdir

Description

Make/create a new directory.

Example

mkdir my_work
Make a directory called 'my_work' in the current directory.


rmdir

Description

Remove/delete a directory.

Example

rmdir my_work
Remove the directory 'my_work' contained in the current directory.

Note

You must first remove ('rm') or move ('mv') every file and directory - inside a directory - before you can remove that directory. Also, you cannot remove the current directory.


^File Management

cp

Description

Copies a file from one place, to another.

Examples

cp ~/hello .
Copies the file 'hello', from the current user's home directory ('~'), to the current directory ('.').

cp hello goodbye
Copies the file 'hello' to a new file named 'goodbye' and places 'goodbye' into the same directory as 'hello'.

cp work/example play/example-backup
Makes a copy of the file 'example', located in the 'work' directory (located in the current directory), and places the new file in the 'play' directory (again located in the current directory), and calls the copy 'example-backup'.


mv

Description

Move or rename, a file or directory.

Examples

mv letter old-letters/an_old_letter
Move the file 'letter' from the current directory to the directory 'old-letters' (contained in current directory), and rename the file 'an_old_letter'.

mv letter my_letter
Rename the file 'letter', as 'my_letter' in the current directory since no path was specified.

Note

If you were to enter 'mv Budget Finance' in order to rename the directory 'Budget' as 'Finance' and a 'Finance' subdirectory already exists in the current directory, then the 'Budget' directory is moved to become a subdirectory of 'Finance' i.e. '/Finance/Budget'. This could prove both useful and annoying!


rm

Description

Remove file/s.

Examples

rm ~/files/my-text-file
Remove the text file 'my-text-file' located in the 'files' directory, which resides in the user's home directory ('~').

rm * -rf
The '-r' part allows you to also delete directories and its contents. The 'f' part forces files to be removed without confirmation. Be VERY careful when using 'f'!

Warning

If you entered say 'rm * .97', to delete every file in the current directory, that ends with '.97', you would find to your to horror, that you are about to delete EVERYTHING in the current directory! Why? - Because there's a space between the '*' and the '.97' which makes the shell think you've entered 'rm *'!!!


^Miscellaneous

clear

Description

Clears the screen.

Example

clear
Clears the screen.

Note

Instead of typing 'clear' all the time, you can simply press Ctrl+l.


df

Description

Display free space available on each Linux partition and mounted floppy disk.

Example

df
Display free space available on each Linux partition and mounted floppy disk.


info

Description

Display the info page pertaining to a command/program.

Example

info ls
Displays the info page for the 'ls' command.

Keys

Ctrl+Z = Exit.
Enter  = Follow a link.
l      = Go back to previous page.
Ctrl+h = Display keys. 
h      = Help screen.

Note

Further information can be obtained using the 'man' command, albeit the cryptic (and perhaps outdated) equivalent of the info page e.g. 'man ls'.


passwd

Description

Change your login password.

Example

passwd
Prompts user to:

  1. Enter current password for authentication.
  2. Enter new password.
  3. Repeat new password.

By Laurence Hunter laurence@thebits.co.uk

Home Contents Previous Next

Download Latest Manual

www.THEBITS.co.uk - updated daily...