Most Popular
1500 questions
132
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
- 98,580
- 191
- 570
- 977
132
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,442
- 2
- 10
- 8
132
votes
6 answers
Setting a name for a screen session
Is there a way to give a particular name to a unix screen session? For instance, say I'm running the same program multiple times, each with different parameters and I want to tell which one is which.
well actually
- 3,045
- 5
- 20
- 11
131
votes
3 answers
How do you use output redirection in combination with here-documents and cat?
Let's say I have a script that I want to pipe to another command or redirect to a file (piping to sh for the examples). Assume that I'm using bash.
I could do it using echo:
echo "touch somefile
echo foo > somefile" | sh
I could also do almost the…
strugee
- 14,723
- 17
- 73
- 119
131
votes
3 answers
Kill an unresponsive ssh session without closing the terminal
Is there a way to disconnect from an SSH session that has become unresponsive without killing the whole terminal? Specifically I'm using konsole, and the machine I'm working with sometimes hangs, but doesn't actually die (thus killing the…
Falmarri
- 12,897
- 17
- 58
- 71
131
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
- 9,808
- 4
- 25
- 43
131
votes
10 answers
How can I keep my SSH sessions from freezing?
I have ServerAliveInterval and in case of few machines also ClientAliveInterval set to 540 in SSH client/server configuration files (I suppose setting it to more than that would not be a good idea). I work with many SSH sessions which currently…
syntagma
- 12,091
- 21
- 57
- 74
131
votes
3 answers
How to renew an expired keypair with gpg
What is the best way to renew a gpg key pair when it got expired and what is the reason for the method?
The key pair is already signed by many users and available on public servers.
Should the new key be a subkey of the expired private key?
Should…
Jonas Stein
- 3,898
- 4
- 34
- 55
131
votes
8 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
- 86,451
- 30
- 200
- 258
130
votes
8 answers
How can get the creation date of a file?
I want to find out the creation date of a particular file on a Linux system. Not the modification date or access date, the creation date.
I have tried with ls -ltrh and stat filename but neither gives me what I need. What else can I do to get this…
Özzesh
- 3,549
- 8
- 23
- 25
130
votes
5 answers
How to ssh to remote server using a private key?
I have two servers. Both servers are in CentOS 5.6. I want to SSH from Server 1 to Server 2 using a private key I have (OpenSSH SSH-2 Private Key).
I don't know how to do it over unix. But what I did on windows using Putty was to feed my OpenSSH…
Aivan Monceller
- 1,563
- 2
- 11
- 10
129
votes
7 answers
How can I look up a username by id in linux?
The command id can be used to look up a user's uid, for example:
$ id -u ubuntu
1000
Is there a command to lookup up a username from a uid? I realize this can be done by looking at the /etc/passwd file but I'm asking if there is an existing command…
cwd
- 44,479
- 71
- 146
- 167
129
votes
1 answer
How to make tmux count windows starting from 1 instead of 0?
I was able to make GNU Screen start counting windows with the number 1 instead of the default 0 with this code in my .screenrc:
# Get rid of screen 0
bind c screen 1
bind ^c screen 1
bind 0 select 10
When I created windows in .screenrc I used…
hekevintran
- 3,443
- 3
- 14
- 9
129
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,488
- 16
- 59
- 88
129
votes
5 answers
Match exact string using grep
I have a text file:
deiauk 1611516 afsdf 765
minkra 18415151 asdsf 4152
linkra sfsfdsfs sdfss 4555
deiauk1 sdfsfdsfs 1561 51
deiauk2 115151 5454 4
deiauk 1611516 afsdf ddfgfgd
luktol1 4545 4 9
luktol 1
and I want to match exactly deiauk. When I do…
user3334375
- 1,745
- 6
- 16
- 16