matthewstorey.co.uk
In this section Access FAT32 Partitions | Commands | Enabling DMA | Links | File Locations | Other Settings | File Permissions | Run Levels | Services | Using Truetype Fonts

Commands

As well as common commands, this page covered redirecting output and note on using commands

Common commands

A list of common commands to use in terminal sessions, not all of them will be available in all versions of Linux.

Command Description
cd Change to home directory.
cd .. Change to parent directory.
cd <directory> Change directory to the directory specified.
chgrp <group> <filename> Changes the group that files or directories belong to.
chmod <mode> <filename> Alters the permissions of files or directories.
chown <owner> <filename> Changes the owner (user) of files or directories.
cp <source> <destination> Copy the source file(s) to the destination.
cp -R <source> <destination> Copy the entire contents of the source directory to the destination.
df [mount point] Displays the amount of free space on all or the specified mount points.
echo <text> Echoes (displays) the text on the screen.
env Displays a list of environment variables and their values.
exit Exits the current terminal session.
export <name>=<value> Sets the environment variable with a value (see env).
iconv -f IBM-1047 -t ISO8859-1 <in filename> > <out filename>
iconv -f ISO8859-1 -t IBM-1047 <in filename> > <out filename>
Converts a text file from EBCDIC to ASCII or vice versa.
id [<userid>] Displays the UID, GID and group information for specified user.
If no use is specified, the current user details are shown.
ls List the contents of a directory.
ls -a List the contents of a directory, including hidden files.
ls -l List the contents of adirectory with list of attributes.
mkdir <directory name> Creates a new directory.
od -v <filename> Display an octal dump of a file showing all the lines.
pr -t <filename> Displays the contents of a file with no header or trailer.
ps -A Displays a list of running processes.
ps -A -d -m -o jobname,stime,etime,atime,vsz,state,args Displays a list of running processes in the format of:
jobname, start time, elapsed time, actual time, virtual memory, process state and command arguments.
pwd Displays the Present Working Directory.
rm <filename> Deletes a file.
rmdir <directory name> Deletes a directory.
sh -L Starts a new shell within your current one, clearing any previous settings.
su Log on as the administrator.
time <command> Runs the command given as its argument and produces a breakdown of total time to run (real),
total time spent in the user program (user), and total time spent in system processor overhead (sys).
Times given are statistical, based on where execution is at a clock tick.
times Displays the accumulative times in minutes and seconds.
User time is CPU time spent in user programs.
System time is CPU time spent in the operating system on behalf of the user process.

The output layout is:
shell user time      shell system time
child user time      child system time
top Resource usage analyzer. Will Display RAM, CPU, and total time usage.
who Displays a list of the users currently logged on.

Back to top

Using commands

A couple of points to remember when using the commands are:

Filenames

File and directory names can be abbreviated using the first few letters followed by '*', e.g. 'cd fr*' will change to directory 'fred'. Alternatively, you can press 'Tab' to autocomplete filenames (if your terminal supports this).

The maximum length for a single directory or file name is 255 characters.

If you have a file or directory that contains a space in the name, use ' characters around it.

Long commands

To enter a long command over more than one line use the '\' character, for example, entering 'ls \' followed by '$HOME' will list the contents of your home directory.

Separator characters

There are 2 types of separater character in Linux:

Stopping programs

If you are running a program that you think is not responding, type '$c' to terminate it.

Another way is to find the programs Process ID (PID) number using the 'ps' command and then type 'kill -9 <pid>'

Redirecting output

You can redirect the input and/or output produced by commands or programs to other files.

There are 3 system files, each with an identifier:

You can redirect STDOUT to a file by using the '>' symbol at the end of a command, so 'ls -l > listing' will send the directory listing to file "listing".

You can redirect STDOUT and STDERR to separate files by using the '1>' and '2>' symbols at the end of a command, so 'ls -l xxx 1> listing.out 2> listing.err' will send the directory listing to file "listing.out" and any errors produced to "listing.err".

The '>>' characters mean append to, so 'ls -l 1>> output.txt' will add the output to the "output.txt" file.

The '&' character can be used to redirect one form of output to another, so 'ls -l xxx 2>&1 1>> output.txt' will send any errors to STDOUT, which is appended to "output.txt".

Input can also be redirected from a file using the '<' symbol at the end of a command, so 'ls -l <dirname' where file "dirname" contains a directory name.

Back to top