-1

If I'm in another folder, how do I run a command like wget to download in ~ /home/user folder with name it has already?

So that in since we dont know user home name is it /root or is it /home/user1 or /home/user2

Like

wget www.website.com/.tmux.conf -O ~
muru
  • 72,889
  • How to make this not a duplicate? There is written to make in some folder. Here question is about home/username folder – Kangarooo Mar 26 '21 at 19:52
  • 1
    The directory ~user2 is the home directory of user2, the directory ~root is the home directory of root. Then apply the solution for the duplicate to save in the correct directory. – Kusalananda Mar 26 '21 at 20:46
  • @Kusalananda how to write script code command for every username in world? – Kangarooo Mar 29 '21 at 08:42
  • Why would that be necessary? I feel that you may want to update your question a bit to clarify what it is you want to do. In the current question, you say that you don't know the user's home directory. Given a username, "user", the home directory for that user is ~user. If you have further issues about this, then you must update your question to clarify what it is that you don't currently understand. It's also unclera, currently, who is running the wget command. Is it one of the users? If so, the home directory of that user is ~ or $HOME as Artem says in their answer. – Kusalananda Mar 29 '21 at 08:50

1 Answers1

3

-P prefix --directory-prefix=prefix Set directory prefix to prefix. The directory prefix is the directory where all other files and subdirectories will be saved to, i.e. the top of the retrieval tree. The default is . (the current directory).

This should work:

wget -P ~ URL

or $HOME instead of ~

  • 2
    Applications don't need to know about ~. In fact, they know as much about $HOME as they do about ~. Both of these are expanded by the shell before calling the application which is why wget -P ~ URL works just as well as wget -P "$HOME" URL. In both cases, what is actually run is wget -P /home/username since both the ~ and $HOME are expanded before calling wget. – terdon Mar 14 '21 at 17:37
  • You're right but I've always avoided using ~ in scripts - don't know why. I'm not sure it works in scripts, does it? @terdon – Artem S. Tashkinov Mar 14 '21 at 17:55
  • You know, I think you're right and there are some weird edge cases where ~ doesn't work, but I can't find one now. It works as expected in a script (I just had cd ~/foo; pwd; cd~; pwd in a script and confirmed it works with bash, dash, sh, csh and tcsh). So while I also have this vague recollection that it doesn't work in certain contexts, I can't remember where and scripts are not one of them. – terdon Mar 14 '21 at 18:26