Most Popular

1500 questions
96
votes
1 answer

How to change primary group?

I have a user like this: uid=501(ironsand) gid=500(foo) groups=500(foo),10(wheel),497(git),501(ironsand) And to change primary group to ironsand like gid=501(ironsand), I typed this command: sudo usermod -g ironsand ironsand It changed groups…
ironsand
  • 5,205
96
votes
10 answers

Use system clipboard in vi-copy mode in tmux

I'm running tmux 1.6 and I'm trying to configure it to use vi-style keybindings as well as use the system clipboard when copying in interactive mode: set-window-option -g mode-keys vi bind-key -t vi-copy 'v' begin-selection bind-key -t vi-copy 'y'…
Naftuli Kay
  • 39,676
96
votes
15 answers

chroot: failed to run command ‘/bin/bash’: No such file or directory

When I run the chroot command an error is given: failed to run command ‘/bin/bash’: No such file or directory
USER3254789
  • 1,091
96
votes
14 answers

How to remove all the files in a directory?

I am trying to remove all files and subdirectories in a directory. I used rm -r to remove all files, but I want to remove all files and subdirectories, excluding the top directory itself. For example, I have a top directory like images. It contains…
whiterose
  • 1,069
  • 1
  • 8
  • 4
96
votes
13 answers

bash: test if $WORD is in set

I am looking for a construct in bash, to decide if a variable $WORD is one of defined words. I need something like this: if "$WORD" in dog cat horse ; then echo yes else echo no fi does bash have such construct? If not, what would be the…
Martin Vegter
  • 358
  • 75
  • 236
  • 411
96
votes
4 answers

Why use install rather than cp and mkdir?

I've seen in many places used install -d to create directories and install -c to copy a file. Why not use mkdir and cp? Is there an advantage in using install?
96
votes
3 answers

Why is the root directory denoted by a / sign?

I have done some research about this on Google, but the results were cloudy. Why is the / sign used to denote the root directory. Are there any solid reasons behind it?
Ruban Savvy
  • 8,659
95
votes
9 answers

Is there a tool that combines zcat and cat transparently?

When handling log files, some end up as gzipped files thanks to logrotate and others not. So when you try something like this: $ zcat * you end up with a command line like zcat xyz.log xyz.log.1 xyz.log.2.gz xyz.log.3.gz and then with: gzip:…
0xC0000022L
  • 16,593
95
votes
5 answers

Splitting string by the first occurrence of a delimiter

I have a string in the next format id;some text here with possible ; inside and want to split it to 2 strings by first occurrence of the ;. So, it should be: id and some text here with possible ; inside I know how to split the string (for instance,…
gakhov
  • 1,105
95
votes
2 answers

How to display the Linux kernel command line parameters given for the current boot?

In the grub.conf configuration file I can specify command line parameters that the kernel will use, i.e.: kernel /boot/kernel-3-2-1-gentoo root=/dev/sda1 vga=791 After booting a given kernel, is there a way to display the command line parameters…
colemik
  • 1,371
95
votes
2 answers

How to insert text into a root-owned file using sudo?

Possible Duplicate: Redirecting stdout to a file you don't have write permission on Running a command like sudo echo 'text' >> /file.txt fails with: bash: /file.txt: Permission denied
tshepang
  • 65,642
95
votes
8 answers

Multiple arguments in shebang

I am wondering whether there is a general way of passing multiple options to an executable via the shebang line (#!). I use NixOS, and the first part of the shebang in any script I write is usually /usr/bin/env. The problem I encounter then is that…
95
votes
7 answers

How to set custom resolution using xrandr when the resolution is not available in 'Display Settings'

I'm a new Linux user trying to change the screen resolution as there is no option under display. I have successfully managed to add new resolutions by fluke by following online guide. I don't have a GPU, I don't know if this is the issue? Below is…
nick
  • 961
95
votes
2 answers

Is there ever a good reason to run sudo su?

To launch a root shell on machines where the root account is disabled, you can run one of: sudo -i : run an interactive login shell (reads /root/.bashrc and /root/.profile) sudo -s : run a non-login interactive shell (reads /root/.bashrc) In the…
terdon
  • 242,166
95
votes
4 answers

How to get last N commands from history?

I want to see what are the last N commands in my history. I thought history | tail -n 5 would make it, but I noticed that a multiline command counts for as many lines as it has. $ echo "hello how are you" $ history | tail -2 how are you" 1051 …
fedorqui
  • 7,861
  • 7
  • 36
  • 74