Beruflich Dokumente
Kultur Dokumente
Table of Contents
Using this guide
Starting a Terminal
Commands
sudo: Executing Commands with Elevated Privileges
File & Directory Commands
System Information Commands
Adding A New User
Options
"Man" and getting help
Searching for man files
Other Useful Things
Pasting in commands
Save on typing
Change the text
More Information
"Under Linux there are GUIs (graphical user interfaces), where you can point
and click and drag, and hopefully get work done without first reading lots of
documentation. The traditional Unix environment is a CLI (command line
interface), where you type commands to tell the computer what to do. That
is faster and more powerful, but requires finding out what the commands
are." -- from man intro(1)
This guide will make you familiar with basic GNU/Linux shell
commands.
Note that Linux is case sensitive. User, user, and USER are all
different to Linux.
Starting a Terminal
The terminal can be found at Applications > Accessories > Terminal
Commands
sudo: Executing Commands with Elevated
Privileges
Most of the following commands will need to be prefaced with the
sudo command if you will be working with directories or files not owned by
your account. Please see RootSudofor information on using sudo.
you're located ( pwd stands for "print working directory"). Example: "pwd"
in the Desktop directory will show "~/Desktop". Note that the Gnome
Terminal also displays this information in the title bar of it's window - see the
example screenshot at the top of this page.
ls: The ls command will show you the files in your current directory.
Used with certain options, you can see sizes of files, when files where made,
and permissions of files. Example: "ls ~" will show you the files that are in
your home directory.
cd: The cd command will allow you to change directories. When
you open a terminal you will be in your home directory. To move around the
file system you will use cd. Examples:
cp: The cp command will make a copy of a file for you. Example: "cp
file foo" will make a exact copy of "file" and name it "foo", but the file "file"
will still be there. When you use mv that file would no longer exist, but
when you use cp the original file stays and a new copy is made.
directory.
o
Note that if you are using mv with sudo you will not be able to
use the ~ shortcut, but will have to use the full pathnames to your files.
This is because when you are working as root, ~ will refer to the root
account's home directory, not your own.
man: The man command is used to show you the manual of other
commands. Try "man man" to get the man page for man itself. See the "
Man & Getting Help" section down the page for more information.
df: The df command displays filesystem disk space usage for all
partitions. " df -h" is probably the most useful - it uses megabytes (M) and
gigabytes (G) instead of blocks to report. ( -h means "human-readable")
free: The free command displays the amount of free and used
memory in the system. "free -m" will give the information using
megabytes, which is probably most useful for current computers.
uname -a: The uname command with the -a option prints all system
information, including machine name, kernel name & version, and a few
other details. Most useful for checking which kernel you're using.
Description:
Release:
6.06
Codename:
dapper
Options
The default behavior for a command may usually be modified by adding a -option to the command. The ls command for example has an -s option so
that "ls -s" will include file sizes in the listing. There is also a -h option to
get those sizes in a "human readable" format.
Options can be grouped in clusters so "ls -sh" is exactly the same command
as "ls -s -h". Most options have a long version, prefixed with two dashes
instead of one, so even "ls --size --human-readable" is the same
command.
man -k foo will search the man files for foo. Try "man -k nautilus"
to see how this works.
man -f foo searches only the titles of your system's man files. Try
Save on typing
Up Arrow or
ctrl+p
Down Arrow or
Takes you back to a more recent command.
ctrl+n
Enter
tab
ctrl+b
ctrl+k
Deletes from the current cursor position to the end of the line.
ctrl+u
ctrl+w
More Information
The following online guides are available:
AptGetHowto - using apt-get to install packages from the command
line.
AptGet
Howto
This article applies to all supported versions of Ubuntu
Introduction to APT
"In the beginning there was the .tar.gz. Users had to compile each program that they
wanted to use on their GNU/Linux systems. When Debian was created, it was deemed
necessary that the system include a method of managing the packages installed on the
machine. The name dpkg was given to this system. Thus the famous 'package' first came
into being on GNU/Linux, a while before Red Hat decided to create their own 'rpm'
system.
A new dilemma quickly took hold of the minds of the makers of GNU/Linux. They needed
a rapid, practical, and efficient way to install packages that would manage dependencies
automatically and take care of their configuration files while upgrading. Here again,
Debian led the way and gave birth to APT, the Advanced Packaging Tool, which has
since been ported by Conectiva for use with rpm and has been adopted by some other
distributions."
Commands
All of these commands must be run as root or with superuser privileges, see sudo
for more information. Replace <package_name> with the name of the package you are
attempting to install.
Installation commands
This command searches the repositories and installs the build dependencies for
<package_name>. If the package is not in the repositories it will return an error.
auto-apt
It will then ask to install the needed packages and call apt-get
automatically. If you're running X, a graphical interface will replace the
default text interface.
Maintenance commands
apt-get update
apt-get upgrade
This command upgrades all installed packages. This is the equivalent of "Mark all
upgrades" in Synaptic.
apt-get dist-upgrade
The same as the above, except add the "smart upgrade" checkbox. It tells APT to
use "smart" conflict resolution system, and it will attempt to upgrade the most
important packages at the expense of less important ones if necessary.
apt-get check
This command is a diagnostic tool. It does an update of the package lists and
checks for broken dependencies.
apt-get -f install
This command does the same thing as Edit->Fix Broken Packages in Synaptic.
Do this if you get complaints about packages with "unmet dependences".
apt-get autoclean
This command removes .deb files for packages that are no longer installed on
your system. Depending on your installation habits, removing these files from
/var/cache/apt/archives may regain a significant amount of diskspace.
apt-get clean
The same as above, except it removes all packages from the package cache. This
may not be desirable if you have a slow internet connection, since it will cause
you to redownload any packages you need to install a program.
o The package cache is in /var/cache/apt/archives . The command
du -sh /var/cache/apt/archives
will tell you how much space cached packages are consuming.
dpkg-reconfigure <package_name>
Reconfigure the named package. With many packages, youll be prompted with
some configuration questions you may not have known were there.
For example:
dpkg-reconfigure fontconfig-config
This command places the desired package on hold. This is the same as Synaptic's
Package->Lock Version.
o
This command removes the "hold" or "locked package" state set by the above
command. The note above about sudo usage applies to this command.
Removal commands
+ operator
apt-get autoremove
This command removes packages that were installed by other packages and are no
longer needed.
o
Search commands
dpkg -l *<search_term>*
This will find packages whose names contain <search_term>. Similar to aptcache search, but also shows whether a package is installed on your system by
marking it with ii (installed) and un (not installed).
dpkg -L <package_name>
dpkg -c foo.deb
This command lists files in the package "foo.deb". Note that foo.deb is a
pathname. Use this command on .deb packages that you have manually
downloaded.
dlocate <package_name>
dpkg -S <package_name>
This command does the same as dlocate, but does not require the installation of
any additional packages. It is slower than dlocate but has the advantage of being
installed by default on all Debian and Ubuntu systems.
This command acts like dlocate and dpkg -S, but searches all available packages.
It answers the question, "what package provides this file?".
o
apt-cache pkgnames
A general note on searching: If searching for a generates a list that is too long, you
can filter your results by piping them through the command grep. Examples:
o
will show only the files that contain filename as a whole word
o
will list files located in the directory /usr/bin, useful if you're looking for a
particular executable.
For more information on apt-get, apt-cache and dpkg consult their manual pages by using
the man command. These manuals will provide a wider scope of information in addition
to all of the options that you can use with each program.
Example:
man apt-get
It gives me a lot of answers. I see a game named "torcs". Lets get some more information
on this game.
apt-cache show torcs
Hmmm... it seems interesting. But is this game not already installed on my computer?
And what is the available version? Is it from Universe or main?
apt-cache policy torcs
What is the command I must type in the console to launch this game? In this example, it's
straightforward ("torcs"), but that's not always the case. One way of finding the name of
the binary is to look at what files the package has installed in "/usr/bin". For games, the
binary will be in "/usr/games". For administrative programs, it's in "/usr/sbin".
dpkg -L torcs | grep /usr/games/
The first part of the command display all files installed by the package "torcs" (try it).
With the second part, we ask to only display lines containing "/usr/games/".
Hmmm, that game is cool. Maybe there are some extra tracks?
apt-cache search torcs
But I'm running out of space. I will delete the apt cache!
apt-get clean
Oh no, my mother asked me to remove all games from this computer. But I want to keep
the configuration files so I can simply re-install it later.
apt-get remove torcs
On some installations there will be no apt-conf file set up. This procedure will
either edit an existing apt-conf file or create a new apt-conf file.
gksudo gedit /etc/apt/apt.conf
Add this line to your /etc/apt/apt.conf file (substitute your details for yourproxyaddress
and proxyport).
Acquire::http::Proxy "http://yourproxyaddress:proxyport";
BASH rc method
This method adds a two lines to your .bashrc file in your $HOME directory. This method
is useful if you would like apt-get and other applications for instance wget, to use a httpproxy.
gedit ~/.bashrc
Add these lines to the bottom of your ~/.bashrc file (substitute your details for
yourproxyaddress and proxyport)
http_proxy=http://yourproxyaddress:proxyport
export http_proxy
Save the file. Close your terminal window and then open another terminal window or
source the ~/.bashrc file:
source ~/.bashrc
Test your proxy with sudo apt-get update and whatever networking tool you desire. You
can use firestarter or conky to see active connections.
If you make a mistake and go back to edit the file again, you can close the terminal and
reopen it or you can source ~/.bashrc as shown above.
source ~/.bashrc
The Basics
Ubuntu uses apt for package management. Apt stores a list of repositories or software
channels in the file
/etc/apt/sources.list
By editing this file from the command line, we can add, remove, or temporarily disable
software repositories.
All the lines beginning with one or two hashes (#) are comments and do not get
read by apt or its front-ends apt-get, Synaptic, and Adept.
The lines without hashes are apt repository lines. The first two apt lines in our
example are
Future Versions
in the future you would replace the 'hardy' with the current version you
have installed. So if you have Intrepid installed it would look like below:
Adding Repositories
Adding the Universe and Multiverse Repositories
Additional software repositories such as Universe and Multiverse can be enabled by
uncommenting the corresponding apt line (i.e. delete the '#' at the beginning of the line).
In our example, we would uncomment the following lines for the Universe:
It is important to add the hardy-updates part of both the universe and the
multiverse to ensure you get updates.
Once you are satisfied with your choices, save the file. Now, retrieve the updated package
lists from the newly added repositories by issuing the following command:
Done! Your system is ready to install packages from the Universe and Multiverse
repositories.
Be aware that the software contained within this repository is NOT open
source.
Note: There are some (but not many) good reasons for which you might want to
add non-Ubuntu repositories to your list of software sources. Some software cannot be
distributed by Ubuntu due to patent and licensing restrictions in some countries (see the
RestrictedFormats page for examples). You might want to add repositories that offer such
software. Make sure that all repositories you add in this way have been tested and are
known to work on Ubuntu systems. Repositories that are not designed to work with your
version of Ubuntu can introduce inconsistencies in your system and might force you to
re-install.
You can add custom software repositories by adding the apt repository line of
your software source to the list of repositories. It should look something like this:
deb http://mirror3.ubuntulinux.nl/ hardy-seveas freenx
Add the line at the end of your sources.list and save the file.
Next, make apt aware of the new software repositories by issuing the following
command:
sudo apt-get update
Done! The new software repositories should now be available for use.
Now make the changes to uncomment all repositories listed in the sources.list file.
sudo sed -i -e "s/# deb/deb/g" /etc/apt/sources.list
Make apt aware of the new software repositories by issuing the following
command:
sudo apt-get update
Done! The new software repositories should now be available for use.
Problem: You are looking for a way to enable a repository which you provide for users
of your software.
Make apt aware of the new software repositories by issuing the following
command:
sudo apt-get update
Please be aware that you should sign your packages and ask your users to import
your PGP key. Otherwise they will have to confirm that they want to install
untrusted packages from your repository.
What Is grep?
Grep is a command line tool that allows you to find a string in a file or stream. It can be
used with Regular expression to be more flexible at finding strings.
This is OK but it does not show the true power of grep. First this only looks at one file. A
cool example of using grep with multiple file would be to find all files in a directory that
contains the name of a person. This can be easily accomplished using a grep in the
following way :
% grep 'Nicolas Kassis' *
Notice the use of single quotes; the quotes are not essential, but in this example they are
required because the name contains a space. Double quotes could also have been used in
this example.
Now lets use some regular expressions...
.*
[]
Matches on character for the one listed in the the Square brackets
[^]
\
Denotes the beginning and end (respectively) of a word
<, \>
This will search for any word which begins with a letter upper or lower case.
find
Contents
1. Introduction
2. The Basics
1. Locating Files by
Name
2. Locating Files by
Size
3. Locating Files by
Access Time
3. Advanced Usage
1. Combining Searches
2. Acting On The files
3. Using xargs
4. More Information
Introduction
The GNU find command search files within within a directory and its subdirectories
according to several criteria such as name, size and time of last read/write. By default
find prints the name of the located files but it can also perform commands on these files.
The GNU find command is part of the GNU findutils and is installed on every Ubuntu
system. findutils is actually made up of 4 utilities:
1.
2.
3.
4.
This wiki page will be only be dealing with find while also briefly mentioning xargs.
Hopefully locate and updatedb will be covered on their own page in the near future.
The Basics
The syntax for using find is:
find [-H] [-L] [-P] [path...] [expression]
The 3 options [-H] [-L] [-P] are not commonly seen but should at least be noted if only to
realise that the -P option will be the default unless another option is specified:
-H : Do not follow symbolic links, except while processing the command line
arguments.
-L : Follow symbolic links.
-P : Never follow symbolic links: the default option.
The option [path...] refers to the particular location that you wish to search, whether it be
your $HOME directory, a particular directory such as /usr, your present working directory
which can simply be expressed as '.' or your entire computer which can be expressed as
'/'.
The option [expression] refers to one or a series of options which effect the overall option
of the find command. These options can involve a search by name, by size, by access
time or can also involve actions taken upon these files.
It is important to get into the habit of quoting patterns in your search as seen above or
your search results can be a little unpredictable. Such a search can be much more
sophisticated though. For example if you wished to search for all of the ogg files in your
home directory, some of which you think might be named 'OGG' rather than 'ogg', you
would run:
find $HOME -iname '*.ogg'
Here the option '-iname' performs a case-insensitive search while the wildcard character
'*' matches any character, or number of characters, or zero characters. To perform the
same search on your entire drive you would run:
sudo find / -iname '*.ogg'
This could be a slow search depending on the number of directories, sub-directories and
files on your system. This highlights an important difference in the way that find operates
in that it examines the system directly each time unlike programs like locate or slocate
which actually examine a regularly updated database of filnames and locations.
There are several options with -size, I have used 'M' for 'megabytes' here but 'k' for
'kilobytes' can be used or 'G' for 'Gigabytes'. This search can then be altered to look for
files only that are less than 100 megabytes:
find $HOME -iname '*.ogg' -type f -size -100M
Are you starting to see the power of find, and the thought involved in constructing a
focused search? If you are interested there is more discussion of these combined searches
in the Advanced Usage section below.
This type of search is normally more useful when combined with other find searches. For
example one could search for all ogg files in the $HOME directory that have an access
time of greater than 30 days:
find $HOME -iname '*.ogg' -atime +30
The syntax works from left to right and by default find joins the 2 expressions with an
implied "and". This is dealt with in more depth in the section below entitled "Combining
Searches".
Advanced Usage
The sections above detail the most common usage of find and this would be enough for
most searches. However there are many more possibilities in the usage of find for quite
advanced searches and this sections discusses a few of these possibilities.
Combining Searches
It is possible to combine searches when using find with the use of what is known in the
find man pages as operators. The classic example is the use of a logical AND syntax:
find $HOME -iname '*.ogg' -size +20M
This find search performs initially a case insensitive search for all the ogg files in your
$HOME directory and for every true results it then searches for those with a size of 20
megabytes and over. This contains and implied operator which could be written joined
with an -a. This search can be altered slightly by use of an exclamation point to signify
negation of the result:
find $HOME -iname '*.ogg' ! -size +20M
This performs the same search as before but will look for ogg files that are not greater
than 20 megabytes. It is possible also to use a logical OR in your find search:
find $HOME -iname '*.ogg' -o -iname '*.mp3'
This will perform a case insensitive search in the $HOME directories and find all files
that are either ogg OR mp3 files. There is great scope here for creating very complex and
finely honed searches and I would encourage a through reading of the find man pages
searching for the topic OPERATORS.
This syntax is often used to delete files by using -exec rm -rf but this must be used with
great caution, if at all, as recovery of any deleted files can be quite difficult.
Using xargs
When using a really complex search it is often a good idea to use another member of the
findutils package: xargs. Without its use the message Argument list too long could be
seen signalling that the kernel limit on the combined length of a commandline and its
environment variables has been exceeded. xargs works by feeding the results of the
search to the subsequent command in batches calculated on the system capabilities (based
on ARG_MAX). An example:
find /tmp -iname '*.mp3' -print0 | xargs -0 rm
This example searches the /tmp folder for all mp3 files and then deletes them. You will
note the use of both -print0 and xargs -0 which is a deliberate strategy to avoid problems
with spaces and/or newlines in the filenames. Modern kernels do not have the
ARG_MAX limitation but to keep your searches portable it is an excellent idea to use
xargs in complex searches with subsequent commands.
CommandlineHowto
Contents
1. Introduction
1. What is it?
2. History
1. POSIX
3. Advantages of using
the command line
4. Prerequisites
5. How to invoke it
6. Basic structure and
concepts
2. Command Syntax
1. Single Command
2. Multiple Commands
3. Wildcards
1. Specifing a
single
character
2. Specifying
multiple
characters
3. Specifying a
range
4. Control Flow
1. Redirection
2. Pipe
3. Further reading
Introduction
Even though Ubuntu is the newbie friendly and polished graphical distribution, there are
still situations where a significant amount of time and mouse-clicking can be spared by
typing a bit. I don't think this is a bad thing at all; no matter what you do, Linux has one
of its real strengths in the Command Line!
What is it?
A Command Line is, in all simplicity, a user interface based on lines of commands. You
can say that it is a textual direct serial processor. Most commonly, the user interacts
directly with the computer by typing one line (although it can be more than one), which
triggers actions from the computer based on the syntax of the current processor.
Before everything gets too complicated, we can quite simply move on. The impatient
can move right on to the Command Syntax section.
History
In the early days of computers, there was only the Command Line. The concept of a
Graphical User Interface (GUI) after which most GUI are modeled was developed by
engineers at Xerox's Palo Alto Research Center (PARC). A bit later, Apple paid a
whole bunch of money to be allowed to "study" their GUI idea. And, after a while, Apple
had their own GUI.
Not until 1986 did UNIX get its first GUI, developed by the MIT Project. They named it
X. Linux, however, had to wait ten more years before XFree86 was released. XFree86
was, and is even today, a free adaptation of the original X server.
As mentioned earlier, the CLI (Command Line Interface) was the only way to
communicate with computers before the GUI was invented. In 1969, Bell Telephone
Laboratories released V1 of the UNIX Timeshare System. UNIX had a shell called sh,
which was the only means of communicating with the computer, and it would stay that
way for quite some time.
Later on, there came derivatives of UNIX: HP-UX, 1BSD, Solaris, OpenVMS, IRIX,
SCO XENIX, etc. As time progressed, GNU/Linux emerged. However, the history of
Linux itself is way off the scope of this HOWTO. Suffice to say that alternative CLI to sh
emerged: zsh, ksh, bourne shell, etc.
POSIX
The Wikipedia defines POSIX as the following:
"POSIX is the collective name of a family of related standards specified by the IEEE to
define the application program interface (API) for software designed to run on variants of
the Unix OS. They are formally designated as IEEE 1003 and the international standard
name is ISO/IEC 9945. The standards emerged from a project, begun circa 1985. The
term POSIX was suggested by Richard Stallman in response to an IEEE request for a
memorable name; before that the standards effort was called IEEE-IX. POSIX is a near
acronym for Portable Operating System Interface, with the X signifying the Unix heritage
of the API."
This sounds fancy and all, but to stay rather concise, POSIX is the underlying standard
and functionality of how your CLI responds.
For example, you have been called by the systems administrator that you have used too
much space. You want to quickly work out where the most space is used, so using a
graphical interface, start your timer - go. Now, go to a command line and type:
du | sort -n (we will describe more later). See? It is faster to do some things on the
command line (and other times, easier for graphical).
Prerequisites
This assumes that you are running any version of Ubuntu Linux and have a desire to learn
its inner workings.
How to invoke it
For the purpose of this document, we will invoke the command line interface from the
Desktop.
Ubuntu
Applications | Accessories | Terminal
Kubuntu
KDE Menu | System | Konsole Terminal Program
Xubuntu 6.10
Applications | System | Terminal
An alternative way to invoke the command line, only using keyboard shortcuts (since on
the command line, you would mostly be interacting only through the keyboard) is:
On GNOME (Ubuntu): Alt + F2 -> (Type within the text box) gnome-terminal (Press
return)
On KDE (Kubuntu): Alt + F2 -> (Type within the text box) konsole (Press return)
What you see here is called the prompt. It signifies that the computer is ready and
awaiting user input. In my case, dud is the user that I'm logged in as. shadowplay is the
computer's hostname, and ~ is the current directory (the user's home directory).
Concepts:
Command Syntax
This section will try to give you a good rundown of the basic usage for the bash shell,
which is the default user shell in Ubuntu.
Single Command
The command syntax will vary with each command. Here are some of the basics.
The simplest way to use some commands is to type just the command.
command
Example:
dud@shadowplay:~ $ ls
file1.txt
file2.pdf
file3.mp3
file1.pdf
another_file.txt
Yet-Another_file.txt
file-with_other-NAME.TXT
The above example displays the contents of the current working directory, while other
commands may require one or more arguments.
command <argument>
Example:
dud@shadowplay:~ $ cat file1.txt
Roses are red.
Violets are blue,
and you have the bird-flu!
The above example shows you the content of the file1.txt file by adding the filename as
the argument for the cat command. Almost all commands, whether they have arguments
or not, have options.
command -option
Example:
dud@shadowplay:~ $ ls -r
file-with_other-NAME.TXT
Yet-Another_file.txt
another_file.txt
file1.pdf
file3.mp3
file2.pdf
file1.txt
Using the previous example of showing the current directory, we have added the -r
option. As you can see, the listing of the current working directory has been displayed in
the reverse order.
Multiple Commands
Sometimes the desired task may require the use of more than one command to be
completed. Here is the syntax for the use of multiple commands.
If you want to execute two commands consecutively, then you would use the following
syntax:
command1 ; command2
Example:
dud@shadowplay:~ $grep red file1.txt ; grep blue file1.txt
Roses are red,
Violets are blue,
In the example above, command1 and command2 are executed. However, if you need
command1 to complete successfully before executing command2, then you would use the
following syntax:
Example:
dud@shadowplay:~ $ grep red file1.txt && grep blue file1.txt
Roses are red,
Violets are blue,
dud@shadowplay:~ $ grep purple file1.txt && grep blue file1.txt
dud@shadowplay:~ $
In the example above, you will notice nothing happened when the first command did not
complete successfully. If you want command2 to execute only if command1 fails, then
you would use the following syntax:
command1 || command2
Example:
In the example above, you will notice command2 was only executed when command1
failed.
Wildcards
Wildcards are a useful feature that allows an unknown value or values to be used with
another command. This becomes very useful with commands such as "ls" allowing only a
range of filenames to be displayed.
There are three operators used with wildcards - "*", "?" and "[x-y]".
Specifying a range
If we wanted to know all PDF filenames beginning with "file" and a number between 1
and 5 then we use:
dud@shadowplay:~ $ ls file[2-23].pdf
file2.pdf
file23.pdf
Control Flow
Commands read input from the keyboard (standard input, or stdin) and write to output
(standard out, or stdout). There is also a special output category for error messages called
standard error (or stderr). These three locations are created automatically for each
program.
We can redirect input and output to and from a command.
Redirection
If you wanted the output of a command to go to a file instead of the terminal, then you
would use the following syntax:
Example:
dud@shadowplay:~ $ ls > file4.txt
dud@shadowplay:~ $ cat file4.txt
file1.txt
file2.pdf
file3.mp3
file1.pdf
another_file.txt
Yet-Another_file.txt
file-with_other-NAME.TXT
file4.txt
The above example will create file4.txt if it is not found. NOTE: If file4.txt exists
already, the above command will overwrite its contents. If you want to add to the end of a
existing file, then you would use the following syntax:
Example:
dud@shadowplay:~ $ ls >> file4.txt
dud@shadowplay:~ $ cat file4.txt
file1.txt
file2.pdf
file3.mp3
file1.pdf
another_file.txt
Yet-Another_file.txt
file-with_other-NAME.TXT
file4.txt
file1.txt
file2.pdf
file3.mp3
file1.pdf
another_file.txt
Yet-Another_file.txt
file-with_other-NAME.TXT
file4.txt
In the example, you will notice the file was appended with the new information. Now we
are going to do a different redirection: We are going to take the input from a file for the
command to be executed. Here is the syntax for this redirection:
Example:
dud@shadowplay:~ $ sort < file4.txt
another_file.txt
another_file.txt
file1.txt
file1.txt
file2.pdf
file2.pdf
file3.mp3
file3.mp3
file4.txt
file4.txt
file-with_other-NAME.TXT
file-with_other-NAME.TXT
Yet-Another_file.txt
Yet-Another_file.txt
As you can see from this example, we used the file4.txt as input into the sort command.
Pipe
When you need the output from command 1 for the input into command 2, then you
would use pipe character '|'. Here is the syntax for the pipe character:
command | command
Example:
dud@shadowplay:~ $ ls | sort
another_file.txt
file1.pdf
file1.txt
file2.pdf
file3.mp3
file-with_other-NAME.TXT
Yet-Another_file.txt
The above example is using the output from ls as input to the sort command. You will
notice the list has been sorted.
As you can see, the command line is an easy and powerful way of completing many
tasks. If you want more information on using the command line, then look at the further
reading section of this document.
HowToReadline
<Ctrl><Delete>
This has been part of the default configuration since Kubuntu release 6.06, but is
included here for completeness.
2
Each call to Readline starts in insert mode; the Insert key doesn't "stick" between calls.
A word is defined by Readline to be a sequence of letters or numbers; it is not possible to
change this definition. Other parts of Ubuntu might define a word differently. For
instance, Konsole by default defines the characters in :@-./_~ to be part of a word when
double clicking (see Settings/Configure Konsole).
Keyboard map
Before installing the new Readline configuration file, it is necessary to configure the
terminal emulator to emit a unique byte sequence for each required key combination.
Konsole needs only a small change: with the default XTerm (XFree 4.x.x) keyboard
table, it emits the same byte sequence for <Ctrl><Backspace> as for
<Shift><Backspace>, which is just the same as for <Backspace> on its own.
Attached to this article is myKubuntu.keytab, which configures Konsole to emit the
required byte sequences. The simplest way to install it is to put it in
~/.kde/share/apps/konsole (~ is the conventional notation for "my home directory").
Alternatively, you could make a system-wide change by putting the keytab in
/usr/share/apps/konsole.
Rather than downloading the entire table, you could download the patch in
default.keytab.patch and apply it to the default keyboard table. The default keyboard table
doesn't exist as a .keytab file since it's built into Konsole; instead, it's available in
/usr/share/doc/konsole/README.default.Keytab.gz. To create the new keytab,
issue these commands:
gzip -cd /usr/share/doc/konsole/README.default.Keytab.gz >
myKubuntu.keytab
patch myKubuntu.keytab default.keytab.patch
After installing myKubuntu.keytab as outlined above, start a new Konsole session and
select Settings/Keyboard/XTerm (myKubuntu). If you're happy with this after testing,
select Settings/Save as Default.
If you don't use the default Konsole keyboard table, and need to modify a different keytab
file, a useful technique during development is to start Konsole with the command
konsole --keytab myKubuntu (or whatever name you choose). This allows you to see
any error messages from Konsole, for instance those that say a key combination has been
defined earlier in the keytab file. To verify a key combination, a useful technique is to
start vim, enter Insert mode with i, and enter <Ctrl>v followed by the key combination.
See /usr/share/doc/konsole/README.KeyTab for details of the format of the keytab
file.
[FIXME: not described are the GNOME terminal emulator, the Linux tty console, or
classic xterm.]
Readline configuration
After your terminal emulator is configured to emit the required byte sequences, it's time
to configure Readline. Download the file inputrc and install it either in your home
directory as .inputrc or as a replacement for the existing file /etc/inputrc.
Again, you might prefer to apply a patch instead of installing a complete replacement.
Download inputrc.patch (say, to /tmp) and with root privilege issue the command:
patch --backup /etc/inputrc /tmp/inputrc.patch
Note this creates a backup file, most likely called /etc/inputrc.orig (see patch(1) for
details).
Remember to start a new session before testing and, if necessary, change the keyboard
table.
Summary
You have modified your terminal emulator to emit the byte sequences required by your
custom Readline configuration file. Now Bash and other command-line programs can use
the keys defined in the table above, as well as Home, End, etc.