Command Line - Ubuntu: Questions and Answers (2014)

Ubuntu: Questions and Answers (2014)

Command Line

Skip to questions, Wiki by user stefano-palazzo

What Questions Should Have This Tag?:

· How do I do this via command line?

· Basic Command Line commands

· Shell Specific commands

Basic Definitions:

Command Line Interface is a way of interacting with the system and software by typing text commands into a terminal (or terminal emulator).

Brief Introduction to the Subject:

"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)

Some users prefer using the command line for some tasks because it saves them time and effort. They also benefit from being able to create scripts to automate common tasks, and they can use the command line to configure their operating system on a very low level to exactly fit their needs.

Important Links for Learning More:

Questions using this tag might be related to Bash - the default command line shell in Ubuntu, Shell-Scripting and Programming.

· The Ubuntu community documentation has a General introduction to the Command Line.

· There is also a longer, more in-depth Command Line How-To.


Q: How do I enable full-color support in Vim?

Tags: command-line (Next Q), vim (Next Q)

I have a lovely Vim colorscheme (xoria256) and it looks brilliant in GVim, but when I use normal vim in Terminal, the colorscheme is only partially supported -- for example, the default semi-transparent aubergine background color is used. How do I make Terminal faithfully render my Vim colorscheme?

Tags: command-line (Next Q), vim (Next Q)

User: david-siegel

Answer by marius-gedminas

GNOME Terminal supports 256 colors, but doesn't advertise its support. You can override vim's autodetection by putting the following:

if $COLORTERM == 'gnome-terminal'

set t_Co=256


in your ~/.vimrc.

Note: if you use GNU screen, it will happily eat those 256-color codes and convert them to basic 16 colors. A better fix is to change TERM to xterm-256color before launching screen/vim.

Answer by dave-jennings

A more general solution is to install the term type "xterm-256color". In 10.04 I think it's installed by default. Previously you needed to install "ncurses-term" to get it.

Then set the term type in .bashrc with something like the following:

if [ -n "$DISPLAY" -a "$TERM" == "xterm" ]; then

export TERM=xterm-256color


If you'd prefer to only have the 256 colour capability for certain programs (perhaps it confuses some others) use instead:

TERM=xterm-256color myprogram

and perhaps set that as an alias for the program.

Then check your terminal colour capabilities with:

$ tput colors


You still may need the vim setting above to have vim recognise it. Most applications will recognise the 256 colours automatically (if they can use them).

Emacs also has colour themes that are much better with 256 colours. To check if it 256-colour capable run:

M-x list-colors-display is Perl script that will display all the colours in your terminal.

Answer by crncosta

Just include the line below into your $HOME/.bashrc (preferably in the last line of the file):

export TERM="xterm-256color"

And save it. After, restart your gnome-terminal. This change will be available not only in vim, but for all your terminal applications.

To check if it works, run this little script:

Skip code block

#!/usr/bin/env python

# Copyright (C) 2006 by Johannes Zellner, <>

# modified by to fit my output needs

# modified by to fit my output needs

import sys

import os

def echo(msg):

os.system('echo -n "' + str(msg) + '"')

def out(n):

os.system("tput setab " + str(n) + "; echo -n " + ("\"% 4d\"" % n))

os.system("tput setab 0")

# normal colors 1 - 16

os.system("tput setaf 16")

for n in range(8):



for n in range(8, 16):





while y < 231:

for z in range(0,6):


y += 1



for n in range(232, 256):


if n == 237 or n == 243 or n == 249:



os.system("tput setaf 7")

os.system("tput setab 0")

Thereafter, you will see something like the following (depends on your gnome-terminal theme):


Tags: command-line (Next Q), vim (Next Q)

Q: How can I tell, from the command line, whether the machine requires a reboot?

Tags: command-line (Next Q), package-management (Next Q)

When you install certain updates (e.g. a new kernel) in Ubuntu Desktop, you get an indication that a reboot is required (in Lucid, the logout icon turns red).

How can I check, from the command line, whether an Ubuntu server requires a reboot?

I could grep for 'System restart required' in /etc/motd, but I'd like a solution that's more elegant. Also, I want a solution that works in older releases, e.g. Hardy (8.04 LTS).

Tags: command-line (Next Q), package-management (Next Q)

User: marius-gedminas

Answer by weboide

You can simply check if the file /var/run/reboot-required exists or not.

For example, any of these would tell you "no such file" or "file not found" if you do not need to reboot, otherwise they will show information about the file:

file /var/run/reboot-required

stat /var/run/reboot-required

ls /var/run/reboot-required

In a bash script, you can use:


if [ -f /var/run/reboot-required ]; then

echo 'reboot required'


Answer by kone4040

Normally if the file


exists you should reboot. You can see if this file is there by using this simple command in gnome-terminal.

ls /var/run/reboot-required

Answer by aquaherd

In the package debian-goodies is a command named checkrestart which is quite useful. Its output can help you avoid a full reboot.

Tags: command-line (Next Q), package-management (Next Q)

Q: Coolest looking terminal IRC client

Tags: command-line (Next Q), software-recommendation (Next Q)

I am looking for a IRC client for the terminal that has colors, user list and just generally looks awesome ;) Any recommendations? There are loads of IRC clients in the repositories and I don't want to download them all to find the best one.

Tags: command-line (Next Q), software-recommendation (Next Q)

User: alvin-row

Answer by tutuca

IRSSI - The client of the future

sudo apt-get install irssi

Say no more

enter image description here

Answer by qbi

I would prefer weechat. Apart from having colors and looking awesome it is very customizable.

screenshot weechat

A very small IRC client is ii, but has no colors out of the box. It is good for using in shell scripts etc.

Tags: command-line (Next Q), software-recommendation (Next Q)

Q: How can I restart x-server from the command line?

Tags: command-line (Next Q)

How can I restart x-server from the command line?

I'd really like to be able to restart my gui without having to do a full system reboot.

Tags: command-line (Next Q)

User: noah-goodrich

Answer by txwikinger

Depending on what display manager, you can use one of the following commands:

· Default Ubuntu (with LightDM)

· sudo restart lightdm

· Gnome (with GDM)

· sudo restart gdm

· KDE (with KDM)

· sudo restart kdm

· For MDM

· sudo restart mdm

Note: From 12.10, Kubuntu also uses LightDM.

Answer by vwduder

For 11.04 and earlier:

sudo service gdm restart

For 11.10 and later:

sudo service lightdm restart

Tags: command-line (Next Q)

Q: How do I determine the total size of a directory (folder) from the command line?

Tags: command-line (Next Q), filesystem (Next Q)

Is there a simple command to display the total aggregate size (disk usage) of all files in a directory (folder)?

I have tried these, and they don't do what I want:

· ls -l, which only displays the size of the individual files in a directory, nor

· df -h, which only displays the free and used space on my disks.

Tags: command-line (Next Q), filesystem (Next Q)

User: david-barry

Answer by marcel-stimberg

The command du "summarizes disk usage of each FILE, recursively for directories," e.g.,

du -hs /path/to/directory

· -h is to get the numbers "human readable", e.g. get 140M instead of 143260 (size in KBytes)

