Linux Commands Examples

A great documentation place for Linux commands


read one line



add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!



Linux command line utility for watching log files live?

There are two things that leap immediately to mind...

tail -f




Monitoring the microphone level with a command line tool in Linux

This solution will avoid writing repeatedly to disk, and even though it in worst case takes a second instead of the desired less than half a second, I found it to be fast enough after trying it. So, here are the two scripts I use:


while true; do
    arecord -d 1 /dev/shm/tmp_rec.wav ; sox -t .wav /dev/shm/tmp_rec.wav -n stat 2>\
    &1 | grep "Maximum amplitude" | cut -d ':' -f 2 | ./
    if [ $? -eq 0 ] ; then
         amixer set Master 0
         amixer set Master 80


#!/usr/bin/env python
import sys

number = 0.0

line = sys.stdin.readline()
thing = line.strip()
number = float(thing)

if number < 0.15:
    raise Exception,"Below threshold"

Hardly elegant, but it works.

Note: If you want a more gradual thing, add something like this:

   for i in `seq 0 80 | tac`; do
      amixer set Master $i

for muting and

   for i in `seq 0 80`; do
      amixer set Master $i

for unmuting.


Remove first N lines from an active log file

No, operating systems like Linux, and it's filesystems, don't make provision for removing data from the start of a file. In other words, the start point of storage for a file is fixed.

Removing lines from the start of a file is usually accomplished by writing the remaining data to a new file and deleting the old. If a program has the old file open for writing, that file's deletion is postponed until the application closes the file.


Command line tool for connecting to wireless (Ubuntu)

Your question is a bit unclear. Do you want to connect to a wireless network? There's a standard tool for this on Ubuntu, the Network Manager. See e.g. for details.

If you cannot use X (which Network Manager needs), you should also be able to set up networking manually, the way Debian does it. Debian offers several mechanisms to do this. The easiest is to just put a block for your interface into /etc/network/interfaces. Sample block for a WLAN network interface:

iface wlan0 inet dhcp
        wpa-ssid MyNetWork
        # plaintext passphrase
        wpa-psk plaintextsecret

Using the config above, you can then type (as root)

ifup wlan0

to activate the interface (ifdown wlan0 to deactivate).

See for more information.


Comparing 2 (or 3 Files If Possible) "Line By Line"

To compare files side-by-side, my favorite tool is Notepad++.

After installing it, on the toolbar click Plugins>Plugin Manager>Available, and check Compare and Install.

After restarting Notepad++, open up the two files (they will open in different tabs), and in the toolbar go to Plugins>Compare>Compare.

There are multiple tweaks you can do, but comparing files looks something like this:

enter image description here

where white text is unchanged, red is removed, green is added, and the sidebar shows an overview of those changes in the two files.


Automating Unix Command Line Application that Asks for Input

I think the missing ingredient is how your display_orders script works (ie without specifics the problem can't be properly solved).

"expect" is definately the "best" solution.

I did, however, come up with a quick-and-nasty hack which might (but probably won't) work for you. If the problem is a slight delay in inputs confusing the display_orders script, and its not time sensitive, you could blindly wait a short period between responses -

sleep 1
echo $Size
sleep 1
echo $Side
sleep 1
echo $Symbol
) | display_orders | mailx -s 'Daily OATS Check'

of-course the sleep 1 can be changed to a longer value and $BROKERA, $SIZE, $Side and $Symbol are already set. Its a cludge because it has no feedback to check if it's answering the right question, and its slow and generally yuk, but it probably does not have any special software prerequisites over and above what is on most systems)


Create multiple files and name them from command line


while read filename; do
  touch $filename
done < filename.txt

This will iterate over each line of filename.txt and create empty file with name in the current line.


How to list files by file owner in Unix command?

I don't think there's anything built in, but you can pipe together a bit of a hack:

find . -ls | sort -k5

This works because on my installation the fifth column (-k5) of output from find is the username. Clearly this isn't portable.


How many characters are in one line?

Your question cannot really be reasonably answered. You're kind of asking the wrong question here.

There is no constant number of characters per line. A line, in the general, technical sense, can be an arbitrarily long sequence of characters that ends with a newline character \n. If that character just doesn't occur, the line can become extremely long. It really depends on the contents of what you write. It's not like in a word processor (or on this web site), where line breaks occur automatically, and the possible line length depends on font size, or page orientation.

In source code, this is also coupled with the difficulty of determining what exactly a line of code is. Do source code comments, that aren't actually code, i.e. processing instructions, count? Do empty lines (lines with only whitespace) count? For source code, there's a metric called Source Lines of Code, or SLOC. This article has some more information about it.

In a linked article, the H states:

It's worth noting that these figures do include the comments, blank lines, documentation, scripts and userland tools included with the kernel (find . -type f -not -regex '\./\.git.*' | xargs cat | wc -l).

So it's really the number of newline characters, including comments, empty lines, etc. of all files excluding the revision control metadata (git) files. This measures the physical lines (counting the \n characters), and really depends on things like source code formatting.


Learning Command Line Basics for Linux

^ This looks like a -really- good site for what you're looking for.


The utility line copies one line (up to a newline) from standard input to standard output. It always prints at least a newline and returns an exit status of 1 on EOF or read error.


The line command is part of the util-linux package and is available from

see also


How can this site be more helpful to YOU ?

give  feedback