how to change directory using Windows command line
The "cd" command changes the directory, but not what drive you are working with. So when you go "cd d:\temp", you are changing the D drive's directory to temp, but staying in the C drive.
Execute these two commands:
D:
cd temp
That will get you the results you want.
One command to create a directory and file inside it linux command
mkdir B && touch B/myfile.txt
Alternatively, create a function:
mkfile() { mkdir -p -- "$1" && touch -- "$1"/"$2" }
Execute it with 2 arguments: path to create and filename. Saying:
mkfile B/C/D myfile.txt
would create the file myfile.txt
in the directory B/C/D
.
Create directory and files with one command
I recommend -p
.
qc() { local p="$1";
if [[ -n "$p" ]];
then mkdir -p "$p" # can be any full or relative path;
else echo "Use: qc <dirpath> [f1[..fN]]"; return 1;
fi;
shift;
for f; do touch "$p/$f"; done;
}
$: qc
Use: qc <dirpath> [f1[..fN]]
$: cd /tmp
$: qc a/b/c 5 4 3 2 1 # relative path
$: qc a/b # no files; dir already exists; no problem
$: qc /tmp/a/b/c/d 3 2 1 # full path that partially exists
$: find a # all ok
a
a/b
a/b/c
a/b/c/1
a/b/c/2
a/b/c/3
a/b/c/4
a/b/c/5
a/b/c/d
a/b/c/d/1
a/b/c/d/2
a/b/c/d/3
use cmd.exe to change directory and run command in that directory
You may want to invoke CD with the /d option, thus not only changing the current directory on drive c: but also going there (in case you are not already on that drive).
cmd /c "cd /d c:\temp && dir"
How to change folder with git bash?
The command is:
cd /c/project/
Tip:
Use the pwd
command to see which path you are currently in, handy when you did a right-click "Git Bash here..."
How to mkdir and switch to new directory in one line
The portable way to do this is with a shell function--not a bash function (using bashims like function
). Put this in the relevant .profile
for interactive use:
mkdir () {
case $1 in
(-c) command mkdir -p "$2" && cd "$2";;
(*) command mkdir "$@";;
esac
}
This adds the -c
option to mkdir
for interactive use. Without -c
the utility acts as it always does.- And note the quoting of "$2"
so this works with directories with white space in their name.
execute a subcommand in a different directory as the current one in fish?
Right, many of us coming from Posix shells like bash
or zsh
are used to being able to run a command substitution like this using $()
or just backticks and leave the parent shell environment untouched. It's a nice trick, IMHO.
On the other hand, fish
doesn't automatically create a subshell when using its command substitution operator ()
. There's a feature request here for that, but the workaround (as suggested there) is fairly straightforward -- Just explicitly create a subshell inside the command substitution. E.g.:
mv (fish -c 'cd ~/Downloads; ls -t | head -1 | xargs -I {} readlink -f {}') ./
The downside is that syntax highlighting/checking doesn't work in the quoted text, and quoting/escaping rules get more complicated.
Related Topics
Colors with Unix Command "Watch"
How to Read a .Properties File Which Contains Keys That Have a Period Character Using Shell Script
What Is a Sysroot Exactly and How to Create One
Is There an Equivalent to Com on *Nix Systems ? If Not, What Was the *Nix Approach to Re-Usability
Loading Multiple Shared Libraries with Different Versions
How to Specify Filenames Within a Zip When Creating It on the Command Line from a Pipe
How to Tell Whether I'm in a Screen
Linux's Thread Local Storage Implementation
Which Signal Does Ctrl-X Send When Used in a Terminal
Why Do We Need a Swapper Task in Linux
Call a Kernel Module Function from Program at User Space
Update-Alternatives: Warning: /Etc/Alternatives/Java Is Dangling
How Set Multiple Env Variables for a Bash Command
Exclude List of Files from Find
How to Sleep for 1 Second Between Each Xargs Command