How do I go back to home directory prompt if I entered some random command?

Screen Link: Learn data science with Python and R projects

By error I entered this command:

cd `

And now I have this prompt instead if the home directory prompt:

> 

I tried entering cd in the prompt but it does nothing.
What did I do and how do I revert it?
Thanks in advance!

PS: I resolved it with ‘control+Z’ hotkey, but I would still like to know what happened.

Hi @daryaholodova:

You can navigate back to the home directory with cd ~ (Shift + key below Esc on a US keyboard) is its a bash prompt (i.e. you see the $). cd without any specified arguments behind has no effect, as you mentioned. In cases where another prompt appears due to a typo, you can press Ctrl+C to get back to the main bash prompt. Hope this helps!

In Bash, backticks (`) have a special function. What is between the backticks is executed and its output is passed as an argument to the command that precedes it.

Here’s an example.

We start off with an empty directory:

work:/mnt/1TB_TOSHIBA/playground/darya$ ls

(No output, hence the directory is empty — well, it at least doesn’t have empty files, but we’ll be ignoring those year without any loss of explainability).

We now create a few files:

work:/mnt/1TB_TOSHIBA/playground/darya$ touch data_202111 data_202112 data_202201
work:/mnt/1TB_TOSHIBA/playground/darya$ ls
data_202111  data_202112  data_202201

Running echo *2021* should output all 2021 files:

work:/mnt/1TB_TOSHIBA/playground/darya$ echo *2021*
data_202111 data_202112

Let’s delete them by running the above command in-between backticks and placing it after rm:

work:/mnt/1TB_TOSHIBA/playground/darya$ rm `echo *2021*`

And now we verify it worked:

work:/mnt/1TB_TOSHIBA/playground/darya$ ls
data_202201

So what happened was that when the shell was parsing the command, it never encountered the closing backtick and so it prompted you for it.

2 Likes

Thank you for such a a detailed explanation, Bruno!
I get it now!

Thank you for your answer, masterryan!
I actually have been using cd without arguments to go back to home directory, so, it has been working fine for me. My question was more about incomplete or wrong commands, because that is what the backtick happened to be in this case.