LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-30-2011, 11:37 PM   #1
azurvii
LQ Newbie
 
Registered: Mar 2006
Posts: 21

Rep: Reputation: 0
Other meanings of `~` (besides `home directory`) in bash


I don't think I'm a newbie anymore, but still sorry that if this is too basic to ask. I failed to find the answer using Google or LQ search. Since the `~` is shown in most PS1 variable, or just could not attract the attention from search engines simply because it's a symbol. And all pages I found introducing bash variables are telling that `~` is your home directory.

But I just came across expressions like
Quote:
~bin
~username
Those are definitely not as simple as `~/` means.

I tried
Code:
echo ~bin
/bin
and
Code:
echo ~backup/
/var/backups/
Can anyone tell me what's going on with `~`?

Big thanks
 
Old 01-31-2011, 12:10 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
No, nothing else. All it means is "home directory."

When you use it like so:
Code:
$ ls -l ~/
It means to list the contents of the home directory for the current user (you).

When you use it like this:
Code:
$ ls -l ~bin
It means to list the contents of the home directory of the user named "bin". This is just a shorthand to refer to another user's home directory.

If you execute this command:
Code:
cat /etc/passwd
I'm certain you will see entries for a user named "bin" and a user named "backup" -- special system accounts. You'll also see their home directories specified in the /etc/passwd output. It should be obvious from the output, but take a look at man passwd if you can't quite figure out the format of the passwd file.

Last edited by Dark_Helmet; 01-31-2011 at 12:11 AM. Reason: code tag typo
 
Old 01-31-2011, 12:21 AM   #3
azurvii
LQ Newbie
 
Registered: Mar 2006
Posts: 21

Original Poster
Rep: Reputation: 0
Ah, that makes sense.
And so i think this should work (if i'm in the sudoers )
Code:
cd ~Dark_Helmet
sudo touch thanks.txt
 
Old 01-31-2011, 12:25 AM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Indeed it would

You're quite welcome!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Home directory already exists. Please enter another home directory path." Daravon Ubuntu 2 02-15-2009 10:26 PM
Help with bash script to create directory to /home folder wegadnie Linux - General 5 10-25-2008 11:50 AM
contents of 'home' directory found at sda5: mounted as /home, and also on sda6:/home leswatson Linux - Newbie 4 04-18-2008 04:02 PM
bash - size of home directory klavuzkarga Linux - Newbie 9 12-17-2007 05:58 AM
Need to chroot bash users to thier home directory coloradopaul Linux - Security 1 09-16-2004 10:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration