Hot answers tagged command-line
7
Depending on how the terminal is configured, typing Alt+Key is like typing the Esc and Key keys in sequence, so it sends the ESC character (aka \e or ^[ or \033) followed by the character or sequence of characters sent upon pressing that Key.
Upon pressing Up, most terminal emulators send either the three characters \033[A or \033OA depending on whether ...
5
If the shell is zsh or bash (though not in sh mode), make exit a function. Functions have precedence over shell builtins (even special ones like exit) in zsh or bash (though not in POSIX shells). So just rename your function to exit and use command exit within the function instead. Otherwise you had endless recursion, of course.
5
This feature makes reading the output of grep easier. If you want to check data that grep cannot read directly then you may end up using a pipe to feed grep instead of creating a temporary file which grep can read. If you don't want a temporary file (e.g. because it would be huge) then without --label you would have the problem that grep cannot print the ...
4
Lots of programs send output to stderr that isn't actually indicative of errors. For example, in some programs it is used to display information that would otherwise affect the output of the program (which is designed to be piped into another program). You can, however, do this:
exec 2>/dev/null
I wouldn't recommend doing this outside of a script.
3
I found this python script called smpdf that has this feature. This script is written in German (some of it) but it's easy enough to figure out what it's doing and how to use it. It requires PyPdf.
Installation & Setup
First download the script:
svn checkout http://smpdf.googlecode.com/svn/trunk/ smpdf
Then download & install PyPdf:
wget ...
3
I don't think that's true. The shell is the one interpreting the command line arguments and passing them to the corresponding commands as it (the shell) is parsing them.
So your C program, when it finally get's executed will only see the arguments 1, 2, and 3. The pipe and everything after is the responsibility of the shell, and will not get passed in as ...
3
( mysqldump --opt --databases $dbname1 --host=$dbhost1 --user=$dbuser1 --password=$dbpass1; \
mysqldump --opt --databases $dbname2 --host=$dbhost1 --user=$dbuser1 --password=$dbpass1; \
mysqldump --opt --databases $dbname3 --host=$dbhost2 --user=$dbuser2 --password=$dbpass2; \
mysqldump --opt --databases $dbname4 --host=$dbhost2 --user=$dbuser2 ...
3
If you want to detach the process from the current shell rather than starting it as a background job with xdg-open http://www.google.com &, I like the detach utility:
detach xdg-open http://www.google.com
One could create an alias for this. I like detach over nohup as closes stdin stdout and stderr by default so its invocation is cleaner.
3
Potential solution #1
Use the timeout command:
$ date
Mon May 6 07:35:07 EDT 2013
$ timeout 5 sleep 100
$ date
Mon May 6 07:35:14 EDT 2013
You can put a guard into the timeout command as well to kill the process if it hasn't stopped after some period of time too.
$ date
Mon May 6 07:40:40 EDT 2013
$ timeout -k 20 5 sleep 100
$ date
Mon May 6 ...
3
You can use Crtl+v to return input codes of your keyboard. If you do that for arrow keys, you will get [[D^, [[C^, [[A^, and [[B values. There aren't any default bindings for Alt+arrow keys, so it seems that performed action is printing letter code alone. Hovewer, if you create your local version of readline library configuration file:
$ cp /etc/inputrc ...
3
Something like
compile && { test -f /path/to/dont_run || run; }
should solve your problem. touch /path/to/dont_run would prevent run from being executed. You can make this more complicated (and more convenient) by e.g. defining a shell function cond_run_cmd which does some check like that, limited to its tty (so that you can have several in ...
2
You could do:
eval paste '<(sort -n ../data/file-'{A,B,C}'.dat)'
Or to automate it as a function
sort_paste() {
local n i cmd
n=1 cmd=paste
for i do
cmd="$cmd <(sort -n -- \"\${$n}\")"
n=$(($n + 1))
done
eval "$cmd"
}
sort_paste ../data/file-{A,B,C}.dat
(in some ksh implementations, you need to replace local with typeset)
To ...
2
It depends on whether the disk image is a full disk image, or just a partition.
Washing the partition(s)
If the disk is in good working condition, you will get better compression if you wash the empty space on the disk with zeros. If the disk is failing, skip this step.
If you're imaging an entire disk then you will want to wash each of the partitions on ...
2
Do not use kill -9 if not absolutely necessary, and most of the time it is not absolutely necessary. Always try kill (without -9) first. See here for more explanation.
I think that your "trouble" killing firefox is a direct result of your kill -9 (or pkill -9). Firefox maintains lockfiles in the profile directory. The lockfiles are there to prevent two ...
2
TTY framebuffer console has no way to have more than 8-16 colors without kernel hacking, see this quote: "Although the Linux frame-buffer supports 256 (or more) colors, the Linux console driver does not; therefore, console applications are still limited to 16 colors on the Linux console, frame-buffer or not."
So you can have no more than 16 or 8 colors. ...
2
Portably:
sed -e 's/.*/ & /' -e :1 -e 's/ test3 / /g;t1' -e 's/^ //;s/ $//'
That is:
first add a space at the beginning and end of the line, to not have to consider test3 at the beginning and end specially,
replace test3 enclosed in spaces with a single space,
repeat the process as long as there are substitutions (to cover the test3 test3 cases).
...
2
I'd look for test3 wrapped with a space on either side, \s, given your example rather than try and use the word boundary notation.
For example
$ echo "test3.legacy test4.legacy test3 test3.kami" | sed 's/\stest3\s/ /g'
test3.legacy test4.legacy test3.kami
The above looks for space test3 space and replaces this with just a space.
NOTE: This won't handle ...
2
Is this what you want?
$ sed 's/\(^\| \)test3\( \|$\)/\1/g' file
test3.legacy test4.legacy test3.kami
This say
substitute
(^ start of line OR space)
test3
(space OR end of line)
with match 1 (AKA space or start of line)
Update:
And as so elegantly put by the good @Stephane Chazelas this would not take care of certain cases. Also emphasize ...
2
I don't believe this information is kept anywhere. They only place you could get some of this type of information would be from the sudo command logs, assuming you're using sudo and that your sudo setup gives out permissions such that you're logging on individual commands such as passwd.
I've used this command before to show what accounts are locked,i.e. ...
2
Strange, it works like that out of the box on my Debian. Try running it in the background:
xdg-open http://www.google.com &
You can make this into a function by adding these lines to your ~/.bashrc file:
function open () {
xdg-open $1 &
}
You can then simply run open http://www.google.com and it will run in the background.
2
In your comment to @tink's answer you want seperate files in the .gz files:
mysqldump --opt --databases $dbname1 --host=$dbhost1 --user=$dbuser1 --password=$dbpass1 > '/var/tmp/$dbhost1.$dbname1.sql' ; mysqldump --opt --databases $dbname2 --host=$dbhost1 --user=$dbuser1 --password=$dbpass1 > '/var/tmp/$dbhost1.$dbname2.sql' ; mysqldump --opt ...
1
It is a good starting point, but "generally" needs to be emphasized. For utility commands it is always a good idea to read the man utility page for what is correct syntax.
There is a guideline at The Open Group that can be worth a read. However there is varying level of how conforming implementations are. Some implementations allow one to break this ...
1
pdftk does not have such an option. But you can burst the complete file in single pages and combine sets of these pages until you would go over 5Mb.
There would be a little error margin as a single page PDF has some overhead compared to the combined ones (resulting in chunks that could have had one more page before going over the 5Mb). But with an average ...
1
One quick way to do it (if you dont care to take an IV + key and send it through RC4) is:
i=1
while [ $i -le 4 ]
do
dd if=/dev/random bs=1 count=16 2>/dev/null | xxd -ps
i=$(( i+1 ))
done
This will generate four 128-bit wep keys. Adjust count for different strengths
1
xdg-open waits for the program to finish. This is by design. If the program is a text mode program, it has to stay in the foreground in the terminal. Even if the program is a GUI one, this behavior is useful in case xdg-open is used from a script and the script wants to perform something after the file has been edited (e.g. send the new version somewhere or ...
1
Try out this bash function in the console. Fittingly, it doesn't work in an X terminal (I think because of the tabs). Especially check out the three files used last, namely
/sys/module/vt/parameters/default_red
/sys/module/vt/parameters/default_grn
/sys/module/vt/parameters/default_blu
clr () {
clear # GFX bug otherwise
setterm -regtabs 4
...
1
Please see here, why eval can be dangerous to use. As you'll notice, it is a very powerful tool, but at the same time can cause a lot of damage.
The following script will do what you want - safely.
sort_ps ()
{
local cmd="$1" p=()
shift;
for f in "$@"; do
p+=(<(sort -n "$f"));
done
"$cmd" "${p[@]}"
}
EDIT: Mr. Chazelas is ...
1
All solutions that divide by four fail, for instance November:
% echo $(( 11/4+1 ))
3
The correct math would be:
$(( (m-1)/3 +1 ))
And as such, the quarter of current and previous month would be:
echo curr ${y}q$(((m-1)/3+1))
if [ $m = 1 ]; then
echo prev $((y-1))q4
else
echo prev ${y}q$(((m-2)/3+1))
fi
It's only twelve values to check, really…
...
Only top voted, non community-wiki answers of a minimum length are eligible






