Most Popular

1500 questions
107
votes
3 answers

Why can rm remove read-only files?

If I create a file and then change its permissions to 444 (read-only), how come rm can remove it? If I do this: echo test > test.txt chmod 444 test.txt rm test.txt ...rm will ask if I want to remove the write-protected file test.txt. I would have…
Magnus
  • 1,413
107
votes
4 answers

What does "3>&1 1>&2 2>&3" do in a script?

I saw this line in a script: DEVICE=`dialog --inputbox "Festplatten-Laufzeit auslesen. Gebe Sie das gewünschte Device an: " 0 70 "" 3>&1 1>&2 2>&3` What is 3>&1 1>&2 2>&3 doing? I know that 1 = stdout and 2 = stderr, but what are the 3 and the &…
jsterr
  • 1,341
107
votes
5 answers

Systemd Restart=always is not honored

Note: I wrote an article on Medium that explains how to create a service, and how to avoid this particular issue: Creating a Linux service with systemd. Original question: I'm using systemd to keep a worker script working at all…
BenMorel
  • 4,587
107
votes
3 answers

Why does bashrc check whether the current shell is interactive?

On my Arch install, /etc/bash.bashrc and /etc/skel/.bashrc contain these lines: # If not running interactively, don't do anything [[ $- != *i* ]] && return On Debian, /etc/bash.bashrc has: # If not running interactively, don't do anything [ -z…
terdon
  • 242,166
107
votes
5 answers

Using awk to sum the values of a column, based on the values of another column

I am trying to sum certain numbers in a column using awk. I would like to sum just column 3 of the "smiths" to get a total of 212. I can sum the whole column using awk but not just the "smiths". I have: awk 'BEGIN {FS = "|"} ; {sum+=$3} END {print…
jake
  • 1,215
  • 2
  • 10
  • 9
107
votes
5 answers

Restart bash from terminal without restarting the terminal application (mac)?

I've looked around and bit for an answer to this question but I don't seem to find it (which is weird). My question is, is there any simple way to restart the BASH session from within the terminal on Mac. I just want the same behaviour as if I…
Mattias
  • 1,587
107
votes
7 answers

How to use command line to change volume?

I am trying to control the volume using my programming script. How can I do the following in Fedora 15, Ubuntu linux? Mute/ Unmute Volume up and volume down Note: Please note that I use a web USB microphone/speaker and also Analogue…
user11085
107
votes
2 answers

how to count the length of an array defined in bash?

I'm new to bash and can't find a good tutorial to answer my question. array=( item1 item2 item3 ) for name in ${array[@]}; do echo current/total ... some other codes done I want to calculate the current and total value, as the expected…
AGamePlayer
  • 7,605
107
votes
3 answers

How can I create a virtual ethernet interface on a machine without a physical adapter?

I have a Dell XPS 13 ultrabook which has a wifi nic, but no physical ethernet nic (wlan0, but no eth0). I need to create a virtual adapter for using Vagrant with NFS, but am finding that the typical ifup eth0:1... fails with ignoring unknown…
STW
  • 2,261
  • 5
  • 20
  • 23
107
votes
4 answers

How to undo `set -x`?

I typed set -x in terminal. Now the terminal keeps printing the last command run on top of my output so the command ~]$echo "this is what I see" returns + echo 'this is what I see' this is what I see There is no man page for set, how do I turn…
107
votes
7 answers

command to determine ports of a device (like /dev/ttyUSB0)

I have a question regarding the ports in Linux. If I connect my device via USB and want to check its port I can't do it using the command lsusb, which only specifies bus number and device number on this bus: [ziga@Ziga-PC ~]$ lsusb Bus 003 Device…
71GA
  • 1,106
107
votes
6 answers

Difference between ls -l and ll?

I'm relatively new to programming as a whole and some tutorials have been telling me to use ls -l to look at files in a directory and others have been saying ll. I know that ls is a short list, but is there a difference between the other two?
Jon
  • 1,191
107
votes
8 answers

Into which directory should I install programs in Linux?

I want to install a program in Linux and run it as a daemon. (Team Speak 3 in this case, but the question is general in nature). There is no package provided, only tarred binaries. Where in the directory structure should I put such a program by…
Eiver
  • 1,225
107
votes
11 answers

Remember a half-typed command while I check something

I often find myself in the following position: I've started typing a long command at the bash prompt, but half-way through I find out I need to check something with another command. This is a problem when I'm at the console (no X), which is often…
106
votes
5 answers

Bash throws error, line 8: $1: unbound variable

I am trying to learn how to use getopts so that I can have scripts with parsed input (although I think getopts could be better). I am trying to just write a simple script to return partition usage percentages. The problem is that one of my bash…