As Web-E explains the most direct way to do what you want with two different commands, I thought I'd show that there are a number of ways to execute multiple commands or to continue commands onto another line without immediately executing them.
Continuing long commands:
1) The most common way to construct one long command is to enter your commands, then use a backslash \
, press return, and then Bash will provide another prompt for you instead of executing the command. This secondary prompt is called PS2 and waits for your input:
find /home/mike/Downloads -type f -iname '*.jpg' \
>
You can keep on adding backslashes and pressing return as long as you want, as long as you think the overall command will make sense.
You can cancel this secondary prompt with the usual Ctrl+C.
2) Bash recognises some commands such as for loops (for i in....) and the prompt will appear immediately; just as it will if you miss a quotation mark off a command:
apt-cache search 'libgimp*
>
Multiple Commands:
3) As Lxnslck notes, you can separate commands with semicolons:
which vlc; whereis vlc
/usr/bin/vlc
vlc: /usr/bin/vlc /etc/vlc /usr/lib/vlc /usr/bin/X11/vlc /usr/share/vlc /usr/share/man/man1/vlc.1.gz
4) Or you can use the ampersand &&
to join two commands:
./configure && make
The . executable
syntax doesn't work with just any executable (or does it?). Instead, it's an alias for the bash source
built-in. So the difference is mostly relevant to bash scripts, and the truth is that they're completely different things :)
./executable
asks to run the executable "normally". ./
is a relative reference to the current path. This avoids having the shell (bash) try to locate the executable in a directory in its $PATH
(which it would do if you didn't specify a path at all with the command). The reason why you can't just do executable
is one of security; imagine you uncompress an archive you downloaded and it contains a malicious version of ls
. If it ran directly from your current directory, you'd run that version without realizing.
On the other hand, . executable
is saying "source a file named executable
". Since you're directly naming the file and it really doesn't have to be an executable, the security restriction for the $PATH doesn't apply. Sourcing will only "run" (or seem to run) shell scripts. What it does is:
source filename [arguments]
Read and execute commands from filename in the current shell
environment and return the exit status of the last command exe‐
cuted from filename.
So... What's really the difference between executing and sourcing? Assuming the same shell script, executing it (./script
) will spawn a new shell, run the script inside that shell, and when the script exits, close that shell and return to the parent shell. In effect, it will start a new bash
process to execute the script).
(. script
) will cause the current shell to read the commands from the file as if they were being typed in the command line. There's no new shell spawned.
A very easy way to see how this behaves is to write a script that only contains exit
. If you ./script
it, nothing will seem to happen, this is because a new shell process is started, the exit
command exits that new shell and your current shell is unaffected.
If you . script
, you current terminal will close, because the exit
command runs in the current shell. So it's equivalent to typing exit
on the command prompt.
Best Answer
Several things you could do.
1. Type a space in front of each command you run.
It's tedious, but putting a space in front of your commands will keep them from being saved to the bash history.
2. Set a Cronjob to delete .bash_history every hour
Your terminals historical commands are stored in
.bash_history
in your home directory. If you delete the file, it will effectively remove your history.First create the script to remove the
.bash_history
file:and add:
then run:
to make script executable and run:
and add
1 * * * * * /home/user/script.sh
.Then exit and save, and it should delete your history every hour.
3. Run
unset HISTFILE
, as @Carl suggested.Just run it before exiting the terminal, and it will not save those commands that you ran in the last session to
.bash_history
.