Most Popular

1500 questions
135
votes
20 answers

How to count the number of a specific character in each line?

I was wondering how to count the number of a specific character in each line by some text processing utilities? For example, to count " in each line of the following text "hello!" Thank you! The first line has two, and the second line has 0.…
Tim
  • 101,790
135
votes
17 answers

Getting tmux to copy a buffer to the clipboard

I am trying to figure out a decent way to copy what I have in a tmux buffer into my clipboard. I have tried a couple of different things like bind-key p select-pane -t 2 \; split-window 'xsel -i -b' \; paste-buffer which gets me fairly close, all…
135
votes
7 answers

Why do we need to fork to create new processes?

In Unix whenever we want to create a new process, we fork the current process, creating a new child process which is exactly the same as the parent process; then we do an exec system call to replace all the data from the parent process with that…
sarthak
  • 1,472
134
votes
8 answers

Which is the safest way to get root privileges: sudo, su or login?

I would like to have the root account in safety even if my unprivileged user is compromised. On Ubuntu you can only use sudo for "security reasons" by default. However I am not sure it is any safer than just using login on a text-mode console. There…
stribika
  • 5,454
134
votes
4 answers

How do you do a dry run of rm to see what files will be deleted?

I want to see what files will be deleted when performing an rm in linux. Most commands seem to have a dry run option to show just such information, but I can't seem to find such an option for rm. Is this even possible?
Cory Klein
  • 18,911
134
votes
10 answers

How do I get bash completion for command aliases?

I am looking to get tab-completion on my command line aliases, for example, say I defined the following alias : alias apt-inst='sudo aptitude install' Is there a way to get the completions provided by aptitude when I hit the tab key? i.e. when I…
levesque
  • 3,815
134
votes
13 answers

How can I tell what version of Linux I'm using?

Often times I will ssh into a new client's box to make changes to their website configuration without knowing much about the server configuration. I have seen a few ways to get information about the system you're using, but are there some standard…
cwd
  • 45,389
134
votes
9 answers

GPT or MBR: How do I know?

How can I tell whether my harddrive is laid out using an MBR or GPT format?
goldilocks
  • 87,661
  • 30
  • 204
  • 262
134
votes
6 answers

What is the right file permission for a .pem file to SSH and SCP

I have tried to SSH into my AWS Ubuntu server and copy the directory to my local machine. Throughout the process I experience different file permission errors (noted below). Is there one specific file permission needed for the .pem file that…
133
votes
14 answers

Replace string in a huge (70GB), one line, text file

I have a huge (70GB), one line, text file and I want to replace a string (token) in it. I want to replace the token , with another dummy token (glove issue). I tried sed: sed 's///g' < corpus.txt > corpus.txt.new but the output…
133
votes
36 answers

Quick directory navigation in the bash shell

I would like to frequently switch between directories that are in totally unrelated paths, for example /Project/Warnest/docs/ and ~/Dropbox/Projects/ds/test/. But I don't want to type cd /[full-path]/ all the time. Are there any shortcut commands to…
saiy2k
  • 1,593
133
votes
1 answer

Does nginx support comment blocks in configuration?

I have here an nginx config. I need to comment out blocks in it: ...things I want... ...things I don't want... ...things I want... The things are 30-50 lines long, and I won't backup and delete them. I also don't want write #s to the beginning of…
peterh
  • 9,731
133
votes
6 answers

watch command alias expansion

If a run the watch command containing an alias, it will not expand the alias. I have tried both with single quote and double quotes, in fact given the following alias: # alias ll alias ll='ls -l --color=tty' The following command will fail # watch…
ztank1013
  • 2,221
  • 2
  • 14
  • 14
133
votes
6 answers

Confusing use of && and || operators

I was skimming through an /etc/rc.d/init.d/sendmail file (I know this is hardly ever used, but I'm studying for an exam), and I've become a bit confused about the && and the || operators. I've read where they can be used in statements such as: if […
josh-cain
  • 1,821
133
votes
3 answers

How to shrink root filesystem without booting a livecd

I find myself needing to rearrange a system's partitions to move data previously under the root filesystem into dedicated mount points. The volumes are all in LVM, so this is relatively easy: create new volumes, move data into them, shrink the root…
Tom Hunt
  • 10,056