How to Issue Commands in Linux

Tortoise

The Linux environment is interactive. When you type a command at the keyboard and then press the Enter or Return key, Linux immediately begins to act on the command. More accurately, Linux interprets the command using a special program of its own called the shell. (On Milk Shake, the default shell is bash.) All shells produce a shell prompt to let you know that Linux is awaiting your next command. Milk Shake's shell prompt has the form username@host:~$, where host is the name of the Linux system you are using (e.g. andrew@milk:~$). Whenever you see this prompt, you know that the Linux shell is ready for your next command.

Linux is case-sensitive. That is, Linux distinguishes between upper and lower case letters in the names of files and programs. Thus, while ls is a valid Linux command, LS is not. Login names and passwords are also case-sensitive.

Some programs, such as Pico, have their own commands that you type within the program rather than at the Linux shell prompt. However, the shell prompt reappears whenever you exit such programs.


Basic File Commands

These are typed at the shell prompt username@host:~$.

ls

List the files in the current directory

ls -a

List all the files in the current directory, even the hidden ones

ls -F

As above, but indicate sub-directories by appending a backslash (/) to their name

cp FILE1 FILE2

Make a copy of FILE1 and call the copy FILE2

mv FILE1 FILE2

Rename a file from old name FILE1 to new name FILE2

mv FILE1 DIR/

Move a file from it's present directory into another directory (DIR)

rm FILE

Remove or delete FILE

more FILE

Display the contents of FILE, pausing after each screenful

--More--(18%)
Whenever you see something like the above at the bottom of your screen, you can:

press the space bar

To see the next screenful of text

type b

To go back one screenful

type q

To quit the listing of text and return to the Linux shell prompt

 


Correcting Typing Mistakes:

(at the Shell Prompt)

Delete or Backspace

Erase the last character you typed

Ctrl -u

Delete the last line you typed

 


Basic Directory Commands

These are typed at the shell prompt username@host:~$
In Linux your files are organized in directories and subdirectories. When you first log in to your account, you are placed in your home directory, which you can refer to with the character ~.

 

cd DIR

Go to the directory called DIR

cd ..

Go to the directory above the current directory

mkdir DIR

Create a new directory called DIR

rmdir DIR

Remove the directory DIR (must be empty first; if not, use rm  -r)

cd or cd ~

Go to your home directory

mv DIR1 DIR2

Move or rename a directory from old name DIR1 to new name DIR2

Use the / character to separate directory and file names when specifying a path.

 


Useful Commands

exit

Ends your work on the Linux system

Ctrl-l or clear

Clears the screen

Ctrl-c

Stops the program currently running

Ctrl-p

Retrieves the last shell command you typed

Ctrl-z

Pauses the currently running program

man COMMAND

Looks up the Linux command COMMAND in the online manual pages

find . -name FILE -print

Finds all paths containing FILE in the current directory or below it

 

fgrep -i PATTERN FILE

Searches for and displays all lines in file that contain PATTERN (case insensitive)

finger USER@ADDRESS

Displays login/e-mail status of a user at another host

jobs

Lists background jobs started during your current login session

ps

Lists all jobs (background and foreground) started during your login session

 

du

Displays disk usage in kbytes by directory, starting in the current directory and working down

du -s

Displays total disk usage

fs listquota

Displays your current disk space usage and quota in kbytes

telnet ADDRESS

Logs on to another machine on the Internet on which you have an account

ftp ADDRESS

Begins a file transfer session with another computer on the Internet

wc FILE

Counts the lines, words, and characters in FILE

spell FILE

Reports possible misspelled words in FILE

 


Linux Shell Short Cuts


The Linux shell keeps a record of the commands you type during your login session. Here are a few commands that take advantage of this history facility. All are typed at the shell prompt username@host:~$.

history

List all commands typed so far (default maximum number=500)

!!

Repeat the last command

!n

Repeat command n from the history list

!PATTERN

Repeat last command beginning with PATTERN

^PATTERN1^PATTERN2

Repeat last command but replace PATTERN1 (usually a typo) with PATTERN2 (the correction)

Site Contents and Design (c) Andrew Och 2002