Most Popular

1500 questions
376
votes
13 answers

Prepending a timestamp to each line of output from a command

I wish to prepend a timestamp to each line of output from a command. For example: foo bar baz would become [2011-12-13 12:20:38] foo [2011-12-13 12:21:32] bar [2011-12-13 12:22:20] baz ...where the time being prefixed is the time at which the line…
anon
375
votes
6 answers

Why does my shell script choke on whitespace or other special characters?

… or an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some file names). I encountered a problem such as the…
369
votes
5 answers

How to set default file permissions for all folders/files in a directory?

I want to set a folder such that anything created within it (directories, files) inherit default permissions and group. Lets call the group "media". And also, the folders/files created within the directory should have g+rw automatically.
Chris
  • 8,540
  • 5
  • 23
  • 18
368
votes
5 answers

How do I set an environment variable on the command line and have it appear in commands?

If I run export TEST=foo echo $TEST It outputs foo. If I run TEST=foo echo $TEST It does not. How can I get this functionality without using export or a script?
367
votes
4 answers

How do I clear Bash's cache of paths to executables?

When I execute a program without specifying the full path to the executable, and Bash must search the directories in $PATH to find the binary, it seems that Bash remembers the path in some sort of cache. For example, I installed a build of…
365
votes
10 answers

Change the Python3 default version in Ubuntu

I am using Ubuntu 16.04 LTS . I have python3 installed. There are two versions installed, python 3.4.3 and python 3.6 . Whenever I use python3 command, it takes python 3.4.3 by default. I want to use python 3.6 with python3. python3 --version shows…
codeclue
  • 3,763
364
votes
11 answers

How can I monitor disk io?

I'd like to do some general disk io monitoring on a debian linux server. What are the tools I should know about that monitor disk io so I can see if a disk's performance is maxed out or spikes at certain time throughout the day?
camomileCase
  • 3,865
364
votes
18 answers

How do I set my DNS when resolv.conf is being overwritten?

Most of the info I see online says to edit /etc/resolv.conf, but any changes I make there just get overridden. $ cat /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND…
Seán Hayes
  • 4,541
363
votes
6 answers

How to define 'tab' delimiter with 'cut' in Bash?

Here is an example of using cut to break input into fields using a space delimiter, and obtaining the second field: cut -f2 -d' ' How can the delimiter be defined as a tab, instead of a space?
Muhammad Hasan Khan
  • 3,733
  • 2
  • 15
  • 6
361
votes
3 answers

Hide curl output

I'm making a curl request where it displays an html output in the console like this Warning: Cannot modify header information - headers already sent by (output started at…
Rjack
  • 3,613
360
votes
4 answers

How to permanently set environmental variables

My variables are LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib ORACLE_HOME=/usr/lib/oracle/11.2/client64 How to save these variables permanently ?
user3021349
  • 16,569
355
votes
5 answers

How can I update to a newer version of Git using apt-get?

I've just set up a new machine with Ubuntu Oneiric 11.10 and then run apt-get update apt-get upgrade apt-get install git Now if I run git --version it tells me I have git version 1.7.5.4 but on my local machine I have the much newer git version…
cwd
  • 45,389
354
votes
12 answers

How to know number of cores of a system in Linux?

I wanted to find out how many cores my system has, so I searched the same question in Google. I got some commands such as the lscpu command. When I tried this command, it gave me the following result: $ lscpu Architecture: x86_64 CPU…
Mr ASquare
  • 3,735
352
votes
22 answers

How can I run ssh-add automatically, without a password prompt?

I want to communicate between several computers on my network (static Ethernet), through SSH. In order to do that I need to run ssh-add every time I log in on a specific machine. What can I do so it's set up once and it doesn't ask me for the…
zdun8
  • 3,687
350
votes
4 answers

What does "rc" in .bashrc stand for?

Is it "resource configuration", by any chance?
Lazer
  • 35,307