Most Popular
1500 questions
400
votes
4 answers
What characters do I need to escape when using sed in a sh script?
Take the following script:
#!/bin/sh
sed 's/(127\.0\.1\.1)\s/\1/' [some file]
If I try to run this in sh (dash here), it'll fail because of the parentheses, which need to be escaped. But I don't need to escape the backslashes themselves (between…
detly
- 5,020
- 6
- 23
- 29
397
votes
4 answers
Specify identity file (id_rsa) with rsync
I need to make periodic backups of a directory on a remote server which is a virtual machine hosted by a research organisation. They mandate that access to VMs is through ssh keys, which is all good, except that I can't figure out how to point rsync…
Jangari
- 4,388
- 2
- 13
- 9
396
votes
3 answers
How to check OS and version using a Linux command
What is the Linux command to check the server OS and its version?
I am connected to the server using shell.
sarath
- 4,071
- 3
- 13
- 4
396
votes
14 answers
What DNS servers am I using?
How can I check which DNS server am I using (in Linux)? I am using network manager and a wired connection to my university's LAN. (I am trying to find out why my domain doesn't get resolved)
Grzenio
- 5,747
- 12
- 32
- 41
393
votes
7 answers
Count total number of occurrences using grep
grep -c is useful for finding how many times a string occurs in a file, but it only counts each occurence once per line. How to count multiple occurences per line?
I'm looking for something more elegant than:
perl -e '$_ = <>; print scalar ( () =…
user4518
391
votes
12 answers
How to view the output of a running process in another bash session?
I have left a script running on a remote machine from when I was locally working at it. I can connect over SSH to the machine as the same user and see the script running in ps.
$ ps aux | grep ipcheck
myuser 18386 0.0 0.0 18460 3476 pts/0 …
jwbensley
- 7,402
- 11
- 35
- 43
389
votes
1 answer
How do you empty the buffers and cache on a Linux system?
Prior to doing some benchmarking work how would one free up the memory (RAM) that the Linux Kernel is consuming for its buffers and cache?
Note that this is mostly useful for benchmarking. Emptying the buffers and cache reduces performance! If…
slm
- 363,520
- 117
- 767
- 871
388
votes
32 answers
What is the fastest way to view images from the terminal?
The terminal is very fast and convenient way to quickly access directories and files (faster than find and click on the directory).
One thing that it cannot show in text-mode is "pictures".
What is a best way to view pictures (like you see images…
fronthem
- 4,957
- 6
- 24
- 31
382
votes
12 answers
How can I delete all lines in a file using vi?
How can I delete all lines in a file using vi?
At moment I do that using something like this to remove all lines in a file:
echo > test.txt
How can I delete all lines using vi?
Note:
Using dd is not a good option. There can be many lines.
Cold
- 4,133
- 5
- 13
- 11
378
votes
7 answers
How can I find the implementations of Linux kernel system calls?
I am trying to understand how a function, say mkdir, works by looking at the kernel source. This is an attempt to understand the kernel internals and navigate between various functions. I know mkdir is defined in sys/stat.h. I found the…
Navaneeth K N
- 3,988
- 3
- 17
- 13
378
votes
11 answers
Write all tmux scrollback to a file
How can I write all the scrollback in a tmux session to a file?
capture-panel can grab the current screen, but not the entire scrollback.
David Wolever
- 4,654
- 4
- 17
- 15
376
votes
2 answers
Ctrl-s hangs the terminal emulator?
I came across a sentence in vimdoc:
Note: CTRL-S does not work on all terminals and might block
further input, use CTRL-Q to get going again.
and using CTRL-S indeed hangs my vim. I was thinking that it was vims fault, since there…
Hongxu Chen
- 5,828
- 8
- 27
- 32
376
votes
13 answers
How to remove a single line from history?
I'm working in Mac OSX, so I guess I'm using bash...?
Sometimes I enter something that I don't want to be remembered in the history. How do I remove it?
B Seven
- 7,659
- 7
- 23
- 20
370
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…
Gilles 'SO- stop being evil'
- 807,993
- 194
- 1,674
- 2,175
368
votes
12 answers
How to list all files ordered by size
I would like to list all files in the order of big to small in size and the files could be present anywhere in a certain folder.
Joe
- 3,813
- 2
- 13
- 4