Tagged Questions
86
votes
13answers
19k views
How to do integer & float calculations, in bash or other languages/frameworks?
Using echo "20+5" literally produces 20+5
What command can I use to get the actual sum, e.g. 25 in this case.
Also, what's the easiest way to do it just using bash for floating point, e.g.
echo ...
5
votes
3answers
2k views
Storing output of command in shell variable
I have an operation using cut that I would like to assign result to a variable
var4=ztemp.xml |cut -f1 -d '.'
I get the error:
ztemp.xml is not a command
The value of var4 never gets ...
5
votes
4answers
1k views
Make cd automatically ls
I find that I often do the following:
%> cd bla/bla
%> ls
I would like it that whenever I cd into a directory it automatically does an ls.
I fiddled with my .bashrc for a while, but couldn't ...
10
votes
1answer
259 views
Order of redirections
I don't quite understand how the computer reads this command.
cat file1 file2 1> file.txt 2>&1
If I understand, 2>&1 simply redirect Standard Error to Standard Output.
By that ...
48
votes
8answers
2k views
Remember a half-typed command while I check something
I often find myself in the following position: I've started typing a long command at the bash prompt, but half-way through I find out I need to check something with another command. This is a problem ...
51
votes
10answers
7k views
How to grep a specific line _and_ the first line of a file?
Assuming a simple grep such as:
$ psa aux | grep someApp
1000 11634 51.2 0.1 32824 9112 pts/1 SN+ 13:24 7:49 someApp
This provides much information, but as the first line of the ps ...
22
votes
4answers
1k views
Is there a one-liner that allows me to create a directory and move into it at the same time?
I find myself repeating a lot of:
mkdir longtitleproject
cd longtitleproject
Is there a way of doing it in one line without repeating the directory name? I'm on bash here.
13
votes
6answers
32k views
How do I make my pc speaker beep
Using bash, how can I make the pc speaker beep?
Something like echo 'beepsound' > /dev/pcspkr would be nice.
7
votes
3answers
527 views
How to pipe the list of commands displayed by of “tab complete”?
When using commands in bash I like the double tab option to display the available commands. Some commands have more possible matches than others:
Is there a way I can pipe the output of the double ...
11
votes
4answers
2k views
how to glob every hidden file except current and parent directory
I want to glob every hidden file and directory, but not the current (.) and parent directory (..).
I am using bash.
Observe current behaviour:
$ ls -a
. .. ...a ...aa ..a ..aa .a .aa .aaa ...
7
votes
4answers
625 views
What is the easiest way to execute text from tail at the command line?
Sometimes I'm working on a new (ubuntu) box and I type git and am alerted:
The program 'git' is currently not installed. You can install it by typing:
apt-get install git-core
If that happens I ...
4
votes
3answers
1k views
How can I expand a relative path at the command line, with tab completion?
In bash is there any way to expand a relative path into an absolute path, perhaps with tab completion?
I ask because sometimes I will search for a file, find it, then vim it:
cd /etc
cd apache2
cd ...
24
votes
3answers
2k views
Why shouldn't someone use passwords in the command line?
Why do people fear writing passwords in the command line?
The history file is located in ~/.history, so it's available only to the user who executed the commands (and root).
10
votes
2answers
429 views
Highlight the three last updated files in ls output
Is there any way to overload or wrap the ls command so that it will highlight / underline / otherwise make obvious the last three modified files?
I know that I can simply ls -rtl to order by reverse ...
12
votes
6answers
1k views
put history command onto command line without executing it
I use !n where (n) is the line number for executing a line in the history file I want executed at the command prompt which I find via history|less.
But there is a command line history event I wish ...