Most Popular
1500 questions
410
votes
13 answers
How can I get the size of a file in a bash script?
How can I get the size of a file in a bash script?
How do I assign this to a bash variable so I can use it later?

haunted85
- 4,261
409
votes
18 answers
How can I prevent 'grep' from showing up in ps results?
When I search for some process that doesn't exist, e.g.
$ ps aux | grep fnord
wayne 15745 0.0 0.0 13580 928 pts/6 S+ 03:58 0:00 grep fnord
Obviously I don't care about grep - that makes as much sense as…

Wayne Werner
- 11,713
408
votes
13 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 …

Baldrick
- 7,652
407
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
406
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,989
406
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,867
399
votes
33 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
- 5,107
397
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,081
397
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
- 369,824
397
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,854
384
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,153
381
votes
21 answers
How do I trim leading and trailing whitespace from each line of some output?
I would like to remove all leading and trailing spaces and tabs from each line in an output.
Is there a simple tool like trim I could pipe my output into?
Example file:
test space at back
test space at front
TAB at end
TAB at front
sequence…

rubo77
- 28,966
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
378
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,913
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,858