Sparhawk
  • Member for 9 years, 6 months
  • Last seen this week
  • Melbourne, Australia
15 answers
140 votes
204k views
How do I repeat the last command without using the arrow keys?
Accepted answer
197 votes

With csh or any shell implementing csh-like history substitution (tcsh, bash, zsh): !! Then Enter. Or alternatively: !-1 Then Enter. Or Ctrl+P, Enter Magic space Also, note that !! and !-1 will ...

View answer
6 answers
75 votes
348k views
How to use a shell command to only show the first column and last column in a text file?
104 votes

Almost there. Just put both column references next to each other. cat logfile | sed 's/|/ /' | awk '{print $1, $8}' Also note that you don't need cat here. sed 's/|/ /' logfile | awk '{print $1, $8}...

View answer
1 answers
25 votes
35k views
Does rsync delete files on the destination that were deleted from the sending side?
Accepted answer
47 votes

Only if you… select one of the delete options. See man rsync for more information, but here is an excerpt: --delete delete extraneous files from dest dirs --delete-before ...

View answer
8 answers
12 votes
6k views
Grep remove line with 0 but not 0.2?
Accepted answer
35 votes

grep -vx 0 From man grep: -x, --line-regexp Select only those matches that exactly match the whole line. For a regular expression pattern, this is like parenthesizing the ...

View answer
2 answers
20 votes
7k views
vimdiff to compare output instead of files
Accepted answer
29 votes

You are confusing $(…) with <(…). You used the former, which passes the output as arguments to vimdiff. For example, if the last line of /path/to/foo contains bar bar bar, then the following ...

View answer
1 answers
11 votes
31k views
Is it possible to run Steam games using optirun?
Accepted answer
27 votes

In theory, primusrun is preferred over optirun for performance and stability, as recommended by the bumblebee devs. I'm unsure why you get the results you did. I know in some cases, frames are capped, ...

View answer
1 answers
15 votes
4k views
How can I find if my wifi card supports 802.11ac?
Accepted answer
23 votes

If you run iw list, look for the lines specifying VHT. VHT Capabilities (0x038071a0): Max MPDU length: 3895 Supported Channel Width: neither 160 nor 80+80 short GI (80 MHz)...

View answer
1 answers
9 votes
2k views
How can I prevent Meta from opening up KDE Plasma's launcher?
Accepted answer
14 votes

As implied here, edit ~/.config/kwinrc, adding the following lines to the bottom. [ModifierOnlyShortcuts] Meta= Then restart kwin with kwin_x11 --replace & disown.

View answer
5 answers
10 votes
6k views
Shifting command output to the right
Accepted answer
14 votes

cal | sed 's/^/ /' Explanation cal |: pipe the output of cal to… sed 's/^/ /' sed, which will look for the start of lines ^, replacing with spaces. You can change the number of spaces here ...

View answer
3 answers
22 votes
6k views
What is the fastest way to run a script?
13 votes

I would have instinctively agreed with Satō Katsura's answer; it makes sense. However, it's easy enough to test. I tested writing a million lines to the screen, writing (appending) to a file, and ...

View answer
1 answers
3 votes
3k views
Is `echo $TEST` expanding an asterisk in the variable a bug?
Accepted answer
13 votes

No, it is not a bug. You have shown that echo '*' will produce a literal *. Hence when you substitute this output, as per the following command TEST=$(echo '*') it will put * into the variable $...

View answer
21 answers
48 votes
54k views
Simple command-line calculator
11 votes

Personally, I like libqalculate (the command-line version of Qalculate). $ qalc > 236-192 236 - 192 = 44 While the interface is certainly simple, (lib)qalculate is a powerful, full-fledged ...

View answer
2 answers
7 votes
8k views
How to get execution millisecond time of a command in zsh?
Accepted answer
11 votes

zsh's time uses the TIMEFMT variable to control the format. By default, this is %J %U user %S system %P cpu %*E total, which produces the following. $ time sleep 2 sleep 2 0.00s user 0.00s system 0% ...

View answer
1 answers
4 votes
2k views
Replicate oh-my-zsh directory tab completion selection with arrow keys
Accepted answer
10 votes

To enable the tab-completion menu in zsh, put the following in ~/.zshrc: autoload -Uz compinit compinit zstyle ':completion:*' menu select

View answer
2 answers
5 votes
4k views
Execution order with multiple commands
Accepted answer
10 votes

Why don't you test it with some dummy commands that you know will work or fail? $ ls foo && echo ok1 ; echo ok2 ls: cannot access foo: No such file or directory ok2 $ ls foo && (echo ...

