Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I saw someone use cd * and then use other commands like ls et al after that.
What does it do? Can someone explain it?
The shell expands * to an alphabetical list of the current directory's contents.
cd ignores all arguments after the first.
In lucky and/or extremely controlled circumstances, you can rely on the first item in the wildcard expansion to be the directory you want to cd into.
This may be marginally useful and/or entertaining if you have just created and descended into the current directory and populated it with a single subdirectory. I find it hard to imagine it could have other actual uses.
This command:
cd *
will only work if first list from current path is a directory since it expands to very first entry (file or directory) in the current path. You can see what comes first by doing echo *.
I would suggest not really relying on it since alphabetically first expansion can give you a file also like .bashrc or some other file name starting with dot.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed last year.
Improve this question
Why doesn't the command:
ls -ad /*
...show both hidden and non-hidden directories? And given this does not work, what would be the simplest command for showing hidden and non-hidden directories, without showing files?
Thanks!
/* is expanded by the shell before ls ever runs. The expansion only includes non-hidden files unless the dotglob option is set. Also, if you want the expansion limited to directories, use /*/ instead.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
Is it possible with bash (or maybe even zsh) to use a character other than the tilde ("~") do designate one's home directory? For example, "cd ~" takes you to your home directory. Hitting the shift key with my right pinky and then ~ key with my left pinky simultaneously has always seemed very awkward to me, particularly since it's a keystroke combination that's used so much. Is there another way to do this? I don't want to have to type $HOME all the time either. Ideally, I'd like to be able to use something more natural like shift+$ or shift+% instead of shift+~. Can this be done? By the way, I'm not looking for a shortcut such as "cd" to get back to my home directory. I want to make it easier to get to directories beneath my home directory.
Just use cd without arguments to go to the HOME directory.
See man bash
You can remap backtick ` to tilde ~ in Bash. With a US keyboard layout, this saves you a Shift:
bind '"`": "~"'
This only affects the shell prompt, and has the additional benefit of reminding you to always use $(..) over deprecated `..` for command substitution.
Several proposals that cannot work:
"shift+~" is just a symbol, not some weird metakey-combo!
"shift+%" gives a '%', which is already reserved for job
control
"shift+$" gives a '$', which is already reserved for variables and spawning child processes as in '$(cat blah)'
Some ideas that might work:
Instead of using $HOME, define $H in ~/.bashrc. That's only 2 characters, and $ is much less complicated to type
If it's your computer, you could create a symlink '/h' that points to your home directory, so that you could type /h/foo/bar instead of ~/foo/bar.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
Looking at the man pages for plain old ls I see there's a flag for -F
-F, --classify
append indicator (one of */=>#|) to entries
I've used it a few times, but all I see it adds a slash / to folders which is the same as ls -p
What does this mean for the others *=>#|?
I'm running Ubuntu 14.04 with GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Each of the symbols is for a specific type of file. If you haven't seen them, it's probably because you don't have any files of that type. The man page for ls should say what each of them means. But, in case you can't read yours for some reason, here's what mine says:
-F Display a slash (`/') immediately after each pathname that is a
directory, an asterisk (`*') after each that is executable, an at
sign (`#') after each symbolic link, a percent sign (`%') after
each whiteout, an equal sign (`=') after each socket, and a
vertical bar (`|') after each that is a FIFO.
Mine seems to use some characters yours doesn't and not use some that yours does. So, to resolve the others you need to read the man page that refers to your version.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
i'm very new to mac world, and i'm using bash doing some work.
But I'm not clear about the bash command line. It's so different from cmd.
yb_server:~ Aaron$
above is the command line when i start a terminal.
what's the meaning of yb_server?( I used to remember it's originally macintosh, why
it's changing to yb_server, how can i recover?)
what does ~ mean?
what does $ mean?
yb_server is your computer.
: is an arbitrary delimiter.
~ is your home directory (the current directory).
Aaron is you.
$ is "Speak to me, master!" But it is effectively an arbitrary delimiter.
The whole thing is your prompt. Google "bash prompt" for lots of info. Its format is totally up to you. Say echo $PS1 to find out what the format is now. The default is:
\h:\W \u\$
Learning what those symbols mean is left as an exercise for the reader!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Suppose I have these directories:
CSCI100
CSCI200
CSCI300
CSCI400
If I do
cd C<TAB>
it completes up to
cd CSCI
and then I must type a number to proceed.
Is there a way to do
cd 200<TAB>
which then alters the full command to
cd CSCI200
?
Bash's readline command "menu-complete" enables this behavior. You can either have this replace the Tab key's usual behavior (with the command bind "Tab: menu-complete", or by putting "Tab: menu-complete" in your .inputrc file), or choose a different keyboard shortcut for this function.
EDIT: Sorry, I misunderstood the question; it's about completing a suffix rather than a prefix of a filename. You can sort of do this with the default settings in bash if you use a wildcard and there's only one match for the pattern:
cd *200<TAB>
expands to:
cd CSCI200
If there's more than one match, it'll list matches if you TAB again. Binding TAB to menu-complete will make it cycle through matches instead. I don't know of any way to do this in bash without explicitly giving a wildcard to tell it where to do the expansion.