Linux Topic
   >  Why use the Command Line?
   >  Common Linux Commands
   >  Directory Structure
   >  Using Regular Expressions
   >  $STDIN; $STDOUT and $STDERR
   >  IO Redirection and Pipes

 

Common Linux Commands

Common Commands

To cover all the commands possible in Linux would take several books! Here I'm just going to list a few of the common ones and let you use your favourite search engine to find out the details:

CommandDescriptionExample Usage
lsList files (-and their attributes) in a given directory$ ls
$ ls -l /var/temp
cdChange the current directory to the one specified$ cd
$ cd ..
$ cd /var/temp
pwdDisplay the current directory path$ pwd
moreDisplay the contents of a file, one page at a time. Press "SPACE" to show the next page or "q" to quit$ more /var/tmp/myfile
chmodChange the permissions on a file or directory$ chmod 755 myfile
chownChange the owner of a file or directory$ chown fred:users myfile
viEdit the file in the "vi" editor$ vi /var/tmp/myfile
dfList the filesystems on the system$ df -h
echoPrint out the text specified$ echo "hello $USER"
psList running processes$ ps -ef
killStop (abort) a running Process ID (PID)$ kill 1036
grepSearch for a string in a file$grep "fred" names.txt
|Known as a "pipe" : take output from one command as input to the next$ps -ef | grep "root"
cpMake a copy of an existing file$ cp fred.txt bert.txt
mvRename or move an existing file$ mv fred.txt /tmp/bert.txt
rmDelete (remove) an existing file(s)$ rm fred.txt bert.txt
mkdirCreate a directory$ mkdir backupDir
rmdirDelete (remove) a directory$ rmdir backupDir

Each of these commands can be used singly or in conjunction with each other (-see the chapter on I/O Redirection for details of the latter).


Command Documentation

Every Linux command has a man (-short for manual) page: if you type "man <Linux command>" into a command line, it will print out lots of useful information. For example if you are unsure of the options used with the "ls" command, you can type:

$ man ls
LS(1)                User Commands                LS(1)

NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

DESCRIPTION
       List  information  about  the FILEs (the current
       directory by default).  Sort entries  alphabeti‚Äź
       cally if none of -cftuvSUX nor --sort.

 Manual page ls(1) line 1

Man pages tend to be quite long and will be displayed a page at a time: hit the spacebar to display the next page or the "q" key to quit the listing and return to the prompt.

Note: you can also find man pages on the web!


A Session Example

Here's a extract from a simple command line session:

   $ cd /home/fredb(change to the /home/fredb directory) 
   $ pwd(check we are now in the right directory) 
   /home/fredb
   $ ls (list all files in this directory) 
   myfile.txt    yourfile.sh
   $ mkdir tmp(create a sub directory called "tmp") 
   >$ cd /home/fredb(change to the /home/fredb directory) 
   >$ pwd(check we are now in the right directory) 
   /home/fredb/tmp<
   $ ls (list all files - none listed of course) 
   $ cp /home/fredb/myfile.txt herfile.txt(copy "myfile.txt" from the original directory to this one as "herfile.txt") 
   $ ls(list all files in this directory) 
   herfile.txt
   $ pwd(check we are in the right directory) 
   /home/fredb/tmp

HomeSite IndexDesktop GuideServer GuideHints and TipsHardware CornerVideo SectionContact Us

 sitelock verified Firefox Download Button