Taking command of the command line - 8
Changing directory
Changing around the different directory is what we always wanted to do most often.There are lot of cool way to do that other than cd lets have a look at them in details.
Cd command
First and for most the cd <directory-name> command will change the directory.
Same stands true on windows to just use cd<directory-name>.
Previous Directory.
For both windows and Unix-like system use cd .. to go back to the previous directory.
Returning back to the current directory.
It's more often people use cd .. to again. Na !! But using this you go off to the root. Of your system again its a bit far root to come along the directory we are in . Instead use cd - — cd <minus - > command return back to current directory you're previously in .
For ex: cd /<dir1>/<dir2>
Pwd
User/dir1/dir2:
By using cd - you’ll again bring back to the directory User as before this will help us whenever we have to move back and forth of a certain directory.
Moving forward in the directory - pushd and popd
This the quite a Bit of trick that will help us a lot when we are working on multiple directory and switch directory more often.
pushd /<dir1>/<dir2> pushd command will take you to the directory to which you wanted and store those trace of path as stored in the stack.
For example
There are multiple directory you have to change most often then use
pushd /<dir1> /<dir2>
Pwd
User/dir1/dir2:>
pushd /<dir3> /<dir4>
Will move you to dir3 to dir 4.
Pwd
User/dir1/dir2/dir3/dir4:>
Now if you want go back to the directory at which you are came from just use popd will give the last trace of the pushd this will get to the last trace what you made from pushd.
Here in the above eg if you use popd then you’ll be on the dir2.
popd
pwd
User/dir1/dir2:>
If you again use popd
popd
You’ll be in the home directory as before
Copying current directory pbcopy
It happens most often where we have to copy a certain file path and paste it to run certain task or navigate some directory through explorer or an finder to go to the certain path we tried to type the path by our hand missed numerously or try to use ctrl/Command + c . We all made those circus.
Its very easy to copy the file path or the command or the files in directory just using the command pbcopy which will copy to the clip board.and paste it where ever its is necessary.
For eg
1. pwd | pbcopy - will copy the current working directory.
1. pwd | pbcopy - will copy the current working directory.
2. ls | pdcopy - copy the files or the directory which are present in the respective directory give it a try .
Comments
Post a Comment