· -s is for summary (otherwise you'll get not only the size of the folder but also for everything in the folder separately)

Answer by geekq

Recently I found a great, ncurses based interactive tool, that quickly gives you an overview about directory sizes. Searched for that kind of tool for years.

· quickly drilldown through file hierarchy

· you can delete e.g. huge temporary files from inside the tool

· extremely fast

Think of it as baobab for the command line:

apt-get install ncdu

Tags: command-line (Next Q), filesystem (Next Q)

Q: How to create a permanent "alias"?

Tags: command-line (Next Q)

If you create an alias for example:

alias cls="clear"

It exists untill you kill terminall session. When you start a new terminal window the alias doesn't exist any more. How to create "permanent" alias, one that exists in every terminal session?

Tags: command-line (Next Q)

User: zango

Answer by php-guru

You can put such aliases in the ~/.bash_aliases file.

That file is loaded by ~/.bashrc. On Ubuntu 10.04, the following lines need to be uncommented to enable the use of ~/.bash_aliases. On Ubuntu 11.04 and later, it's already enabled:

if [ -f ~/.bash_aliases ]; then

. ~/.bash_aliases


Answer by txwikinger

Add your line into ~/.bashrc or into ~/.profile / ~/.bash_profile for remote logins.

If you want the command being executed for all users, put it into /etc/bash.bashrc.

Edit: In the latest versions of Ubuntu, ~/.bashrc automatically sources ~/.bash_aliases, so permanent aliases are best put into this file instead.

Tags: command-line (Next Q)

Q: Moving from bash to zsh

Tags: command-line (Next Q), bash (Next Q)

I'm considering moving from bash to zsh as I often come across posts praising zsh. I'm an experienced command line user and I'm assuming the basics are pretty much the same, so I'm looking for advice to get the benefits of moving, and any gotchas to be aware of.

Please just give one bit of advice per answer. I'm looking for bite-size chunks where I can come back and integrate extra bits of info into my shell usage at a steady pace rather than trying to learn it all in one go.

Tags: command-line (Next Q), bash (Next Q)

User: hamish-downer

Answer by loevborg

As you say, zsh is similar in many respects to bash. It has some features you won't find in bash, and it can be extended in powerful ways. Don't think of moving as a kind of revolution, but rather as a series of evolutionary steps that help you in you daily work. Here are some hints from my .zshrc. Although you say you prefer single pieces of advice, this post is a longish list. Still it is a good idea to go through the points one by one. Just add the interesting bits to you ~/.zshrc and reload with source ~/.zshrc. A final tip: learn the keystrokes of zsh's default ("Emacs") keyboard shortcuts: ^A ^E ^W Alt-F Alt-B Alt-P ^L ^R. You can replace Alt by two separate keystrokes: Alt-P is equivalent to ESC P.

This gives you more extensive tab completion.

autoload -U compinit


Tab completion from both ends.

setopt completeinword

Tab completion should be case-insensitive.

zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'

Better completion for killall.

zstyle ':completion:*:killall:*' command 'ps -u $USER -o cmd'

Changes the definition of "word", e.g. with ^W.

autoload select-word-style

select-word-style shell

Colors for ls.

if [[ -x "`whence -p dircolors`" ]]; then

eval `dircolors`

alias ls='ls -F --color=auto'


alias ls='ls -F'


Shortcuts for ls.

alias ll='ls -l'

alias la='ls -a'

One history for all open shells; store 10,000 entires. This makes this into a useful memory aid to find the commands you used last time for ./configure etc. Use Alt-P (find command that starts like this) and ^R (search in history) liberally.



setopt sharehistory

setopt extendedhistory

Enables all sorts of extended globbing, such as ls */.txt (find all text files), ls -d *(D) (show all files including those starting with "."). To find out more, go to man zshexpn, section "FILENAME GENERATION".

# superglobs

setopt extendedglob

unsetopt caseglob

This is useful to remember command in your history without executing them.

setopt interactivecomments # pound sign in interactive prompt

Type ".." instead of "cd ..", "/usr/include" instead of "cd /usr/include".

setopt auto_cd

Nice prompt.

PS1='[%T] %n@%m:%~# '

Display CPU usage stats for commands taking more than 10 seconds


Some commands you use extensively in Ubuntu.

alias 'a=sudo aptitude'

alias 'ai=sudo aptitude install'

alias 'ar=sudo aptitude remove'

alias 'au=sudo aptitude update'

alias 'ag=sudo aptitude safe-upgrade'

alias 'as=apt-cache search'

alias 'aw=apt-cache show'

Lists packages sorted by their size - useful when deciding which packages are taking up you disk space.

function apt-list-packages {

dpkg-query -W --showformat='${Installed-Size} ${Package} ${Status}\n' | grep -v deinstall | sort -n | awk '{print $1" "$2}'


Answer by qbi

I would recommend the book From bash to Z Shell. It has all the advice you need for switching your shell. It explains the differences of both shells and makes it easy for a new zsher.

Tags: command-line (Next Q), bash (Next Q)

Q: How can I suspend/hibernate from command line?

Tags: command-line (Next Q)

How can I suspend or hibernate my laptop using command line, without installing additional software?

Tags: command-line (Next Q)

User: user1034

Answer by txwikinger

Traditionally ubuntu supported a fairly blunt method of suspend and hibernate. Neither would integrate well with other apps and sometimes not even work on some machines. The new method doesn't require root and notifies all applications listening for power events.

New Method

See the answer here on this page from Adam Paetznick regarding the use of dbus. Ideally you would create a ~/bin/suspend shortcut/script that makes the use of this action easy.

For use over ssh, you should modify policykit rules as outlined by Peter V. Mrch

Old Method

According to the Ubuntu Forum you can use the following commands:

pmi action suspend


pmi action hibernate

This requires that you install the powermanagement-interface package (not tested).

sudo apt-get install powermanagement-interface

I have also found the commands sudo pm-suspend and sudo pm-hibernate to work on my netbook.

Answer by adam-paetznick

The gnome-friendly way is to use dbus.

dbus-send --system --print-reply \

--dest="org.freedesktop.UPower" \

/org/freedesktop/UPower \


There are two advantages to this command over pm-suspend.

1. It will lock your screen (upon resume) if you have that option selected in gnome.

2. It does not require root privilege, so it is easy to add it as a keyboard shortcut, for example.

Note: This is basically the same as qbi's answer, but updated to work for newer versions of Ubuntu.

Answer by greg


If you just want your computer to suspend in one hour because you want to go to bed listening to your favorite radio station, just open terminal and type :

sudo bash -c "sleep 1h; pm-suspend"

and your computer will fall asleep in 1 hour, and when you awake, he will have kept your open images and all your stuff.

you can replace 1h by what you want (h for hours, m for minutes, s for seconds, d for days).

Good night!


Si vous voulez juste que votre ordinateur se mette en veille dans une heure parce que vous voulez vous endormir en ecoutant votre radio prfre, ouvrez Terminal et tapez :

sudo bash -c "sleep 1h; pm-suspend"

et votre ordinateur sendormira dans une heure, et quand vous vous rveillerez, il aura conserv en mmoire vos applications ouvertes.

Vous pouvez remplacer 1h par ce que vous voulez (h pour les heures, m pour les minutes, s pour les secondes, d pour les jours).

Bonne nuit!

Tags: command-line (Next Q)

Q: Change folder permissions and ownership

Tags: command-line (Next Q), permissions (Next Q)

I would like the user to have full rights on this folder (as well as all sub-directories and files in it):


currently owned by root.

I have found numerous posts (in this forum and elsewhere) on how to do this for files but I can't find a way to do it for whole folders.

Tags: command-line (Next Q), permissions (Next Q)

User: user2413

Answer by ikke

Use chown to change ownership and chmod to change rights.

As Pawe Karpiski said, use the -R option to apply the rights for all files inside of a directory too.

Note that both these commands just work for directories too. The -R option makes them also change the permissions for all files and directories inside of the directory.

For example

sudo chown -R username:group directory

will change ownership (both user and group) of all files and directories inside of directory and directory itself.

sudo chown username:group directory

will only change the permission of the folder directory but will leave the files and folders inside the directory alone.

As enzotib mentioned, you need to use sudo to change the ownership from root to yourself.


Note that if you use chown user: file (Note the left-out group), it will use the default group for that user.

Answer by andrewsomething

If you prefer, this can be done with a GUI as well. You will need to open Nautilus as root to do so. Press Alt+F2 to access the "Run Applications" dialog and enter gksu nautilus

Next, browse to and right click on the folder you would like to modify. Then, select "Properties" from the context menu. You can now select the user or group that you would like to be the "Owner" of the folder as well as the permissions you would like to grant them. Finally, press "Apply Permissions to Enclosed Files" to apply the changes recursively.

Though it seems this does not always work for some operations in a deep folder tree. If it does not work use the appropriate terminal command.

alt text

Answer by lucian-adrian-grijincu

Make the current user own everything inside the folder (and the folder itself).

chown $USER -R ~/.blabla

Tags: command-line (Next Q), permissions (Next Q)

Q: How can I add a new user as sudoer using the command line?

Tags: command-line (Next Q), sudo (Next Q)

After I add a user using adduser, I can't see it via System->Administration->Users and Groups unless I logout and then login again. Is that normal?

Also, can I set a newly added user as a sudoer or do I have to change that only after adding it? How can I do that via the shell?

Finally, can I delete the original user that was created upon initial installation of Ubuntu, or is this user somehow 'special'?

Tags: command-line (Next Q), sudo (Next Q)

User: david-b

Answer by ændrük

Just add the user to the sudo group:

sudo adduser <username> sudo

The change will take effect the next time the user logs in.

This works because /etc/sudoers is pre-configured to grant permissions to all members of this group (You should not have to make any changes to this):

# Allow members of group sudo to execute any command


As long as you have access to a user that is in the same groups as your "original" user, you can delete the old one.

Realistically, there are also other groups your new user should be a member of. If you set the Account type of a user to Administrator in Users Settings, it will be placed in at least all of these groups:

adm sudo lpadmin sambashare

Because your system configuration may vary, I suggest taking a look at the output of groups <username> to see what groups are normally in use.

Answer by mithun-p-

Open the sudoers file: sudo visudo will open the /etc/sudoers file in GNU nano. If not, try export EDITOR="nano" and try sudo visudo again.

Add the below line to the end of file.

`username ALL=(ALL) ALL` **Change the user name before you issue the commands**

Then perform WriteOut with Ctrl + O. The editor will ask you for the file name to write into. The default will be /etc/sudoers.tmp:

File Name to Write: /etc/sudoers.tmp

Change that to /etc/sudoers:

File Name to Write: /etc/sudoers

A prompt will be displayed:

File exists, OVERWRITE ?


Save file under DIFFERENT NAME ?

In both cases, press Y. Quit the nano editor with Ctrl + X.


Answer by leszek

I did

sudo usermod -a -G sudo <username>

as recommended here.

Tags: command-line (Next Q), sudo (Next Q)

Q: How to clean launch a GUI app via the Terminal (so it doesn't wait for termination)?

Tags: command-line (Next Q)

Some GUI apps launch cleanly via the Terminal command line.

Some don't, and they cause the Terminal to wait for the app to terminate.
...and even then, some don't "release" the command line.

The mysterious ampersand "&" suffix, seems to cause the terminal to put the process into the background... (but I'm not sure what happens there).

Is there a way to launch an app via the Terminal, so that there is no "hang on" effect? ... just like launching something via F2.

I'd like to have the command line available again, immediately (without something still in the background and writing out system message in the terminal).

Tags: command-line (Next Q)

User: peter.o

Answer by con-f-use

Suppose gedit is the program you want to run detached (aka. "disown", "disentangle", "decouple"). There are different ways depending on what you want to do exactly:

Program already running


disown -h is the way to go if you want to do that with an already running program (i.e. if you forgot to nohup it). You first have to stop it using Ctrl+Z. Then you can put in in the brackground using bg [jobId] (e.g. bg 1). You get a list of running jobs with their jobId using jobs. After that you can decouple it from terminal using disown -h %[jobId]. Example terminal session:

confus@confusion:~$ gedit


[1]+ Stopped gedit

confus@confusion:~$ jobs

[1]+ Stopped gedit

confus@confusion:~$ bg 1

[1]+ gedit &

confus@confusion:~$ disown -h %1

confus@confusion:~$ exit

Program not started yet


nohup is not always present on all machines. If you know you want to decouple beforehand you would use:

nohup gedit &

Maybe you will want to redirect the shell output as well and your program a pseudo input source, so: nohup ./myprogram > foo.out 2> bar.err < /dev/null &. You would want to redirect the output to either not be annoyed by it or to use it later. The null-input can help to prevent hickups in ssh an such.


You can achieve a similar effect by

confus@confusion:~$ (geany 2>&1 /dev/null &)

The brackets open a new subshell to run gedit in. The 2>&1 /dev/null redirects the shell output to nowhere (suppressing the output). And the & at the end puts the process in the background.

Terminal multiplexing

Also terminal multiplexing using screen or byobu. You basically run the program in a terminal of its own. I can really recommend byobu for other reasons too. Below is a list of boybu-shortcuts that might come in handy for your first steps:


· F2 Create a new window

· F3 Move to the next window

· F4 Move to the previous window

· F6 Detach from the session and logout

· Shift-F6 Detach from the session, but do not logout

· F7 Enter scrollback/search mode

· Ctrl-F5 Reconnect any SSH/GPG sockets or agents

Less useful:

Shift-F2 Split the screen horizontally -- Ctrl-F2 Split the screen vertically -- Shift-F3 Move focus to the next split -- Shift-F4 Move focus to the previous split -- Shift-F5 Collapse all splits -- F5 Refresh all status notifications -- F8Rename the current window -- F9 Launch the Byobu Configuration Menu -- F12 GNU Screen's Escape Key -- Alt-Pageup Scroll back through this window's history -- Alt-Pagedown Scroll forward through this window's history -- Ctrl-a-! Toggle all of Byobu's keybindings on or off --

The 'at' deamon and others

at is a nice usefull little tool to run a command at a scheduled time. It can be 'misused' to detach a command from the shell:

echo './myprogram myoption1 myoption2' | at now

Also you can look into setsid and start-stop-daemon, but the other methods should suffice.

Answer by roger-pate

The mysterious ampersand "&" suffix, seems to cause the terminal to put the process into the background... (but I'm not sure what happens there).

It does, and is often what you want. If you forget to use &, you can suspend the program with ctrl-z then place it in the background with the bg command and continue to use that shell.

The process' stdin, stdout, and stderr are still connected to the terminal; you can redirect those from/to /dev/null or any other file (e.g. save an output log somewhere), as desired:

some-program </dev/null &>/dev/null &

# &>file is bash for 1>file 2>&1

You can see the process in jobs, bring it back to the foreground (fg command), and send it signals (kill command).

Some graphical programs will detach from the terminal; if that's the case, when you run the command "normally" you'll notice it starts the graphical program and "exits".

Here's a short script, you can place it in ~/bin, which I named runbg:

Skip code block


[ $# -eq 0 ] && { # $# is number of args

echo "$(basename $0): missing command" >&2

exit 1


prog="$(which "$1")" # see below

[ -z "$prog" ] && {

echo "$(basename $0): unknown command: $1" >&2

exit 1


shift # remove $1, now $prog, from args

tty -s && exec </dev/null # if stdin is a terminal, redirect from null

tty -s <&1 && exec >/dev/null # if stdout is a terminal, redirect to null

tty -s <&2 && exec 2>&1 # stderr to stdout (which might not be null)

"$prog" "$@" & # $@ is all args

I look up the program ($prog) before redirecting so errors in locating it can be reported. Run it as "runbg your-command args..."; you can still redirect stdout/err to a file if you need to save output somewhere.

Except for the redirections and error handling, this is equivalent to htorque's answer.

Answer by florian-diesch

Use nohup

nohup is a program that runs a given command with hangup signals ignored, so that the command can continue running in the background after its parent process terminates. See the manpage

For example:

nohup gedit something

Tags: command-line (Next Q)

Q: How to send mail from the command line?

Tags: command-line (Next Q)

How to send mail from the command line?

Tags: command-line (Next Q)

User: olivier-lalonde

Answer by crncosta

Try to install The Mutt E-mail Client. Other option is using emacs with gnus. Others options available too... IMHO, you should use more details in your questions, or several different answers to your question you will receive :-)

Answer by sid

· Install ssmtp Install ssmtp: sudo apt-get install ssmtp

· Edit the ssmtp config file : gksu gedit /etc/ssmtp/ssmtp.conf

· Enter this in the file:




· AuthUser=username

· AuthPass=password

· FromLineOverride=YES


· Enter the email address of the person who will receive your email:

· ssmtp

· Now enter this:

· To:

· From:

· Subject: Sent from a terminal!

Your content goes here. Lorem ipsum dolor sit amet, consectetur adipisicing.

· To send the email: Ctrl + D

You can also save the text mentioned in Point 5 into a text file and send it using:

ssmtp < filename.txt

Answer by marco-ceppi

Most of the time you shouldn't need to configure an SMTP server you can simply use mail from the commandline. (Or if you're on a server where sendmail is configured, etc)

marco@dagobah:~$ mail -v

Subject: Hello World!

This is an email to myself.

Hope all is well.



You terminate messages with a . on a single line. That's when mail will prompt you for Cc: enter the information (or leave blank) and mail will then print out additional information on what it is attempting to do, as well as detailing the processing of connecting, transmitting, and receiving data from the mail server.

Tags: command-line (Next Q)

Q: What to do when Ctrl-C won't kill running job?

Tags: command-line (Next Q), bash (Next Q)

Sometimes, processes ignore the SIGINT signal sent by Ctrl-C in Bash. For instance, man and vi. Assuming you don't want to google or read the manual on how to exit the running process, is there any key sequence that will alwayswork (without leaving the terminal)?

Tags: command-line (Next Q), bash (Next Q)

User: olivier-lalonde

Answer by stefano-palazzo

Send the SIGQUIT signal with Ctrl+\.

.. $ sleep 10


This is equivalent to kill -3 pid. Programs run in user-space don't ignore sigquit.

There is also a set of Magic SysRq keyboard shortcuts. One of the more interesting ones is this: Alt+SysRq+k. It kills every process on the current virtual console. If one of your ttys is completely and utterly broken, this can be used to go back. On the tty running, it can be used to kill X without mercy.

The SysRq key is, on most keyboards, the same as the Print Key. On my notebook, it can be invoked using the Fn key; I.e. AltFnPrintk in that order.

Here are some of the basic process management shortcuts:

· Ctrl+Z: pause a process (plus bg to resume in the background, fg to raise to foreground )

· Ctrl+C: politely ask the process to shut down now

· Ctrl+\: mercilessly kill the process that is currently in the foreground

· Alt+SysRq+s: Write data to disk (always do this before killing anything important)

· Alt+SysRq+s, k: mercilessly kill all current processes on a given virtual console

· Alt+SysRq+s, b: mercilessly reboot without unmounting,

· Alt+SysRq+r, e, i, s, u, b: Safely reboot even if the system is utterly broken,

Note: Ctrl+Z, in contrast to Ctrl+C and Ctrl+\, also works for man, vi, less, and the like.

When in doubt, the follwing procedure will almost always work:

Skip code block

~$ sleep 10


[5]+ Stopped sleep 10

~$ ps


4804 pts/0 00:00:00 bash

6207 pts/0 00:00:00 sleep

6208 pts/0 00:00:00 ps

~$ kill -9 6207

[5]+ Killed sleep 10


^Z of course indicates that Ctrl+Z has been pressed.

For a more in-depth look at Shells and Terminals, also see my answers on:

· What are shells

· Why is a Virtual Terminal virtual, and what/why/where is the real Terminal?

A mistake in this answer kindly corrected by Juliano.

Tags: command-line (Next Q), bash (Next Q)

Q: Why is a virtual terminal "virtual", and what/why/where is the "real" terminal?

Tags: command-line (Next Q)

I hope the question is self-explanatory.

My understanding is that gnome-terminal and konsole are virtual terminals, and they are basically serving the same purpose, i.e. a command line environment for various optional command interpreters. (I'm not even sure if that's the right way to look at it.)

I assume that the real terminal is where I am teleported to occasionaly by mis-keying Ctrl+Alt+F1,F2, etc.

But "There be Dragons" in that black-screen hinterland, so I'm outta-there as quickly as I can press Ctrl+Alt+F7 (I learnt that somewhere: "When all is black and dark: press the secret keys to return :)

· Is/are the "real" terminal(s) the one(s) that exist behind the Ctrl+Alt+F1,F2, etc. keys?

· And what is so "real" about them vs the "virtual" ones?

· And how to they differ? Is it as simple as "no GUI" vs "GUI"?

P.S. are "console" and "terminal" synonymous?

Tags: command-line (Next Q)

User: peter.o

Answer by stefano-palazzo

basically serving the same purpose: ie. A command line environment for various optional command interpreters

This isn't strictly true. Virtualy Terminals are merely programs that send keystrokes and recieve output (this is called Standard In, Standard Out[ and Standard Error]) to a process in the background. This is a basic input processingoutput system, and is at the heart of your operating system.

A teletype (or teleprinter)

Man working at a Computer Terminal

Let's see if I can explain it properly

In a Unixlike system such as Linux there is the concept of "everything is a file". That means, for example, your DVD Drive is a file (/dev/sdb1), your keyboard is a file (/dev/input/keyboard) and so on.

Another set of those magical files are the TTYs, where TTY stands for Teletype. A Typewriter that sends keystrokes to a computer, which in turn sends letters back to the Type Ball. This would have represented a physical device, a remote typewriter, in the same way as /dev/lp0 may represent your printer.

a terminal emulator, the VT100

The Teletype workstations would have been called "Consoles" or "Terminals", a virtual terminal, as opposed to a real one, thus is any application or machinery that provides the same functionality as this workplace arrangement - which is accessing the computer by sending keystrokes to it and receiving output back from it, printing it to a piece of paper. You can imagine that a Modem works in a very similar way.

Terminal Emulators, such as the one pictured above, are cheap and simple computers that emulate the functionality of a teletype. When we say terminal emulator these days, we - in turn - usually mean a program that emulates the functionality of such a machine.

There are still Terminal based computer systems in use. They are in fact getting ever more popular. In the past, the reason for Terminals was that a computer at every desk was completely ridiculous - where computers filled a room and were immensely expensive. Now, it saves money and makes administration easy.

a "thin client" the modern equivalent of the VT100

I hope that this is helpful. Please alert my if I've made a mistake.

Does that mean that Control-Alt-F1,F2,etc are also virtual terminals, and the only difference between them and "gnome-terminal" / "konsole" is that they don't have a GUI?

Yes, basically. The difference between TTY1-7 and gnome-terminal is that the system provides the ttys, whereas gnome-terminal and konsole are themselves running on a tty (which is running the graphical subsystem). This abstraction can be nested even deeper (e.g. x-forwarding, using the telnet protocol to act as a terminal, ...), after all, the humancomputer interface acts just like any other file. And can be piped, abstracted and moved about in the same way.

Answer by hbdgaf

Pretty sure calling it a "virtual terminal" is a throwback to when there were physical terminals connected to unix servers...

Tags: command-line (Next Q)

Q: How to become a Terminal Pro

Tags: command-line (Next Q)

There are rumors. These rumors claim that there are nerd on this hell of a planet who don't touch a mouse. They are my heroes :D

How can I become such a pro?

(I used to know a site, like stackoverflow, where you could upvote really cool commands, like twittering from terminal etc.)

Tags: command-line (Next Q)

User: jai-puri

Answer by sid

For starters, I'd recommend:

· The Linux Cookbook: Tips and Techniques for Everyday Use

· Your One Stop Command Line Shop!

· Ubuntu Linux Toolbox: 1000+ Commands for Ubuntu and Debian Power Users

· One of my favorite Stack Exchange community wikis: What are your favorite command line features or tricks?

· Bonus: Command Line xkcd webcomic:

Answer by paweł-karpiński

look at this address:

Tags: command-line (Next Q)

Q: How can you log out via the terminal?

Tags: command-line (Next Q)

Is there a command, that will take you back to the login screen?

Tags: command-line (Next Q)

User: thex

Answer by stefano-palazzo

11.10 and above


11.04 and previous versions

dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1

(via alt textDoR, see his answer to "Reboot without sudoer privileges?" for more dbus goodness!)

or alternatively, you can use

gnome-session-save --force-logout

--force-logout in contrast to just --logout will not ask the user to deal with unsaved documents and so on.

is this the easiest way? no simple one line command like sudo logout?? I will never remember all that.

Yes, there is a command called logout, but it concerns the Terminal. gnome-session-save is the program that actually quits the gnome-session, which you can of course kill, but that wouldn't qualify as logging out. :-)

Notice as well that these commands don't require you to be root.

You can always add an alias to your system if you want to have a shorter command.

Open ~/.bash_aliases with a text editor, or create it if it isn't there, and add something like this to it:

alias logout-gnome="gnome-session-save --force-logout"

(.bashrc is a script that is run every time a new virtual terminal is started up, you should set up all your permanent aliases there, see also: How to create a permanent "alias"?)

Answer by nick

11.10 and above

Here's my personal solution!

In the terminal, run:

gedit ~/.bash_aliases

And add:

alias log-out="gnome-session-quit"

to the file! Now you just have to run log-out!

Answer by dan

I had installed mate desktop and none of the menus worked, even the f-keys didn't work. I managed to get xterm through browsing with file manager.

The only thing that worked was :

sudo pkill -u username

Tags: command-line (Next Q)

Q: Progress and speed with 'cp'?

Tags: command-line (Next Q), coreutils (Next Q)

When copying files using cp, is it possible to display the progress and speed of the transfer? Otherwise, is there any alternative command line utility that can achieve this?

Tags: command-line (Next Q), coreutils (Next Q)

User: olivier-lalonde

Answer by stefano-palazzo

While cp hasn't got this functionality, you can use pv to do this:

pv my_big_file > backup/my_big_file

Note: this method will lose the file's permissions and ownership. Files copied this way will have the same permissions as if you'd created them yourself and will belong to you.

In this example, pv basically just outputs the file to stdout*, which you redirect to a file using the > operator. Simultaniously, it prints information about the progress to the terminal when you do that.

This is what it looks like:

stefano@ubuntu:~/Data$ pv my_big_file > backup/my_big_file

138MB 0:00:01 [73.3MB/s] [=================================>] 100%

You may need to Install pv (alternatively, type sudo apt-get install pv) on your system.

*: The technical bit

There are three important streams of data in a unix-like system: stdout (standard output), stderr (standard error) and stdin (standard input). Every program has all three, so to speak. The pipe-operator redirects a programs output to another programs input. The > operator redirects a programs standard output to a file. cp basically does nothing fancier than

cat source > destination

(where cat just reads a file and prints it to stdout). pv is just like cat, but if you redirect it's output stream somewhere else, it will print progress information to stdout instead.

Take a look at man pv to learn more about it.

Another option, as alt textDoR suggests in this answer, is to use rsync instead:

rsync -ah --progress source-file destination

alt text

This will preserve the files permissions/ownership while showing progress.

Answer by user76204

If you want to see if your files are transferring correctly you could use gcp and gcp is like cp but by default gives you a progress bar so that you can see what is being copied. As the program's wiki notes, gcp has several useful features such as

· transfer progression indication

· continuous copying on error (skip to next file)

· copy status logging: gcp logs all its actions so that it is possible to know which files have been successfully copied

· name mangling to handle target filesystem limitations (for example deletion of incompatible characters "*" or "?" on FAT)

However, even when the progress bar has reached 100% when using the tool, you must wait until your terminal prompt reappears before safely removing your media so that you can ensure that the transfer process has successfully finished.

gcp is used to copy files and has options such as --preserve so that various attributes and permissions can be preserved and --recursive so that whole directories can be copied. More information on its options can be found by entering man gcp or by going to the Ubuntu manpages online. A tutorial is also available on this site.

Install gcp from the repositories with

sudo apt-get install gcp

(Note: in Ubuntu 12.10 the new automount point is, for example, /media/user/usbdisk)

You can copy a file to your media by entering

gcp /home/mike/file.mp4 /media/usb

and copy a folder to your media with

gcp -rv ~/Podcasts /media/Mik2

Sample output from gcp with the progress bar:

gcp ~/Videos_incIplayer/mars.flv /media/Mik2

Copying 168.57 MiB 100% |########################################################| 7.98 M/s Time: 00:00:22

You can of course specify multiple files or folders to copy to your disk, and there are a lot of other options covered in man gcp.

Answer by user35186

There isn't. See here as to why. Although it does more than you need, rsync has one with --progress parameter. The -a will keep permissions,etc, and -h will be human readable.

rsync -ah --progress source destination

Tags: command-line (Next Q), coreutils (Next Q)

Q: What do the different colors mean in the terminal?

Tags: command-line (Next Q)

What does the different colours in Ubuntu mean? For example, when I type 'ls' in one of my folders, I get one of the files in light green, the other (which is a folder) in blue with green high lighting. What does those colours mean, and there is any manual about all the colours?

Tags: command-line (Next Q)

User: rafid

Answer by karthick87

Blue color - Directory

Green color - Executable or recognized data file

Sky Blue Color - Linked file

yellow with black background - device

Pink colour - graphic image file

Red - Archive file

For your Information:

· To turn the color off, you have to comment out the following lines in .bashrc.
alt text

· Also if you want to see your own bash color meanings,then copy/paste the following codes in your terminal.

· eval $(echo "no:global default;fi:normal file;di:directory;ln:symbolic link;pi:named pipe;so:socket;do:door;bd:block device;cd:character device;or:orphan symlink;mi:missing file;su:set uid;sg:set gid;tw:sticky other writable;ow:other writable;st:sticky;ex:executable;"|sed -e 's/:/="/g; s/\;/"\n/g')

· {

· IFS=:

· for i in $LS_COLORS

· do

· echo -e "\e[${i#*=}m$( x=${i%=*}; [ "${!x}" ] && echo "${!x}" || echo "$x" )\e[m"

· done

· }

alt text


· For more informations type man dir_colors in terminal.

Answer by stefano-palazzo

You can find out what colours ls uses by looking at the $LS_COLORS variable:

· Turquoise: audio files1

· Bright Red: Archives and compressed files2

· Purple: images and videos3

In addition, files are colourised by attributes:

alt text

· 1:, aac, au, flac, mid, midi, mka, mp3, mpc, ogg, ra, wav, axa, oga, spx, xspf.

· 2:, tar, tgz, arj, taz, lzh, lzma, tlz, txz, zip, z, Z, dz, gz, lz, xz, bz2, bz, tbz, tbz2, tz, deb, rpm, jar, rar, ace, zoo, cpio, 7z, rz.

· 3:, jpg, jpeg, gif, bmp, pbm, pgm, ppm, tga, xbm, xpm, tif, tiff, png, svg, svgz, mng, pcx, mov, mpg, mpeg, m2v, mkv, ogm, mp4, m4v, mp4v, vob, qt, nuv, wmv, asf, rm, rmvb, flc, avi, fli, flv, gl, dl, xcf, xwd, yuv, cgm, emf, axv, anx, ogv, ogx.

all this information is contained in the output of dircolors --print-database, but it's formatting is rather unreadable.

Here's a technical explanation of what's happening:


CHR 40;33;01

The colour code consists of three parts:

· The first part before the semicolon represents the text style.

o 00=none, 01=bold, 04=underscore, 05=blink, 07=reverse, 08=concealed.

· The second and third part are the colour and the background color:

o 30=black, 31=red, 32=green, 33=yellow, 34=blue, 35=magenta, 36=cyan, 37=white.

Each part can be omitted, assuming starting on the left. i.e. "01" means bold, "01;31" means bold and red. And you would get your terminal to print in colour by escaping the instruction with \33[ and ending it with an m. 33, or 1B in hexadecimal, is the ascii sign "ESCAPE" (a special character in the ascii character set). Example:

"\33[1;31mHello World\33[m"

Prints "Hello World" in bright red.

the command ls with the argument --color=auto, and on Ubuntu, ls is an alias for ls --color=auto, goes through all the file names and tries first to match different types, like Executable, Pipe and so on. It then tries to match regular expressions like *.wav and prints the resulting filename, enclosed in these colour-changing instructions for bash.

Tags: command-line (Next Q)

Q: Find and replace text within a file using commands

Tags: command-line (Next Q)

How can I find and replace specific words in a text file using command line?

Tags: command-line (Next Q)

User: jon-doe

Answer by cscarney

sed -i 's/original/new/g' file.txt


· sed = Stream EDitor

· -i = in-place (i.e. save back to the original file)

· The command string:

o s = the substitute command

o original = a regular expression describing the word to replace (or just the word itself)

o new = the text to replace it with

o g = global (i.e. replace all and not just the first occurrence)

· file.txt = the file name

Answer by marco-ceppi

There are a number of different ways to do this. One is using sed and Regex. SED is a Stream Editor for filtering and transforming text. One example is as follows:

marco@imacs-suck: ~$ echo "The slow brown unicorn jumped over the hyper sleeping dog" > orly

marco@imacs-suck: ~$ sed s/slow/quick/ < orly > yarly

marco@imacs-suck: ~$ cat yarly

The quick brown unicorn jumped over the hyper sleeping dog

Another way which may make more sense than < strin and > strout is with pipes!

marco@imacs-suck: ~$ cat yarly | sed s/unicorn/fox/ | sed s/hyper/lazy/ > nowai

marco@imacs-suck: ~$ cat nowai

The quick brown fox jumped over the lazy sleeping dog

Tags: command-line (Next Q)

Q: How to create an empty file from command line

Tags: command-line (Next Q)

How can I create an empty file from the command line?

Tags: command-line (Next Q)

User: nes

Answer by alvin-row

Use the touch command:

The touch utility sets the modification and access times of files to the

current time of day. If the file doesn't exist, it is created with

default permissions.


touch newfile

Answer by balki

> newfile

Will also create an empty file. If the file does already exist, it will be truncated (emptied). To keep the file contents, use >> for appending as in:

>> file

Even if the file exists, the contents will be untouched.

Edit: If you don't have any content to type, this one is faster:

user@host$ :> newfile

user@host$ :>> new_or_existing_file

Note. : is the command here. It is not part of the prompt.

Tags: command-line (Next Q)

Q: What is the difference between ./ and sh to run a script?

Tags: command-line (Next Q), scripts (Next Q)

I have written a simple script. When I runsh <>, i got the correct output, but when I run ./<>, I got an error.

What is difference between when I do sh and ./?

Tags: command-line (Next Q), scripts (Next Q)

User: mr_eclair

Answer by martin-owens--doctormo-

When you run any script by passing the filename to the script interpreter program, you are running the interpreter program with the script as an argument passed into it. For example this would look like the process 'sh' with the argument ''. The sh interpreter is opening the file.

On the other hand if you run the script itself, the system calls out to the interpreter program specified and feeds in the scripts contents. In this case the process looks like '' with no arguments.

You should make sure you have a bang line:


# bash script here

A bang line is the very first line in the script and starts with the same two characters #!, these are what the system reads when it tries to execute the script and then the system passes the the script to the program immediately after. Note that this line isn't anything to do with bash and works just as well for python and perl, even though they're very different languages. You would use #!/usr/bin/python for example and then follow it with python code.

Once you have your script, make sure you have set execute permissions:

chmod a+x

Then you can run the script as its own process:


Or put the file into a known location with a nice program name, like /usr/sbin and run from anywhere:

sudo cp /usr/sbin/program-name


And this is really the practical benefit of using the bang line with the right permissions - it's all about deployment. It's very hard to get users to run a script if they have to remember what program to run the script with. Remember to give a full path to the script every time they want to run it. Where as putting it in /usr/local/bin for example, and making it executable, can save an awful lot of grief for people trying to use your script. These programs then become available to all users on the your computer.

It's also good for identification. If you go into the top program, a script run without the bang line will just have the name of the interpreter i.e. bash, perl or python. But if a script is run with the right permissions, then the name of the script shows.

Note: If you want to distribute a script that's accessible to everyone, then please create a man page and a deb package to install it. We need to reduce the number of random scripts online and increase the number of debs which can be uninstalled.

Answer by stefano-palazzo

The short version:

· sh is the command line interpreter (dash).
Running sh my_script makes dash interpret the script.

· ./ tries to find out which interpreter to use, by looking at the first line. E.g. #!/bin/bash, or even #!/bin/ruby (as oppsed to running ruby my_script).

Tags: command-line (Next Q), scripts (Next Q)

Q: How to protect Ubuntu from fork bomb

Tags: command-line (Next Q), security (Next Q)

I heard someone talking about a fork bomb, I did some research and found some dreadful information about some strange looking characters people can have you type at the command line and as a result do bad things on the computer. I certainly would not issue commands I do not understand but one never knows what can happen.

I heard that some OS allows the administrator to place some limit on user processes to mitigate the effects of fork bombs, is this protection in Ubuntu by default or would a person with sudo privilege have to set this? If so, how?

Tags: command-line (Next Q), security (Next Q)

User: dblang

Answer by marco-ceppi

You can easily limit the amount of processes that can be spawned in Ubuntu and most other Linux distributions by modifying /etc/security/limits.conf

sudoedit /etc/security/limits.conf

Then add this line to the bottom of that file

* hard nproc 800

You can raise this to whatever number you want - nproc is simply the maximum number of processes that can exist simultaneously on the machine. On my Lucid laptop running standard things: Gwibber, email client, web browser, chat I have about 200 processes running simultaneously - so you may need to adjust the number to your needs.

After this limit is put into place, you'll need to reboot, but it will affect each account on the system. So if a fork bomb is executed as any user (root included) it'll have that hard limit.

If you're not looking to restart anytime soon, you can use sudo ulimit -u 800 which will place the restriction only on the current running session. After restart, whatever is in /etc/security/limits.conf will be used (until ulimit is run again).

Some additional information about fork bombs. They aren't malware or anything dreadful. They typically consist of something as basic as a script that calls itself twice - thereby growing its presence on the machine exponentially. Even though they have a small memory footprint given the rapid pace they multiple they quickly fill all available RAM and the machine reboots. The only danger is loosing unsaved information. I would classify a forkbomb much more as a prank than malicious.

An important reminder:

You should rarely ever execute anything in commandline when you aren't 98% certain of its action. If you can't read the commands you're executing - don't do it. This applies double to unreadable chunks of hex/base64 characters, which can be used to obscure all sorts of nastiness. If you're uncertain of a command you can always search for it's actions in the Ubuntu Manpages and be extra cautions when using sudo since that will execute as the root user.

Tags: command-line (Next Q), security (Next Q)

Q: How to really clear the terminal?

Tags: command-line (Next Q)

I can issue the clear command or press Ctrl + L to clear the current Ubuntu terminal, but this just shifts previous output upwards and if you use mouse scroll or PgUP and PgDown keys it's hard to distinguish where the output of previous command ends and output of current command begins.

Is there a way to really clear the terminal so I won't see previous command results?


Tags: command-line (Next Q)

User: stann

Answer by stefano-palazzo

Yes, the command you're looking for is


In contrast to clear, or Ctrl+L, reset will actually completely re-initialise the terminal, instead of just clearing the screen. However, it won't re-instantiate the shell (bash). That means that bash's state is the same as before, just as if you were merely clearing the screen.

From the other answers:

· You can set a Keyboard Shortcut to reset the terminal, as explained by towolf.

· If you're running Kubuntu, and your terminal is Konsole, you need to go to Edit Clear history, since reset doesn't work the same way there, as UncleZeiv notes.

Answer by towolf

You can also assign a shortcut in gnome-terminal by going to Edit Keyboard Shortcuts. I use Ctrl+Alt+C.

reset and clear shortcut

Tags: command-line (Next Q)

Q: Torrent client for the command-line?

Tags: command-line (Next Q), software-recommendation (Next Q), bittorrent (Next Q)

Yesterday one of my friends asked me, if there is some torrent client, that runs on the command-line.

I have no answer for him, but I think that you have it.

Tags: command-line (Next Q), software-recommendation (Next Q), bittorrent (Next Q)

User: wolfy

Answer by djeikyb


It is controllable by GUI, Web, and Console. Install Deluge.

To setup remote access to a deluge server see the Thinclient guide.

deluge-consoleInstall Deluge


deluge-gtkInstall Deluge

standard deluge gtk ui

deluge-webInstall Deluge(http://localhost:8112)

deluge web ui

Answer by sagarchalise

I think the default torrent client transmission itself has a cli interface and can be installed with

sudo apt-get install transmission-cli

Answer by simon-richter

I use rtorrent on a headless server to serve Debian and Ubuntu ISOs, works quite well and can saturate my network link. Dependencies and memory usage are minimal.

Tags: command-line (Next Q), software-recommendation (Next Q), bittorrent (Next Q)

Q: How do you select the fastest mirror from the command line?

Tags: command-line (Next Q), apt (Next Q)

I want to update my sources.list file with the fastest server from the command line in a fresh Ubuntu Server install. I know this is trivially easy with the GUI, but there doesn't seem to be a simple way to do it from from the command line?

There are two different working answers to this question below:

1. Use apt-get's mirror: method
This method asks the Ubuntu server for a list of mirrors near you based on your IP, and selects one of them. The easiest alternative, with the minor downside that sometimes the closest mirror may not be the fastest.

2. Command-line foo using netselect
Shows you how to use the netselect tool to find the fastest recently updated servers from you -- network-wise, not geographically. Use sed to replace mirrors in sources.list.

The other answers, including the accepted answer, are no longer valid (for Ubuntu 11.04 and newer) because they recommended Debian packages such as netselect-apt and apt-spy which do not work with Ubuntu.

Use sed to replace mirrors in sources.list

sudo sed -i 's/' /etc/apt/sources.list

Tags: command-line (Next Q), apt (Next Q)

User: evan

Answer by rinzwind

Pakket netselect-apt

dapper (net): Choose the fastest Debian mirror with netselect


0.3.ds1-5: all

hardy (net): Choose the fastest Debian mirror with netselect


0.3.ds1-11: all

Pakket apt-spy

dapper (admin): writes a sources.list file based on bandwidth tests


3.1-14: amd64 i386 powerpc

Not included in newer Ubuntu due to secturity issues it seems: see: Bug report

But .. I normally just use ping to find out the speed of a connection to some location. Amount of hops and latency.

Answer by badp

You don't have to do any searching anymore - as ajmitch has explained, you can use deb mirror to have the best mirror picked for you automatically.

apt-get now supports a 'mirror' method that will automatically select a good mirror based on your location. Putting:

deb mirror:// precise main restricted universe multiverse

deb mirror:// precise-updates main restricted universe multiverse

deb mirror:// precise-backports main restricted universe multiverse

deb mirror:// precise-security main restricted universe multiverse

on the top in your /etc/apt/sources.list file should be all that is needed to make it automatically pick a mirror for you based on your geographical location.

Lucid (10.04), Maverick (10.10), Natty (11.04), and Oneiric (11.10) users can replace precise with the appropriate name.

Answer by izx

Here's one way that will always work, using good old netselect and some grep magic:

The terminal-addict's "find best server" hack!

· Download and dpkg -i netselect for your architecture from the Debian website. (it's about 125 KB, no dependencies)

· Find the fastest Ubuntu mirrors from your location, either up-to-date or at most six hours behind with this (I'll explain it below, sorry it doesn't split up nicely in Markdown)

· sudo netselect -v -s10 -t20 `wget -q -O- | grep -P -B8 "statusUP|statusSIX" | grep -o -P "(f|ht)tp.*\"" | tr '"\n' ' '`

· netselect:

1. -v makes it a little verbose -- you want to see progress dots and messages telling you different mirrors mapping to the same IP were merged :)

2. -sN controls how many mirrors you want at the end (e.g. top 10 mirrors)

3. -tN is how long each mirror is speed-tested (default is 10; the higher the number, the longer it takes but the more reliable the results.)

· This is the backquotes stuff (don't paste, just for explanation)

· wget -q -O-

· | grep -P -B8 "status(UP|SIX)"

· | grep -o -P "(f|ht)tp.*\""

· | | tr '"\n' ' '

1. wget pulls the latest mirror status from

2. The first grep extracts mirrors that are up-to-date or six-hours behind, along with 8 lines of previous context which includes the actual ftp/http URLs

3. The second grep extracts these ftp/http URLs

4. tr just converts linebreaks to spaces, since netselect wants its list of servers to test that way.

· Here's a sample output from California, USA:

· 60

· 70

· 77

· 279

· 294

· 332

· 364

· 378

· 399

· 455

o The "ranks" are an arbitrary metric; lower is usually better.

o If you're wondering why the Sweden-EU mirror and an NZ mirror are in the top three from California, well, so am I ;-) The truth is that netselect doesn't always choose the most appropriate URL to display when multiple mirrors map to a single IP; number 3 is also known as!

Tags: command-line (Next Q), apt (Next Q)

Q: How do I install a .deb file via the command line?

Tags: command-line (Next Q), software-installation (Next Q)

How do I install a .deb file via the command line?

Tags: command-line (Next Q), software-installation (Next Q)

User: thex

Answer by luis-alvarado

Packages are manually installed via the dpkg command (Debian Package Management System). dpkg is the backend to commands like apt-get and aptitude, which in turn are the backend for GUI install apps like the Software Center and Synaptic.

Something along the lines of:

dpkg --> apt-get, aptitude --> Synaptic, Software Center

But of course the easiest ways to install a package would be, first, the GUI apps (Synaptic, Software Center, etc..), followed by the terminal commands apt-get and aptitude that add a very nice user friendly approach to the backend dpkg, including but not limited to packaged dependencies, control over what is installed, needs update, not installed, broken packages, etc.. Lastly the dpkg command which is the base for all of them.

Since dpkg is the base, you can use it to install packaged directly from the command line.


sudo dpkg -i DEB_PACKAGE

For example if the package file is called askubuntu_2.0.deb then you should do sudo dpkg -i askubuntu_2.0.deb. If dpkg reports an error due to dependency problems, you can run sudo apt-get install -f to download the missing dependencies and configure everything. If that reports an error, you'll have to sort out the dependencies yourself by following for example How do I resolve unmet dependencies?.


sudo dpkg -r PACKAGE_NAME

For example if the package is called askubuntu then you should do sudo dpkg -r askubuntu.

Answer by atul-makwana

Debian (.deb) packages are the packages that are used in Ubuntu. You can install any .deb package in your system. .deb files can generally be installed from your file manager (Nautilus) merely by clicking on them, since file associations with the default installer is already set in Ubuntu. These instructions are for those who wish to install packages from the command-line terminal (Terminal).

To install a downloaded Debian (Ubuntu) package (.deb): Open Terminal and type

sudo dpkg -i packagename.deb

To remove a Debian (Ubuntu) package (.deb):

sudo dpkg -r packagename

To Reconfigure/Repair an installed Debian (Ubuntu) package (.deb):

sudo dpkg-reconfigure packagename

Answer by dsto

My favourite is GDebi, available from both terminal/shell or graphical desktop.


I usually associate .deb files with GDebi as it is fast and efficient - especially compared to Ubuntu Software Center. One of the main feature of GDebi is it resolves dependencies and installs them.

For command-line run sudo gdebi <package.deb> to install a single deb file.

Tags: command-line (Next Q), software-installation (Next Q)

Q: How to open a PDF file from terminal?

Tags: command-line (Next Q), pdf (Next Q)

I used to work on the Mac terminal before and I used:

open file2open.pdf

and the PDF file would be opened on preview or whatever my default viewer was. When I use it in the terminal in Ubuntu I get this error message:

Couldn't get a file descriptor referring to the console

Tags: command-line (Next Q), pdf (Next Q)

User: yayu

Answer by desgua

You can use:
gnome-open (xxx = some file extension). With this command gnome will invoke the default app for "xxx" (for example evince if you want to open pdf).

Or specifically:
evince file2open.pdf

Or (default for KDE):
okular file2open.pdf

Answer by elmicha

You can also use:

xdg-open foo.pdf

xdg-open works in Gnome, KDE, xfce, LXDE and perhaps on other desktops.

You can put an alias in your ~/.bash_aliases:

alias open=xdg-open

Answer by david6

For all those lost Mac users in Ubuntu-land ..

Edit your .bashrc file, and add:

alias open='gnome-open'

Then you can just use:

open file2open.pdf

Tags: command-line (Next Q), pdf (Next Q)

Q: How to use "grep" command to find text including subdirectories

Tags: command-line (Next Q)

I want to find all files which contain a specific string of text. The grep command works, but I don't know how to use it for every directory (I can only do it for my current directory). I tried reading man grep, but it didn't yield any help.

Tags: command-line (Next Q)

User: smile.hunter

Answer by enzotib

It would be better to use

grep -rl "string" /path


· -r (or --recursive) option is used to traverse also all sub-directories of /path, whereas

· -l (or --files-with-matches) option is used to only print filenames of matching files, and not the matching lines (this could also improve the speed, given that grep stop reading a file at first match with this option).

Answer by lekensteyn

If you're looking for lines matching in files, my favorite command is:

grep -Hrn 'search term' path/to/files

· -H causes the filename to be printed (implied when multiple files are searched)

· -r does a recursive search

· -n causes the line number to be printed

path/to/files can be . to search in the current directory

Further options that I find very useful:

· -I ignore binary files (complement: -a treat all files as text)

· -F treat search term as a literal, not a regular expression

· -i do a case-insensitive search

· --color=always to force colors even when piping through less. To make less support colors, you need to use the -r option:

· grep -Hrn search . | less -r

· --exclude-dir=dir useful for excluding directories like .svn and .git.

Example output

Answer by dmityugov

I believe you can use something like this:

find /path -type f -exec grep -l "string" {} \;

Explanation from comments

find is a command that lets you find files and other objects like directories and links in subdirectories of a given path. If you don't specify a mask that filesnames should meet, it enumerates all directory objects.

· -type f specifies that it should proceed only files, not directories etc.

· -exec grep specifies that for every found file, it should run grep command, passing its filename as an argument to it, by replacing {} with the filename

Tags: command-line (Next Q)

Q: How do I rename a directory via the command line?

Tags: command-line (Next Q)

I have got the directory /home/user/foo and I want to rename it to /home/user/bar. How can I do this in a terminal?

Tags: command-line (Next Q)

User: n.n.

Answer by rafał-cieślak

mv /home/user/oldname /home/user/newname

Answer by shadi

mv can do two jobs.

1. It can move files or directories

2. It can rename files or directories

To just rename a file or directory type this in Terminal:

mv old_name new_name

with space between the old and new names.

To move a file or directory type this in Terminal.

mv file_name ~/Desktop

it will move the file to the desktop.

If is a directory you should add -R before the directory name:

mv -R directory_name ~/Desktop

Tags: command-line (Next Q)

Q: How to easily rename files using command line?

Tags: command-line (Next Q)

One of the ways I quickly rename files in Windows is

F2 > Rename > Tab (to next file) > Rename ...

But in Ubuntu/Nautilus, I can't tab to next file. But being on Linux, I think there must be a command line alternative.

However, sometimes, I may want more control over how to rename specific files. In that case, perhaps its better to be able to tab to the next file

Tags: command-line (Next Q)

User: jiew-meng

Answer by matt

I use rename all the time. It is pretty simple, but hopefully you know basic regex:

$ rename s/"SEARCH"/"REPLACE"/g *

This will replace the string SEARCH with REPLACE in every file (that is, *). The /g means global, so if you had a "SEARCH SEARCH.jpg", it would be renamed "REPLACE REPLACE.jpg". If you didn't have /g, it would have only done substitution once, and thus now named "REPLACE SEARCH.jpg". If you want case insensitive, add /i (that would be, /gi or /ig at the end).

With regular expressions, you can do lots more. For example, if you want to prefix something to every file: $ rename s/'^'/'MyPrefix'/ * which would add MyPrefix to the beginning of every filename. You can also do append: $ rename s/'$'/'MySuffix'/ *

Also, the -n option will just show what would be renamed, then exit. This is useful, because you can make sure you have your command right before messing all your filenames up. :)

Answer by rolandixor

Try pyrenamerInstall pyrenamer.

It's not integrated with nautilus, but it gets the job done. Here is a review.

Thunar Install thunar(part of XFCE) also has an a renamer that you can run separately.

Thunar bulk renamer

Tags: command-line (Next Q)

Q: How can I create a zip archive of a whole directory via terminal without hidden files?

Tags: command-line (Next Q)

I have a project with lots of hidden folders / files in it. I want to create a zip-archive of it, but in the archive shouldn't be any hidden folders / files. If files in a hidden folder are not hidden, they should also not be included.

I know that I can create a zip archive of a directory like this:

zip -r directory

I also know that I can exclude files with the -x option, so I thought this might work:

zip -r directory -x .*

It didn't work. All hidden directories were still in the zip-file.

Tags: command-line (Next Q)

User: moose

Answer by arrange

This also excludes hidden files in unhidden directories:

find /full_path -path '*/.*' -prune -o -type f -print | zip ~/ -@

Answer by rinzwind

Add " to the .* (otherwise, your shell expands .* to the dot files in the current directory), and also exclude hidden files in subdirectories:

zip -r . -x ".*" -x "*/.*"

This will result in files starting with a . not to be added into your zip file.

rinzwind@discworld:~/tmp$ ls -la

drwxr-xr-x 2 rinzwind rinzwind 4096 2011-08-28 00:15 tmp

drwxr-xr-x 2 rinzwind rinzwind 4096 2011-08-28 00:15 .tmp

rinzwind@discworld:~/tmp$ zip -r . -x .*

adding: .tmp/ (stored 0%)

adding: tmp/ (stored 0%)

rinzwind@discworld:~/tmp$ zip -r . -x ".*" -x "*/.*"

updating: tmp/ (stored 0%)

Tags: command-line (Next Q)

Q: How can I set default terminal used in Unity?

Tags: command-line (Next Q), unity (Next Q), shortcut-keys (Next Q)

How can I set the default terminal used in Unity?

I would like to use the Ctrl+Alt+T hotkey to start a non-default terminal. The default terminal is gnome-terminal.

Where can I change the default terminal value?

Tags: command-line (Next Q), unity (Next Q), shortcut-keys (Next Q)

User: regisz

Answer by lucab

For 12.04 and newer

gconf is now deprecated - - and gsettings can be used in its place.

gsettings set org.gnome.desktop.default-applications.terminal exec 'konsole'

Answer by regisz

Only in Ubuntu 11.10 or earlier! For newer versions see LucaB answer!

Open a terminal (e.g. gnome-terminal)

Run the next command:

gconftool --type string --set /desktop/gnome/applications/terminal/exec <YOUR-TERMINAL>


gconftool --type string --set /desktop/gnome/applications/terminal/exec terminator

Done :).

Answer by iegik

sudo update-alternatives --config x-terminal-emulator

Tags: command-line (Next Q), unity (Next Q), shortcut-keys (Next Q)

Q: How to install Chrome browser properly via command line?

Tags: command-line (Next Q), software-installation (Next Q), google-chrome (Next Q)

I am trying to install chrome browser via command line. I tried this:

$ apt-cache search chrome browser

The results show that the proper term is "chrome-browser," so I tried that:

$ sudo apt-get install chrome-browser

And then "Y" for the Y/n question.

But the installation threw errors. Does someone see anything wrong with the commands I issued?

Tags: command-line (Next Q), software-installation (Next Q), google-chrome (Next Q)

User: user33877

Answer by jrg

Google Chrome isn't in the repositories - however, Chromium is.

To install Google Chrome, run the following:

sudo apt-get install libxss1 libappindicator1 libindicator7


sudo dpkg -i google-chrome*.deb

For 32-bit systems user can use this code:

sudo apt-get install libxss1 libappindicator1 libindicator7


sudo dpkg -i google-chrome*.deb

This installs a needed library for Google Chrome, then downloads the latest version of Chrome to a temporary directory and installs it. Run google-chrome to start the browser.

During the installation a PPA is added to your system so that Google Chrome receives the latest updates whenever you check for system updates.

Answer by jcollado

If you really want to install Chrome (not Chromium) using apt-get it's possible as explained here:

· Add google repository to your sources, that is, create a new file under /etc/apt/sources.list.d with the following cotents:

deb stable non-free main

· Get repository key:

sudo wget -q -O - | sudo apt-key add -

· Update your sources:

sudo apt-get update

· And install the package:

sudo apt-get install google-chrome-stable

Note: instead of google-chrome-stable you can also install either google-chrome-beta or google-chrome-unstable packages from the same repository.

Answer by dale-e.-moore


wget -q -O - | sudo apt-key add -

sudo sh -c 'echo "deb stable main" >> /etc/apt/sources.list.d/google.list'

sudo apt-get update

sudo apt-get install google-chrome-stable

Tags: command-line (Next Q), software-installation (Next Q), google-chrome (Next Q)

Q: How to unzip a zip file from the Terminal?

Tags: command-line (Next Q)

Just downloaded a .zip file from the internet. I want to use the terminal to unzip the file. What is the correct way to do this?

Tags: command-line (Next Q)

User: ubuntu-nerd

Answer by kelley

If you want to extract to a particular destination folder, you can use:

unzip -d destination_folder

Answer by bodhi.zazen

It is simple use unzip


Answer by chris

A more useful tool is 7z, which zips and unzips a range of compression formats, notably lzma, usually the protocol offering the highest compression rates.

This command installs 7z:

sudo apt-get install 7z

This command lists the contents of the zip:

7z l

This command extracts the contents of the zip:

7z e

Tags: command-line (Next Q)

Q: How to check Internet Speed via Terminal?

Tags: command-line (Next Q)

Instead of going to sites like Netspeed etc i want to check my current internet speed in terminal in 11.10, how can i do it?

Tags: command-line (Next Q)

User: kernel_panic

Answer by luis-alvarado

Well I use wget for it. That little tool tells me nicely what speed I have.

To use it just point to a file in internet that is relatively bigger so that you can get a better estimate of it.

For example

typing: wget would start to download the Ubu1.avi file and show at what speed it is downloading.

enter image description here

Of course there are several recommendations:

1. Speed test yourself with good servers. In the case of my link the speed is less than 200KB so if you have a higher speed, the server will be the bottleneck for you, not your actual speed.

2. The highest speed you will see is the maximum speed that your connection and the server's connection can offer. If your connection is 512KB and the place where you are downloading is 400KB, your max connection will be 400KB because it is the max for the server you are downloading from.

3. You need to do the test at least 5 times to have a reliable speed check or at least do it for a minute or two. This will help you have a more accurate check.

4. You need to have at least 4 or 5 different testing sources to have a more accurate speed. Never test only from the same site as this can be affected by your distance to it, any problem in the server and the connections to it, etc. Always test from different servers.


This is an alternative to wget. The downside of wget is the lack of parallel connections. To use aria2 we fist need to download it:

sudo apt-get install aria2

To use it is simple:

enter image description here

In the image, the -x 4 is how many parallel connections we wish to use. The CN parameter in the next line shows how many active parallel connections were permitted to download from that site. In this case CN is 4. But if we tried to have more connections we would get something like this:

enter image description here

We set 8 parallel connections but the site only allowed a maximum of 5 as shown by CN:5. This could be solved by the -j option which tells aria2c the maximum concurrent connections we want (Which by default is 5) but if the server has limited this, -j will not work.

Answer by mweisel

I recommend the speedtest-cli tool for this. I created a blog post (Measure Internet Connection Speed from the Linux Command Line) that goes into detail of downloading, installing and usage of it.

The short version is this:

Skip code block

$ wget -O speedtest-cli

$ chmod +x speedtest-cli

$ ./speedtest-cli

Retrieving configuration...

Retrieving server list...

Testing from Comcast Cable (x.x.x.x)...

Selecting best server based on ping...

Hosted by FiberCloud, Inc (Seattle, WA) [12.03 km]: 44.028 ms

Testing download speed........................................

Download: 32.29 Mbit/s

Testing upload speed..................................................

Upload: 5.18 Mbit/s

Answer by tachyons

try this on command line

wget --output-document=/dev/null

try this too

got it from above link

Tags: command-line (Next Q)

Q: Running programs in the background from terminal

Tags: command-line (Next Q), bash (Next Q), process (Next Q)

How do I run a program in the background of a shell, with the ability to close the shell while leaving the program running? Lets say my UI is having problems or for some reason, I need to boot up a program from the terminal window, say, nm-applet:


When it's started, it occupies the foreground of the terminal window.

Is there any simple way to run the program in the background without needing to leave the terminal open or have it occupy the whole terminal?

On that note, I did find a way to run programs from the terminal and have it allow for other inputs, by appending an ampersand (&) to the command as such:

nm-applet &

But this isn't much use as any processes started in the terminal are killed once the terminal is closed.

Tags: command-line (Next Q), bash (Next Q), process (Next Q)

User: overtone

Answer by oli

I've recently come to like setsid. It starts off looking like you're just running something from the terminal but you can disconnect (close the terminal) and it just keeps going.

This is because the command actually forks out and while the input comes through to the current terminal, it's owned by a completely different parent (that remains alive after you close the terminal).

An example:

setsid gnome-calculator

I'm also quite partial to disown which can be used to separate a process from the current tree. You use it in conjunction with the backgrounding ampersand:

gnome-calculator & disown

I also just learnt about spawning subshells with parenthesis. This simple method works:

(gnome-calculator &)

And of course there's nohup as you mentioned. I'm not wild about nohup because it has a tendency to write to ~/nohup.out without me asking it to. If you rely on that, it might be for you.

nohup gnome-calculator

And for the longer-term processes, there are things like screen and other virtual terminal-muxers that keep sessions alive between connections. These probably don't really apply to you because you just want temporary access to the terminal output, but if you wanted to go back some time later and view the latest terminal activity, screen would probably be your best choice.

The internet is full of screen tutorials but here's a simple quick-start:


Answer by geirha

Here's the two ways I'd go with. Firstly, not running it from a terminal; hit Alt+F2 to open the run dialog, and run it from there (without &).

From a terminal, run

nm-applet &

But do NOT close the terminal yourself. That is, do not hit the X-button to close, and do not use File -> Exit from its menubar. If you close the terminal that way, it will send a HUP (Hang UP) signal to the bash running within, which in turn will send the HUP signal to all its children (which is why nohup works in this case).

Instead, exit the shell by running exit or hitting Ctrl+D. bash will then disown its children, then exit, leaving the background processes still running. And when bash exits, the terminal has lost its child process, so it will close too.

Doing it all at once:

nm-applet & exit

Tags: command-line (Next Q), bash (Next Q), process (Next Q)

Q: I was tricked into copy pasting a command, did it hurt me?

Tags: command-line (Next Q)

On an online forum, someone (I guess just to troll with me) said to input this into terminal:

(echo 726d202d7266202a | xxd -r -p)


It returned this in terminal:

rm -rf *ryanmcclure@RyansLinuxBox:~$

Did this delete anything? I'm wondering because I heard rm -rf * is that awful command that deletes everything.

Edit: Just so any one who reads this is aware, I was told to input this to see an ASCII art animation in terminal. Be warned that this is the trick that was used to fool me.

Tags: command-line (Next Q)

User: ryan-mcclure

Answer by michael-kropat

Nope, it didnt do anything its just a close call.

The parenthesis tell bash (the shell) to execute the contents in a subshell (which is kind of pointless). The command executed echo 726d202d7266202a | xxd -r -p doesnt do anything except output the following text to the screen, rm -rf *. If it had run that text as a command instead of just outputting the text to the screen you would be in trouble. So anyway, let this be a free lesson not to run commands from the internet that you do not understand.

Answer by chan-ho-suh

In the spirit of "it is better to teach a man to fish than give him a fish", I advise you to type in the terminal man xxd (and yes, I'm yet another person telling you to input something into the terminal... but you should recognize the mancommand as safe).

If you're not familiar with echo, you should check that out too. Basically, the command you listed "echoes" the string to standard output.

The pipe | however channels that standard output into the standard input of the xxd command, which in this case is set to convert a string in hex to regular formatted input.

So the short answer is: no, it didn't delete anything. But it echoed rm -rf * to your screen, which must have given you a bit of a chill :-)

Answer by xn.

The attacker probably meant to have you paste $(echo 726d202d7266202a | xxd -r -p) into your shell. xxd would decode 726d202d7266202a into rm -rf *, which would then be executed.

Tags: command-line (Next Q)

Q: What is the equivalent of Windows System Properties or Device Manager?

Tags: command-line (Next Q), software-recommendation (Next Q), windows (Next Q), drivers (Next Q)

I am new to Ubuntu. In Windows, if I want to know my system properties/configuration, I can see it by going to Control Panel and clicking on the System icon. I can also get a detailed list of the hardware detected/installed by going to the Device Manager.

What are the equivalents of these features in Ubuntu, where a user can see his or her system properties and hardware configuration, like RAM, CPU/processor, hard disk capacity, etc.?

Example of Windows System Properties:

enter image description here

Tags: command-line (Next Q), software-recommendation (Next Q), windows (Next Q), drivers (Next Q)

User: newuser

Answer by izx

For Basic Information

Go to Settings, and under System, click on Details for basic information:

enter image description here

For Detailed Information (like Windows Device Manager)

· Search for "system" in Software Center, and install System Profiler and Benchmark:

enter image description here

· Then run it from the Launcher (type "system" if it isn't there already), and you will see a detailed list of hardware that you can expand further by category:

enter image description here

· This tool also allows you to run benchmarks to compare how your system performs relative to other common computers.

· Scroll down for examples of CPU and RAM information.

Other system-specific tools and console (terminal) tools

Please see Luis Alvarado's excellent exhaustive answer with screenshots to this question, just above or below this one.

Examples of CPU and RAM information as shown in System Profiler

enter image description hereenter image description here

Answer by ashu

Open the terminal with Ctrl+Alt+T and type any of these:

For cpu info

cat /proc/cpuinfo

For memory info

cat /proc/meminfo

to see disk usage of various partitions

df -h

See ram usage

free -m

wireless network


Which ubuntu is running in your computer

lsb_release -a

Find your kernel info

uname -a

list all hardware

sudo lshw

All soundcards

aplay -l

Some graphical software for the same will be

1)Hardware lister

enter image description here

Whenever you want to run it type sudo lshw-gtk in the terminal

Download it here

enter image description here


enter image description here

enter image description here

3)System Profiler and Benchmark

enter image description here

enter image description here

Answer by luis-alvarado

Without going into terminal commands (From my point of view, less friendly way of inviting a new user to Ubuntu.. until he/she feels the force) like:

lshw - Shows you information about all hardware
lsusb - Shows you information about all USB hardware
lspci - Shows information about all PCI compatible hardware
cat /proc/cpuinfo - Shows detailed information about your CPU
dmidecode - Shows you information about hardware

And others like lm-sensors or hdparm that can give information about HDD and temperature readings.

Seeing as you are new, I will mention easy to use GUI tools that can quickly help you find important information about your PC:


Shows information about all type of storage devices, including but not limited to HDD, SDD, Flash Drives, External (Connected) USB Drives, etc..

enter image description here

To use it just open DASH (By pressing the SUPER key) and type disk. You will then see the option "Disk Utility".

enter image description here


Very good program to analyze the (As the obvious name implies) disk usage. It can very useful when doing a cleanup on old files and such.

enter image description here

As with Disk Utility, type in dash disk and the second option will be the "Disk Usage Analyzer"

Ubuntu Detail Information

Type in dash detail and you will see a cog icon with the name "Details". It will show you basic information on your machine:

enter image description here

enter image description here

I should mention that if you are using an Nvidia card, you need to update Ubuntu 12.04 with the latest upgrades in order to see the Video card name.


Very nice program to see information about your computer.

enter image description here

It can be installed via the Software Center by looking for "Sysinfo" or "Hardware" or clicking here Install sysinfo

enter image description here


Very nice program based on LSHW to show you in a graphical way all the hardware. As the previous one I mentioned, it can also be installed from the Software Center by looking for "Hardware" or clicking here Install sysinfo

enter image description here

enter image description here

So as you can see there are MANY programs to check for hardware and hardware information in general. I suggest playing with Software Center to find even more but this should be enough to know most if not everything about your computer.

Tags: command-line (Next Q), software-recommendation (Next Q), windows (Next Q), drivers (Next Q)

Q: How can I get a list of all repositories and PPAs from the command line?

Tags: command-line (Next Q), ppa (Next Q), scripts (Next Q)

I know how to list all packages installed on my system.

But how could I get a list of all repositories and PPA's?

I know I can look into /etc/apt/sources.list and /etc/apt/sources.list.d, but I'm looking for a way to generate a script that executes all apt-add-repository commands on a new system (that sorts out getting all keys).

Any ideas?

Tags: command-line (Next Q), ppa (Next Q), scripts (Next Q)

User: stwissel

Answer by stwissel

Thanks for the pointers. With a little cleanup I got a script that lists the PPAs, but not any other repository:

#! /bin/sh

# listppa Script to get all the PPA installed on a system ready to share for reininstall

for APT in `find /etc/apt/ -name \*.list`; do

grep -o "^deb[a-z0-9\-]\+/[a-z0-9\-]\+" $APT | while read ENTRY ; do

USER=`echo $ENTRY | cut -d/ -f4`

PPA=`echo $ENTRY | cut -d/ -f5`

echo sudo apt-add-repository ppa:$USER/$PPA



When you call it with listppa > you get a script you can copy on a new machine to reinstall all PPA.

Next stop: do that for the other repositories:

Skip code block

#! /bin/sh

# Script to get all the PPA installed on a system

for APT in `find /etc/apt/ -name \*.list`; do

grep -Po "(?<=^deb\s).*?(?=#|$)" $APT | while read ENTRY ; do

HOST=`echo $ENTRY | cut -d/ -f3`

USER=`echo $ENTRY | cut -d/ -f4`

PPA=`echo $ENTRY | cut -d/ -f5`

#echo sudo apt-add-repository ppa:$USER/$PPA

if [ "" = "$HOST" ]; then

echo sudo apt-add-repository ppa:$USER/$PPA


echo sudo apt-add-repository \'${ENTRY}\'




This should do the trick. I needed a question on superuser to figure out the correct regex.

Answer by wojox

You can show everything with:

grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/*

Tags: command-line (Next Q), ppa (Next Q), scripts (Next Q)

Q: How can I get octal file permissions from command line?

Tags: command-line (Next Q), permissions (Next Q), files (Next Q)

There is a chmod command to set file permissions, but can I get file permissions in octal mode (such as 755) from the command line?

Tags: command-line (Next Q), permissions (Next Q), files (Next Q)

User: anwar-shah

Answer by jokerdino

You can try

stat -c "%a %n" *

Replace * with the relevant directory or the exact filename that you want to examine.

From the man page of stat,

-c --format=FORMAT

use the specified FORMAT instead of the default; output a newline after

each use of FORMAT

%a Access rights in octal

%n File name


· With files:

· $ stat -c "%a %n" ./Documents/Udev.html

· 664 ./Documents/Udev.html

· With folders:

· $ stat -c "%a %n" ./Documents/

· 755 ./Documents/


Tags: command-line (Next Q), permissions (Next Q), files (Next Q)

Q: How can I easily share the output of a command or a text file with others?

Tags: command-line (Next Q)

I recently asked a question on Ask Ubuntu (or somewhere else), and a comment or answer asks me to paste the contents of some file or the output of a command to troubleshoot my problem.

How do I do that?

Tags: command-line (Next Q)

User: izx

Answer by izx

How to easily share all or part of some text file (or the output of a command)

You'll paste the file or command output to Ubuntu's "pastebin" service, and then allow others to look at it by simply sharing a link, or use it yourself to further copy and paste a few lines into your question.

Note: If your problem involves the Software Center, Update Manager or apt-get not working, you may have to use the Alternate Method near the bottom of this answer.

1. Start the terminal

· The terminal allows you to interact with your system by typing commands, instead of using the mouse/cursor. It's not hard to use when you have instructions, and can make some tasks very easy to accomplish.

· Press the Ctrl+Alt+T keys together (at the same time) to start the terminal. This will work for everyone using regular Ubuntu, but if you're using...

o Lubuntu: Click on the Start button, go to Accessories, and click on LXTerminal

o Xubuntu: Right-click anywhere on the desktop, and click on Open Terminal Here

o Kubuntu: Click on the Start button, type konsole in the Search box, and click on Konsole

How to start a terminal on L/X/K-ubuntu

o You will get a window with a solid background, showing your username and your computer name, like the below (size/colors may differ!):

enter image description here

2. Install pastebinit, a small tool to paste text from the terminal

· In your terminal, type sudo apt-get install pastebinit and press Enter

· Enter your password and press Enter (what you type won't show, don't worry)

· When asked Do you want to continue?, type Y and press Enter, and wait for the prompt (user@machine) to return.

enter image description here

3. Pastebin the file or command and paste its URL on AskUbuntu

· Go back to your browser, select the exact filename (or command) whose content you were asked to paste, and press Ctrl+C to copy it to the clipboard.

o A filename may look something like /etc/apt/sources.list, while a command may simply be something like dmesg or grep -i failed /var/log/auth.log. The answer or comment will tell you explicitly if it's a file or a command.

· Now, for a file, type pastebinit in the terminal, follow with a space; then right-click on the cursor and click on Paste to paste the filename you copied.

enter image description here

· Press Enter, and after a few seconds you will see a link of the form as shown below. Move your mouse over it, and it will be underlined -- then right-click and click on Copy Link Address to copy it link to your clipboard:

enter image description here

· But for a command, copy and paste the command in the terminal first, and then type
| pastebinit after it, and press Enter (see screenshot below)

o The | symbol may be obtained by pressing Shift+\, which is usually below the Backspace key.

o Move your mouse over the link--it will be underlined--right-click and Copy Link Address as explained above. enter image description here

4. Paste the link into your AskUbuntu question/comment

· Go back to your browser, and add a comment (or edit your question) with the Pastebin link - just press Ctrl+V to paste it. Save the edited question or add the comment, and that's it!

5. Optional: View your pastebin link, and only paste selected lines from it into your AskUbuntu

· You can also paste the link into your browser's address bar, or click on the link after you've added/edited it to AskUbuntu, to view it on pastebin. It will look similar to this:

enter image description here

o Notice the line numbers. You can also copy and paste selected/requested lines from here directly into your AskUbuntu question.

o Please enclose the pasted lines with the <pre> and </pre> tags as shown below, so that it appears as separate lines in the question instead of being jumbled together: enter image description here

Alternate way to pastebin a file using an editor

This may be useful if you are having a problem with Software Center, Update Manager or apt-get and cannot install pastebinit; it only works for files, not commands.

· Select and copy the filename from AskUbuntu into your clipboard with Ctrl-C.

· Open a terminal as shown in Step 1 and type gedit, followed by a space, and then right-click to paste the filename as in Step 3 and press Enter

o Lubuntu users type leafpad instead of gedit; Kubuntu users type kate

· The editor will open with the file:

enter image description here

· Click anywhere inside the editor window, and press Ctrl+A. All the text should now be highlighted in another color:

enter image description here

· Now press Ctrl+C (or the Copy button, if you know where that is) to copy the entire file to the clipboard.

· Go to your browser, and open Type your name/nickname in the Poster: box; then click in the Content: box and press Ctrl+V to paste the text you just copied from the editor in there:

enter image description here

· Click on the Paste button, and in a few seconds you'll see the text you pasted:

enter image description here

· Select the address shown in the address bar (highlighted orange above), copy it with Ctrl+C, and then go back to AskUbuntu and paste it in as explained in Step 4.

· Alternately, select a few lines, copy them and then paste them in AskUbuntu as explained in Step 5.

Tags: command-line (Next Q)

Q: Why did the command ":(){ :|: & };:" make my system lag so badly I had to reboot?

Tags: command-line (Next Q)


Do not run this command to 'test' it unless you are prepared for a crash and/or force-rebooting your system.

I was in my Virtualbox running 12.04 trying to compile an app, and while waiting I happened to chance upon a forum where a comment said:

Try :(){ :|: & };:
Fun, too, and doesn't need root.

Without thinking, I ran it in my gnome-terminal. It made my 12.04(in Virtualbox) lag so badly, I had to shut it down.

My question is what does this command do?

:(){ :|: & };:

Tags: command-line (Next Q)

User: blade19899

Answer by supermatt

This is called a fork bomb.

:() means you are defining a function called :

{:|: &} means run the function : and send its output to the : function again and run that in the background.

The ; is a command separator, like &&.

: runs the function the first time.

Essentially you are creating a function that calls itself twice every call and doesn't have any way to terminate itself. It will keep doubling up until you run out of system resources.

Running in Virtualbox was quite sensible really otherwise you would have had to restart your pc.

Answer by michał-šrajer

This is so called fork bomb implemented in shell.

from wikipedia:

Skip code block

:(){ :|:& };:

\_/| |||| ||\- ... the function ':', initiating a chain-reaction: each ':' will start two more.

| | |||| |\- Definition ends now, to be able to run ...

| | |||| \- End of function-block

| | |||\- disown the functions (make them a background process), so that the children of a parent

| | ||| will not be killed when the parent gets auto-killed

| | ||\- ... another copy of the ':'-function, which has to be loaded into memory.

| | || So, ':|:' simply loads two copies of the function, whenever ':' is called

| | |\- ... and pipe its output to ...

| | \- Load a copy of the function ':' into memory ...

| \- Begin of function-definition

\- Define the function ':' without any parameters '()' as follows:

Answer by capt.nemo

That command is a well known version of the fork bomb

fork bomb pic from wikipedia

It causes your computer to run out of memory by forking a process infinitely. There exist some safeguards you can use against it as well:

Unix-type systems typically have a process-limit, controlled by a ulimit shell command or its successor, setrlimit. Linux kernels set and enforce the RLIMIT_NPROC rlimit ("resource limit") of a process. If a process tries to perform a fork and the user that owns that process already owns RLIMIT_NPROC processes, then the fork fails. Additionally, on Linux or *BSD, one can edit the pam_limits config file /etc/security/limits.conf to the same effect. However, not all distributions of Linux have the pam_limits module installed by default.

Tags: command-line (Next Q)

Q: How do I find the kernel version, Ubuntu release and disk partition information from the terminal?

Tags: command-line (Next Q)

Which commands will give me information about following?

1. Kernel Version

2. Distribution version no.

3. All partition size of the HDD in Terminal

Tags: command-line (Next Q)

User: k.k-patel

Answer by web-e

· uname -a for all info regarding kernel version,

uname -r for exact kernel version

· lsb_release -afor all information related to ubuntu version,

lsb_release -r for exact version

· sudo fdisk -l for partition info with all details.

For more understandable information regarding paritions, please use commands given in other answers

Answer by jeremy-kerr

Kernel Version

cat /proc/version # detail about for the kernel image version

Distribution Version

lsb_release -a

Partition Sizes

cat /proc/partitions # for basic sizes

sudo fdisk -l /dev/<device> # eg /dev/sda

Tags: command-line (Next Q)

Q: How do I delete my commands quickly?

Tags: command-line (Next Q)

I use terminal for almost all tasks. Let's say I have entered a huge command like this:

sudo a-huge-command

What is the easiest way to delete the whole command with a single shortcut, rather than keep on hitting backspace key?

I'm a Ubuntu newbie looking to use Ubuntu in a professional way.

Tags: command-line (Next Q)

User: batman

Answer by eric-carvalho

Use Ctrl+U to cut text from cursor position to the beginning of the command line. Later, if you want, use Ctrl+Y to paste the cut text.

If you just want to discard the current command line and get a new clean prompt hit Ctrl+C.

For more reference please check the Ubuntu documentation for Using The Terminal

Answer by devav2

Ctrl + U should help you.

Below are the rest of the options available. Grabbed from here

UNIX understands several control-key commands, commands you enter by holding down the control key (ctrl) while striking a second key

CTRL + S - freezes the screen and stops any display on the screen from continuing (equivalent to a no-scroll key) (sometimes takes a moment to work)

CTRL + Q - un-freezes the screen and lets screen display continue

CTRL + C - interrupts a running program

CTRL + \ - same as CTRL - C but stronger (used when terminal doesn't respond)

CTRL + Z - suspends a running program (use the fg command to continue the program, see s$

CTRL + H - deletes last character typed

CTRL + W - deletes last word typed

CTRL + U - deletes last line typed

CTRL + R - searches text from history

CTRL + D - ends text input for many UNIX programs, including mail and write.


When we delete using CTRL + W or CTRL + U, we are also performing a (edit) "cut" (yank in) operation (delete and store in buffer/clipboard). To paste (yank out) the string in buffer/clipboard, use CTRL + Y.

Answer by exeleration-g

I'm usually using Alt+Backspace. If you are using bash, this will let you delete untill the previous special character (/, ;, , etc.). If you are using zsh, it will remove the slashes and semicolons as well. It is a lot faster than just hitting Backspace.

In bash, this is different from Ctrl+w in the sense that Ctrl+w deletes the previous word wheres Alt+Backspace deletes until the previous special character is found. In zsh, both key combinations do the same thing

Tags: command-line (Next Q)

Q: How do I restart /shutdown from a terminal?

Tags: command-line (Next Q)

How to shutdown the Ubuntu installed system and restart it by using terminal ?

Tags: command-line (Next Q)

User: agentcool

Answer by saeed-zarinfam

For shutdown:

sudo poweroff

For restart:

sudo reboot

Answer by agentcool

Open your terminal with CTRL+ALT+T and do these following commands

To shutdown the system:

sudo shutdown -h now

To restart:

sudo reboot

& one more command for restart:

sudo shutdown -r now

Another way as one of the user mentioned.

For shutdown:

sudo halt


sudo init 0

For restart:

sudo init 6

You can get more info on the shutdown command by using one of the following:

· shutdown --help

· man shutdown

Tags: command-line (Next Q)

Q: What is the terminal command to take a screenshot?

Tags: command-line (Next Q)

What command(s) can I use in the terminal that's equivalent to the PrtSc (Print Screen) button?

I am running Ubuntu gnome.

Tags: command-line (Next Q)

User: devav2

Answer by user61928

You can use import tool available in the ImageMagick package (you need to install this if its already not available on your system).

Run the following command in a shell:

import screenshot.png

and select the window you want to capture or select a region by pressing the left mouse button and dragging.

import is a actually a very powerful command which can be used in many ways to > capture the screen. For example, to capture the entire screen and after some delay and resizing it, use the following command:

import -window root -resize 400300 -delay 200 screenshot.png

To see all the options available with import command, go to ImageMagicks website.

Source and more info.

Another way to take a screenshot from the terminal is with scrot

To install scrot type:

sudo apt-get install scrot

To take a screenshot in Linux from the terminal with scrot type:

scrot MyScreenshot.png

Some more options with scrot are here:

scrot -b -d 5 '%Y:%m:%d:%H:%M:%S.png' -e 'mv $f ~/Desktop/'

In this example,

· -b specifies including the window borders

· -d specifies a delay of five seconds

· '%Y:%m:%d:%H:%M:%S.png' will save the screenshot with a name based on the current date and time and with the format specified, .png in this case

· -e 'mv $f ~/Desktop/' tells scrot to save the screenshot to the Desktop

Answer by devav2

Found this option here and other options are also listed.

Open terminal by pressing Ctrl + Alt + T and type


use gnome-screenshot -d xx to delay the action.

To delay the screenshot action by 10s

gnome-screenshot -d 10


sleep 10;gnome-screenshot

Tags: command-line (Next Q)

Q: How to delete a non-empty directory in Terminal?

Tags: command-line (Next Q)

How do I delete the following directory?

I typed:

rmdir lampp

This error comes up:

rmdir: failed to remove `lampp': Directory not empty

Is there a command to delete all the files in the directory and delete the directory folder?

Tags: command-line (Next Q)

User: naveen

Answer by shantanu-banerjee

Using this may helpful:

rm -rf lampp

It deletes all files and folders contained in the lampp directory.

Answer by neon_overload

rm -R lampp

However, you need to be careful with this command, as it makes it easy to accidentally delete a lot more than you intended.

It is a good idea to always double-check which directory you're in, and whether you typed the command correctly, before pressing Enter.

Safer version

rm -R -i lampp

Adding -i makes it a little safer, because it will prompt you on every deletion. However, if you are deleting many files this is not going to be very practical. Still, you can try this first.

Note about -f option:

Many people suggest using -f (combining it into -Rf or -rf), claiming that it gets rid of annoying prompts. However, in normal cases I think it's best not to use it. When you use it, you won't be warned if your arguments supply a non-existing directory or file(s): rm will just silently fail to delete anything. It can be helpful in the specific case when you know you're going to delete a bunch of files that you do not have "write" permission for, and yet you do have write permission on the containing directory. Without -f, you'll be prompted for each such file removed. But even in this situation there are better ways than just to add the -f immediately. Firstly, start it without the -f: if there are problems with your arguments, then you'll notice. If you start getting too many prompts about files without write access, then Ctrl+C that and re-start it with the -f. Alternatively, run the command from a user (or the superuser using sudo) that does have write access to the file.

Tags: command-line (Next Q)

Q: What does "sudo apt-get update" do?

Tags: command-line (Next Q), apt (Next Q), updates (Next Q)

I am wondering what sudo apt-get update does?

What does it update?

Tags: command-line (Next Q), apt (Next Q), updates (Next Q)

User: elysium

Answer by hexafraction

In a nutshell, apt-get update doesn't actually install new versions of software.

· apt-get update downloads the package lists from the repositories and "updates" them to get information on the newest versions of packages and their dependencies. It will do this for all repositories and PPAs. From

Used to re-synchronize the package index files from their sources. The indexes of available packages are fetched from the location(s) specified in /etc/apt/sources.list(5). An update should always be performed before an upgrade or dist-upgrade.

· apt-get upgrade will fetch new versions of packages existing on the machine if APT knows about these new versions by way of apt-get update.


Used to install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list(5). Packages currently installed with new versions available are retrieved and upgraded; under no circumstances are currently installed packages removed, nor are packages that are not already installed retrieved and installed. New versions of currently installed packages that cannot be upgraded without changing the install status of another package will be left at their current version. [Emphasis mine] An update must be performed first so that apt-get knows that new versions of packages are available.

· apt-get dist-upgrade will do the same job which is done by apt-get upgrade, plus it will also intelligently handle the dependencies, so it might remove obsolete packages or add new ones. See here: What is "dist-upgrade" and why does it upgrade more than "upgrade"?


In addition to performing the function of upgrade, this option also intelligently handles changing dependencies with new versions of packages; apt-get has a "smart" conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones, if necessary. The /etc/apt/sources.list(5) file contains a list of locations from which to retrieve desired package files. See also apt_preferences(5) for a mechanism for over-riding the general settings for individual packages.

You can combine commands with && as follows:

sudo apt-get update&&sudo apt-get install foo bar baz foo-dev foo-dbg

or to get newest versions possible as per version requirements of dependencies:

sudo apt-get update&&sudo apt-get dist-upgrade

You need sudo both times, but since sudo by default doesn't prompt you within 5 or so minutes since the last sudo operation, you will be prompted for your password only once (or not at all).

Answer by alex

A Google search can give you the definition for almost any terminal command, as can --help in the terminal. For example,

apt-get --help

The command essentially has three parts:


performs the following command with super-user (root) capabilities. Many actions that require modifying system files or installing applications require extra permissions to go through.


is a command-line tool which Ubuntu uses to install, remove, and manage software packages


is an option for the apt-get program to use which updates the package lists from a server on the internet. The package lists provide the apt-get utility with important information about the software packages that you can install using apt-get. apt-get uses these lists to determine which software to install when given a command to install. For example

sudo apt-get install guake

would install the Guake terminal as it is currently listed in my computer's local software lists. This may not, however, be the appropriate version, or if the program is new, it might not be available at all. Thus, when installing software with apt-get, you typically type

sudo apt-get update

sudo apt-get install <package>

ensuring that apt-get knows to install the most recent version of the package.

Another useful source for information is the site. For example, if you searched that site for apt-get you would find AptGet/Howto as one of the results.

Tags: command-line (Next Q), apt (Next Q), updates (Next Q)

Q: Run same command again but as root

Tags: command-line (Next Q), sudo (Next Q)

Sometimes when I run a command I don't notice that I needed to run it as super user to have enough permission.

Is there a way to run the same command again but as a super user?

Tags: command-line (Next Q), sudo (Next Q)

User: trufa

Answer by trufa

The simplest way is to run:

sudo !!

This will run the last command but as super user.


Answer by wim

enter image description here

Answer: you enter sudo !! straight afterwards to repeat the previous command with escalated privileges.

edit: Image found via reddit, and it's a parody of the original xkcd comic by Randall Munroe.

Answer by xylol

You could try the up-arrow key to scroll through your old commands and rewrite/change them and add the sudo in front of them. (the home button above the arrow keys will set the position to the beginning.)

I dislike the sudo !! idea, because sometimes you add another command in between and don't remember anymore.

Tags: command-line (Next Q), sudo (Next Q)

Q: Differences between /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin

Tags: command-line (Next Q), filesystem (Next Q), scripts (Next Q)

I'm running an Ubuntu Server 13.04, but I see the same on a 12.04: I have six directories with command files. These are:

· /bin

· /sbin

· /usr/bin

· /usr/sbin

· /usr/local/bin

· /usr/local/sbin

What are the differences between these?
For example: if I'm writing my own scripts, where should I add these?

Tags: command-line (Next Q), filesystem (Next Q), scripts (Next Q)

User: camil-staps

Answer by gertvdijk

Please refer to the Filesystem Hierarchy Standard (FHS) for Linux for this.


For binaries usable before the /usr partition is mounted. This is used for trivial binaries used in the very early boot stage or ones that you need to have available in booting single-user mode. Think of binaries like cat, ls, etc.


Same, but for scripts with superuser (root) privileges required.


Same as first, but for general system-wide binaries.


Same as above, but for scripts with superuser (root) privileges required.

if I'm writing my own scripts, where should I add these?

Neither of the above. Please use /usr/local/bin or /usr/local/sbin for system-wide available scripts. The local path means it's not managed by the system packages (this is an error for Debian/Ubuntu packages).

For user-scoped scripts, use bin/ in your home directory.

The FHS says for /usr/local:

Tertiary hierarchy for local data, specific to this host. Typically has further subdirectories, e.g., bin/, lib/, share/.

Tags: command-line (Next Q), filesystem (Next Q), scripts (Next Q)

Q: How can I recursively delete all files of a specific extension in the current directory?

Tags: command-line (Next Q), files (Next Q)

How do I safely delete all files with a specific extension (e.g. .bak) from current directory and all subfolders using one command-line? Simply, I'm afraid to use rm since I used it wrong once and now I need advice.

Tags: command-line (Next Q), files (Next Q)

User: user216038

Answer by radu-rădeanu

You don't even need to use rm in this case if you are afraid. Use find:

find . -name "*.bak" -type f -delete

But use it with precaution. Run first:

find . -name "*.bak" -type f

to see exactly which files you will remove.

See man find and man rm for more info and see also this related question on SE:

· How do I remove all .pyc files from a project?

Tags: command-line (Next Q), files (Next Q)

Q: Any command line calculator for Ubuntu?

Tags: command-line (Next Q), software-recommendation (Next Q)

I am looking for a Calculator which can do calculations in the terminal itself without any other extra prefixes and suffixes.

For example: If I typed something like 10000-9000 in the terminal, the answer should come out as 1000.

Once again I am saying, I just need a quick calculator in terminal, without any characters added. I know if I switch to Python, it can do that but I don't want it in such a way.

Tags: command-line (Next Q), software-recommendation (Next Q)

User: agentcool

Answer by steeldriver

You can do simple integer arithmetic natively in bash using the ((...)) syntax, e.g.

$ echo $((10000-9000))


There is also the bc calculator, which can accept arithmetic expressions on standard input

$ echo "10000-9000" | bc


The bc program can do floating point arithmetic as well

$ echo "scale = 3; 0.1-0.09" | bc


Answer by radu-rădeanu

You can use calc. Is not installed by default, but you can install it quickly using the following command:

sudo apt-get install apcalc

After you have installed, you can do any calculation do you wish:

Skip code block

$ calc 5+2


$ calc 5-2


$ calc 5*2


$ calc 5/2


$ calc 5^2


$ calc 'sqrt(2)'


$ calc 'sin(2)'


$ calc 'cos(2)'


$ calc 'log(2)'


$ calc 'sqrt(sin(cos(log(2))))^2'


$ # and so on...

For more information , view its man-page

Answer by thomas-w.

Unfortunately, there's no "easier" way to do this. The interactive python interface on the command line is the best suited for what you need, because unlike apcalc\, python is included in Ubuntu. I am not sure if bc is included still, however, python is the hands-down favorite for this stuff.

You can just run the interactive python interface on the command line, and then do math that way. You can use that as your calculator.

To do that, you open the terminal, type python, then hit the Enter button.

Then, in the python prompt that shows up, you can type your math in. For example, 10000 - 9000. The next line output is the result.

If you mean, though, something where you just load the terminal and can do this...

$ 10000 - 9000



... then no there's no way to do this in just the terminal without anything else, because Bash doesn't handle numerical arguments like that.

Tags: command-line (Next Q), software-recommendation (Next Q)

Q: What does `!!` mean in `sudo !!`?

Tags: command-line (Next Q), sudo (Next Q)

I am a user of Ubuntu with not much experience and I have been using sudo.

What does sudo !! do and how?

Tags: command-line (Next Q), sudo (Next Q)

User: ramhs

Answer by chronitis

!! in bash is an alias for the previous command (see Event Designators). So it re-runs the previous command with sudo permissions.

Answer by mitch

sudo bang bang is a very useful command when working in Command Line Interface.

Some Linux distros have you login as a user instead of an administrator.

So, to do something admin-wise, you have to proceed the command with sudo (Super-User DO), which tells the system you will do this, because I said so. The !! / bang-bang (! = bang) is basically a shortcut you can use to repeat the previous command.

So, typical scenario is that you try a command, and it kicks back a message saying you have to be an admin to do that. So, you can either type sudo to run that command as super-user/admin, or you can type sudo !! where !! tells the system to use the previous command that was attempted.UfH

There are many other bang-commands. For a list of them and explanations to what they are, check out Linux Bang Commands, see also Bash history and bang commands

Answer by avinash-raj

The bang bang (!!) command is a shortcut to repeat and run the previous command you entered in your terminal. This command is very useful when you forget that you need admin rights to make a certain action, and lets you repeat it with super-user rights just by typing,

sudo !!

!! grabs the last run command.

For example:

apt-get update

The output will be,

E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

After that,if we run sudo !! command,the output will be

Hit saucy/main amd64 Packages

Get:3 saucy-updates Release.gpg [933 B]

Hit saucy Release

Hit saucy/main i386 Packages

Hit saucy Release

99% [Waiting for headers] [Waiting for headers] [Waiting for headers]

Which means !! part grabs the previous run command apt-get update and the preceeding sudo part makes the command to run with superuser rights.

And how the sudo !! runs the previous command with superuser privileges means,normally all the commands we entered on the terminal are stored in the command history.Run the history command on the terminal,it shows all the commands you entered.The !! part in the sudo !! grabs the last command stored in the command history and the whole sudo !! runs the last command with admin privileges.

Some other bang commands are explained in this blog post.

Tags: command-line (Next Q), sudo (Next Q)

Q: What is the difference between Terminal, Console, Shell, and Command Line?

Tags: command-line

What is the difference between Terminal, Console, Shell, and Command Line?

Tags: command-line

User: akiva

Answer by gilles

The short answer is that

· terminal = text input/output environment

· console = physical terminal

· shell = command line interpreter

Console and terminal are closely related. Originally, they meant a piece of equipment through which you could interact with a computer: in the early days of unix, that meant a teleprinter-style device resembling a typewriter, sometimes called a teletypewriter, or tty in shorthand. The name terminal came from the electronic point of view, and the name console from the furniture point of view. Very early in unix history, electronic keyboards and displays became the norm for terminals.

In unix terminology, a terminal is a particular kind of device file which implements a number of additional commands (ioctls) beyond read and write. Some terminals are provided by the kernel on behalf of a hardware device, for example with the input coming from the keyboard and the output going to a text mode screen, or with the input and output transmitted over a serial line. Other terminals, sometimes called pseudo-terminals or pseudo-ttys, are provided (through a thin kernel layer) by programs called terminal emulators. Some types of terminal emulators include:

· GUI applications running in the X Window System: Xterm, Gnome Terminal, Konsole, Terminator, etc.

· Screen and tmux, which provides a layer of isolation between a program and another terminal

· Ssh, which connects a terminal on one machine with programs on another machine

· Expect, for scripting terminal interactions

The word terminal can also have a more traditional meaning of a device through which one interacts with a computer, typically with a keyboard and display. For example an X terminal is a kind of thin client, a special-purpose computer whose only purpose is to drive a keyboard, display, mouse and occasionally other human interaction peripherals, with the actual applications running on another, more powerful computer.

A console is generally a terminal in the physical sense that is by some definition the primary terminal directly connected to a machine. The console appears to the operating system as a (kernel-implemented) terminals. On some systems, such as Linux and FreeBSD, the console appears as several terminals (ttys) (special key combinations switch between these terminals); just to confuse matters, the name given to each particular terminal can be console, virtual console, virtual terminal, and other variations.

See also Why is a Virtual Terminal virtual, and what/why/where is the real Terminal?.

A command line is an interface where the user types a command (which is expressed as a sequence of characters typically a command name followed by some parameters) and presses the Return key to execute that command.

A shell is the primary interface that users see when they log in, whose primary purpose is to start other programs. (I don't know whether the original metaphor is that the shell is the home environment for the user, or that the shell is what other programs are running in.)

In unix circles, shell has specialized to mean a command-line shell, centered around entering the name of the application one wants to start, followed by the names of files or other objects that the application should act on, and pressing the Enter key. Other types of environments (with the notable recent exception of Gnome Shell) usually don't use the word shell; for example, window systems involve window managers and desktop environments, not a shell.

There are many different unix shells. Ubuntu's default shell is Bash (like most other Linux distributions). Popular alternatives include zsh (which emphasizes power and customizability) and fish (which emphasizes simplicity).

Command-line shells include flow control constructs to combine commands. In addition to typing commands at an interactive prompt, users can write scripts. The most common shells have a common syntax based on the Bourne_shell. When discussing shell programming, the shell is almost always implied to be a Bourne-style shell. Some shells that are often used for scripting but lack advanced interactive features include the Korn shell (ksh)and many ash variants. Pretty much any Unix-like system has a Bourne-style shell installed as /bin/sh, usually ash, ksh or bash. On Ubuntu, /bin/sh is Dash, an ash variant (chosen because it is faster and uses less memory than bash).

In unix system administration, a user's shell is the program that is invoked when they log in. Normal user accounts have a command-line shell, but users with restricted access may have a restricted shell or some other specific command (e.g. for file-transfer-only accounts).

The division of labor between the terminal and the shell is not completely obvious. Here are their main tasks.

· Input: the terminal converts keys into control sequences (e.g. Left \e[D). The shell converts control sequences into commands (e.g. \e[D backward-char).

· Line edition, input history and completion are provided by the shell.

o The terminal may provide its own line edition, history and completion instead, and only send a line to the shell when it's ready to be executed. The only common terminal that operates in this way is M-x shell in Emacs.

· Output: the shell emits instructions such as display foo, switch the foreground color to green, move the cursor to the next line, etc. The terminal acts on these instructions.

· The prompt is purely a shell concept.

· The shell never sees the output of the commands it runs (unless redirected). Output history (scrollback) is purely a terminal concept.

· Inter-application copy-paste is provided by the terminal (usually with the mouse or key sequences such as Ctrl+Shift+V or Shift+Insert). The shell may have its own internal copy-paste mechanism as well (e.g. Meta+W and Ctrl+Y).

· Job control (launching programs in the background and managing them) is mostly performed by the shell. However, it's the terminal that handles key combinations like Ctrl+C to kill the foreground job and Ctrl+Z to suspend it.

Recycled from Unix & Linux

Answer by akiva

A visual representation.


enter image description here

Something you can sit down at, and work like a boss.


enter image description here

Some hardware that does a bunch of stuff.

Another example of a console, would be a video game console such as a Super Nintendo [where you can play Actraiser]


enter image description hereenter image description here

Basically an application for running commands.

Command Line [Interface]

enter image description hereenter image description here

Basically anything you input commands into.

Answer by agentcool

From the Linux Information Project:

Terminal : Technically , A terminal window, also referred to as a terminal emulator, is a text-only window in a graphical user interface (GUI) that emulates a console.

In Our words A GUI Application , from where we can access an user's console.

Console: an instrument panel containing the controls for a computer

Shell :A shell is a program that provides the traditional, text-only user interface for Linux and other Unix-like operating systems

Command-Line : A command line is the space to the right of the command prompt on an all-text display mode on a computer monitor (usually a CRT or LCD panel) in which a user enters commands and data

Tags: command-line

Q: How do I enable full-color support in Vim?

Q: How can I tell, from the command line, whether the machine requires a reboot?

Q: Coolest looking terminal IRC client

Q: How can I restart x-server from the command line?

Q: How do I determine the total size of a directory (folder) from the command line?

Q: How to create a permanent "alias"?

Q: Moving from bash to zsh

Q: How can I suspend/hibernate from command line?

Q: Change folder permissions and ownership

Q: How can I add a new user as sudoer using the command line?

Q: How to clean launch a GUI app via the Terminal (so it doesn't wait for termination)?

Q: How to send mail from the command line?

Q: What to do when Ctrl-C won't kill running job?

Q: Why is a virtual terminal "virtual", and what/why/where is the "real" terminal?

Q: How to become a Terminal Pro

Q: How can you log out via the terminal?

Q: Progress and speed with 'cp'?

Q: What do the different colors mean in the terminal?

Q: Find and replace text within a file using commands

Q: How to create an empty file from command line

Q: What is the difference between ./ and sh to run a script?

Q: How to protect Ubuntu from fork bomb

Q: How to really clear the terminal?

Q: Torrent client for the command-line?

Q: How do you select the fastest mirror from the command line?

Q: How do I install a .deb file via the command line?

Q: How to open a PDF file from terminal?

Q: How to use "grep" command to find text including subdirectories

Q: How do I rename a directory via the command line?

Q: How to easily rename files using command line?

Q: How can I create a zip archive of a whole directory via terminal without hidden files?

Q: How can I set default terminal used in Unity?

Q: How to install Chrome browser properly via command line?

Q: How to unzip a zip file from the Terminal?

Q: How to check Internet Speed via Terminal?

Q: Running programs in the background from terminal

Q: I was tricked into copy pasting a command, did it hurt me?

Q: What is the equivalent of Windows System Properties or Device Manager?

Q: How can I get a list of all repositories and PPAs from the command line?

Q: How can I get octal file permissions from command line?

Q: How can I easily share the output of a command or a text file with others?

Q: Why did the command ":(){ :|: & };:" make my system lag so badly I had to reboot?

Q: How do I find the kernel version, Ubuntu release and disk partition information from the terminal?

Q: How do I delete my commands quickly?

Q: How do I restart /shutdown from a terminal?

Q: What is the terminal command to take a screenshot?

Q: How to delete a non-empty directory in Terminal?

Q: What does "sudo apt-get update" do?

Q: Run same command again but as root

Q: Differences between /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin

Q: How can I recursively delete all files of a specific extension in the current directory?

Q: Any command line calculator for Ubuntu?

Q: What does `!!` mean in `sudo !!`?

Q: What is the difference between Terminal, Console, Shell, and Command Line?