View answer
1 answers
3 votes
7k views
Split string by space in ZSH
Accepted answer
9 votes

From man zshbuiltins, zsh's read uses -A instead. read [ -rszpqAclneE ] [ -t [ num ] ] [ -k [ num ] ] [ -d delim ] [ -u n ] [ name[?prompt] ] [ name ... ] ... -A The first name is ...

View answer
1 answers
8 votes
9k views
Iterating over files in Bash and obtaining the index and the counts
Accepted answer
9 votes

I would store the list of files in an array, so that you don't have to read the file system twice, increasing performance and reducing potential race conditions. Then use another variable as the index....

View answer
5 answers
12 votes
3k views
Do I need a Linux distro to learn the command line or would OS X be sufficient?
9 votes

Some good answers so far, but one more reason to stay away from the default OS X command line tools is they are very old versions. For example, OS X's grep is from 2004, and bash is from 2007! The ...

View answer
2 answers
4 votes
2k views
Is there a reason to use multiple question marks instead of an asterisk in filename expansion?
Accepted answer
9 votes

Function They mean different things. The asterisk matches zero to infinity characters. The question mark matches exactly one character. From the references above: The * character serves as a "...

View answer
4 answers
1 votes
358 views
change last 10 characters of the base (not extension) of multiple files
Accepted answer
8 votes

There are two Linux commands called rename that are commonly available in distributions. I prefer the perl-based rename, as it's more powerful. You can check which one you have using $ prename --...

View answer
2 answers
3 votes
716 views
grep ignoring pipe when aliased to 'grep -R'
Accepted answer
7 votes

The alias is what is causing it. From man grep, the -R option causes grep to "read all files under each directory, recursively". Hence, the part after the pipe ignores the output from the first grep, ...

View answer
1 answers
5 votes
3k views
How can I install asciiquarium as a screensaver?
Accepted answer
7 votes

Asciiquarium can run in a fullscreen terminal, and the screen locked with xtrlock. However the link is short on details. Firstlly, I prefer alock to xtrlock, since it provides some visual feedback on ...

View answer
5 answers
6 votes
12k views
Hide part of match from grep output
Accepted answer
7 votes

Instead of using extended-regex grep (-E), use perl-regex grep instead (-P), with a lookbehind and lookahead. $ grep -oP "(?<=\[)[0-9].+(?=\])" logfile 113a6d9e-7b06-42c6-a52b-7a4e4d2e216c ...

View answer
4 answers
6 votes
1k views
How can I blank the nth to mth field using the awk command?
7 votes

</path/to/in_file awk -v 'FS=,' -v 'OFS=,' '{$3=$4=""; print}' Explanation </path/to/in_file: read file to standard in. -v 'FS=,' -v 'OFS=,': set file separators and output file separator to ,....

View answer
2 answers
4 votes
4k views
Run crontab only if condition
Accepted answer
7 votes

I don't think you can use environment variables, as they won't persist between script "runs". Alternatively, you could write to a temporary file in /tmp or somewhere in your home directory, then ...

View answer
1 answers
4 votes
295 views
unexpected output with grep
Accepted answer
7 votes

I think it is because this line No valid EAOPL-handshake + ESSID detected. is probably standard error of the pyrit command, not standard out. Normally, | pipes standard out to the next command, with ...

View answer
1 answers
3 votes
7k views
grep for one or more occurrences of a word
Accepted answer
6 votes

By default, grep uses BRE (basic regular expressions), which means that special characters like + will be interpreted as a literal character. Hence, in GNU grep, it will need to be escaped, i.e. ...

View answer
2 answers
8 votes
3k views
How can I use mutt with local storage, IMAP and instant pushing of new email?
Accepted answer
6 votes

Unfortunately, the two possibilities suggested in the other answer were imperfect. offlineimap was fairly buggy at the best of times. For example, there is no way to automatically run a script after ...

View answer
5 answers
4 votes
6k views
How to get unique lines based on value of a column
6 votes

If you don't mind scrambling the order, then sort <file> | uniq -uw 1 See man uniq for more information, but here are the important parts. -u, --unique only print unique lines ...

View answer
3 answers
2 votes
10k views
How do I check whether a variable has been passed to a function in Bash?
6 votes

I'm not sure why this fails, but there are (at least) two other possible options. Instead of [[ -v $1 ]], you could use either of the following. Check that the number of arguments is more than zero. ...

View answer
1
2 3 4 5
7