mrb
  • Member for 9 years, 6 months
  • Last seen this week
How to display the Linux kernel command line parameters given for the current boot?
Accepted answer
135 votes

$ cat /proc/cmdline root=/dev/xvda xencons=tty console=tty1 console=hvc0 nosep nodevfs ramdisk_size=32768 ip_conntrack.hashsize=8192 nf_conntrack.hashsize=8192 ro devtmpfs.mount=1 $

View answer
How can I page up or down in tmux with Terminal.app?
108 votes

If you're using OS X's Terminal.app, it will capture Page up/down keypresses and just scroll the window contents, as if you used the scroll bar. You can use Shift+Page up/down to send them to the ...

View answer
SSH inside SSH fails with "stdin: is not a tty"
Accepted answer
82 votes

By default, when you run a command on the remote machine using ssh, a TTY is not allocated for the remote session. This lets you transfer binary data, etc. without having to deal with TTY quirks. ...

View answer
How do I perform a reverse history search in ZSH's vi-mode?
Accepted answer
74 votes

You can run bindkey with no arguments to get a list of existing bindings, eg: # Enter vi mode chopper:~> bindkey -v # Search for history key bindings chopper:~> bindkey | fgrep history "^[OA" ...

View answer
Is there a standard command that always exits with a failure?
Accepted answer
70 votes

You can use false (/bin/false, /usr/bin/false, or shell builtin): $ false || echo It failed. It failed. $ You can also use exit 1 from a subshell: $ (exit 1) || echo Gosh, it failed too. Gosh, it ...

View answer
How to grep a specific line _and_ the first line of a file?
59 votes

How do you feel about using awk instead of grep? chopper:~> ps aux | awk 'NR == 1 || /syslogd/' USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND root ...

View answer
Bulk rename, change prefix
Accepted answer
48 votes

for name in TestSR* do newname=CL"$(echo "$name" | cut -c7-)" mv "$name" "$newname" done This uses bash command substitution to remove the first 6 characters from the input filename via cut, ...

View answer
How can I use bash's if test and find commands together?
Accepted answer
33 votes

[ and test are synonyms (except [ requires ]), so you don't want to use [ test: [ -x /bin/cat ] && echo 'cat is executable' test -x /bin/cat && echo 'cat is executable' test returns ...

View answer
My `which` command may be wrong (sometimes)?
Accepted answer
32 votes

The three possibilities that come to mind for me: An alias exists for emacs (which you've checked) A function exists for emacs The new emacs binary is not in your shell's PATH hashtable. You can ...

View answer
How do I use tee to redirect to grep
Accepted answer
22 votes

$ ps aux | tee >(head -n1) | grep syslog USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND syslog 806 0.0 0.0 34600 824 ? Sl Sep07 0:00 rsyslogd -c4 The ...

View answer
diff reports two files differ, although they are the same!
18 votes

Might the differences be caused by DOS vs. UNIX line endings, or something similar? What if you hexdump them? This might show differences more obviously, eg: hexdump -C file1 > file1.hex hexdump -...

View answer
bunzip2 to a different directory
Accepted answer
16 votes

You can use the other bzip2 tools: bzcat foo.tbz2 > /another/directory/foo.tar bzip2 -ckd foo.tbz2 > /another/directory/foo.tar Note that if you want to untar it to another directory, you ...

View answer
Are there pitfalls to putting $HOME in git instead of symlinking dotfiles?
14 votes

I wouldn't want my entire home directory checked into version control simply because it means every subdirectory I go into would have the version-control context of my home dir. Commands like git ...

View answer
What does `chown root.root $file` mean?
Accepted answer
11 votes

It sets the user and group of $file to root (as in chown OWNER.GROUP FILE...). It's the same as calling chown root:root $file, but an older form. The period was replaced by a colon, giving chown ...

View answer
Triple compression and I only save 1% in space?
11 votes

Most common image formats are already compressed (like jpg, png, gif), so you don't get much savings. 1% sounds about right. Adding more compression can actually make the result (slightly) larger, ...

View answer
read with history
Accepted answer
11 votes

You can use rlwrap for this, if you don't mind installing software. You'll probably want to keep a separate history file that only maintains history for the particular prompt in your script (ie. ...

View answer
Is it safe to resize partition on /?
Accepted answer
10 votes

If you are using /dev/sda1 as your current system root, you will be unable to unmount it, and doing so would prevent you from running parted from it anyway. resize2fs is able to enlarge ext3/4 ...

View answer
chmod recursive permission on thousands of files
Accepted answer
9 votes

chmod might or might not change the permissions of files that are already set to what you want, but if not, it would still need to check them to see what their current permissions are[0]. With ...

View answer
netcat in shell script giving invalid connection
Accepted answer
8 votes

Your original script requires that the connection comes from a host named localhost, but for some reason that filtering is failing. Unusual, because it matches exactly the name listed in the error: ...

View answer
Executable symbolic link file not working
Accepted answer
7 votes

Remove the \ from your ln command if you're using quotation marks: ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl (There was also a double / before bin, ...

View answer
How do you specify alternative script interpreters (shebangs)?
Accepted answer
7 votes

The short answer is that you can't. The idea behind using #!/usr/bin/env ruby instead of simply #!/usr/bin/ruby is to use whatever ruby binary is first in the user's path. Then your script doesn't ...

View answer
Search for a string in files recursively in BusyBox 1.0?
7 votes

I rolled this script that does a recursive pattern search from the current directory. It uses busybox's sh and sed. Tested with busybox 1.17.1; your mileage may vary on 1.00. #!/bin/busybox sh sed="...

View answer
How can I ensure my cronjob will run at specified time?
Accepted answer
6 votes

The only way to be sure is to let it run and inspect the results. You can modify your command to log the output somewhere and inspect that, or let it email you the output. You could add another ...

View answer
What is '"^[b" backward-word' When trying to configure ZSH?
5 votes

^ is usually control, but ^[ actually means Escape or Alt (or meta, if you like emacs). So you can press Escb or Escf for those key combinations. By default, Alt doesn't work on Mac terminals, but ...

View answer
Can I access X11's clipboard from tty1-6?
Accepted answer
5 votes

I don't have an X11 machine around so I can't verify this myself, but you might want to look at a program like xclip: xclip is a command line interface to the X11 clipboard. That won't exactly let ...

View answer
In bash, how can I erase an alias without logout?
5 votes

Use the unalias command: $ alias foo=ls $ foo ... ls output ... $ unalias foo $ foo bash: foo: command not found

View answer
creating a device image for a network location
Accepted answer
5 votes

Mount your network location with whichever protocol you're using: # smbfs example: mount -o username=your_hetzner_username //server.or.ip.addr/sharename /mnt/server-mountpoint Create an ext2fs image ...

View answer
When running to a run level does it execute previous run levels?
Accepted answer
4 votes

When you switch runlevel, the only things executed are the scripts in /etc/rc.d/rc${NEW_LEVEL}.d/. This means that you are right: Every rc*.d directory needs to be able to handle all of the process/...

View answer
Disown won't take -h option
4 votes

disown on its own is sufficient to let the program keep running after you disconnect: $ command_running_forever ^Z zsh: suspended command_running_forever $ bg [1] + continued ...

View answer
How to install LXDM instead of GDM3?
Accepted answer
4 votes

It looks like lxdm is not present in Debian wheezy; at least, it's not included in any packages according to the results of a package contents search. You may need to install it from source or from a ...

View answer