My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

Thursday, November 14, 2019

How to show full working directory in mac terminal on every command


Problem description:
You can obviously use a pwd command to see the present working directory. For eg:

prompt$ pwd
/Users/mfaiz/myDir

But sometimes you want to show the full directory path every time. Its a common ask for eg:
/Users/mfaiz/myDir$ pwd


Or, better still you want the directory path to be displayed on top before each command. All such issues can be handled using your bash profile file:


vi ~/.bash_profile


Solution: 
You can add this line -
export PS1='\u@\H:\w$'

or, if you like having a space between the $ and the command, then - 
export PS1='\u@\H:\w$ '



Shown following are two more complex examples that include coloring as well:




Command used to achieve this is:

export PS1="\n$C_LIGHTGREEN\u$C_DARKGRAY@$C_BLUE\h $C_DARKGRAY: $C_LIGHTYELLOW\w\n$C_DARKGRAY\$$C_DEFAULT "




Thursday, November 23, 2017

How can I open a cmd window in a specific location on Windows

Hi,

This hack will help you in many ways. And, shall help you many ways too!
This is a part of my initiative to post simple tricks aimed to Help/ease a QA Day to day life. These Tech Hacks are very handy but increase your efficiency much.

So, for our case today - How can I open a cmd window in a specific location on Windows; I provide two methods:

Trick 1:

If the folder is opened.
Click on address bar, alternatively press Alt+D
Now when address bar is highlighted, type cmd in the bar.
Press Enter key
You will notice that command prompt from that folder



Trick 2:

In the folder. Press Shift and then Right Click

A option appears -> Open Command Window here.


Press that. It will open a command window with present working directory as the selected hotel

Tuesday, July 24, 2012

Enable SSH Root Login Solaris 10

I was in a big trouble as I was not able to ssh to a Solaris 10 machine. More specifically, Solaris 10 was running in a VM. But that essentially, has no effect on my problem. I was not able to transfer files in my network with this newly up system, Solaris.


I was able to ping to and forth with another machine and Solaris, but SSH was not happening. No, was telnet happening. An hour of struggle led me to a good solution. And it was quite easy. You are lucky to find this solution directly! Huh..


Steps:

Open and change the file /etc/ssh/sshd_config. Find string "PermitRootLogin no" and replace "no" with "yes"

Then, restart the services as follows:
#svcadm restart ssh
#svcadm restart svc:/network/ssh:default

Now try to SSH to this machine again.
Yes, its Done!!

Wednesday, July 6, 2011

Terminal (Shell) on Mac OSX or Unix continues to show a folder even if it is deleted or renamed

I have logged this defect with Apple. But since then I have only been told it is legacy Unix behavior. And Unix is supposed to behave that way. In any case, I find it valuable to share this now.

-------------------------------------------------------------
This is already present on Apple Website since 19th March 2010 and has one response in addition to the emails. Read Further Apple Mac OSX Bug By Anwar Faiz.
-------------------------------------------------------------
Make a folder, let us say "xyz" on desktop and cd to this location on a terminal using 'cd' command.
Now rename that folder to "abc".
Now type 'ls' command on Terminal to see the content of folder "xyz", it still shows.
In addition if you use 'pwd' command, it still shows that you are in directory "xyz"
Worse is that even if you delete the folder "xyz" and empty trash. Even then using 'pwd' command would show your present working directory as "xyz" folder.
--------------------------------------------------------------


I got a detailed response for this. The same can be read over at same Apple Official website also. I am thankful to Mr. Bob Harris from New England, USA, who took time to explain.:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All expected behavior.

The 'cd' command makes a chdir() system service call, which opens the target directory and stores the open file descriptor in the process.

When you rename the folder, that just changes the directory entry in its parent folder, it does not change the file system inode for the directory nor does it affect already open file descriptors to the directory.

So when you do an 'ls' with no path, the 'ls' command will ask the file system for the '.' (current directory), which the file systems knows to use the current working directory it already has saved in the process.

This is how Unix has worked forever.

'cd' and 'pwd' are bash built-in commands, so bash has cached the last 'cd' path, and when you issue 'pwd', bash just echos the cached path information. It does not verify anything before displaying the path.

If you want to see the real current path, then try using

/bin/pwd

this will do the more complex reverse path reconstruction, which can have some unexpected responses, because of symbolic and hard links that may have been used to navigate down to the current directory location.
Worse is that even if you delete the folder "xyz" and empty trash. Even then using 'pwd' command would show your present working directory as "xyz" folder.

Again, bash is just echoing the cached path that bash last knew about.

Also since the process still has an open file descriptor to the directory open in the process as the current working directory, the file system will defer the actual directory delete until after that file descriptor is closed.

The fact that a file or directory will not be truely deleted if it is still open, allows an application to continue to use a file if it has it open, even when some other process deletes the file. This can be good for the application, but if that was a huge file and you were trying to free up space, you would not see the space returned until after the process that has the file open, closes the file.

You can use the 'lsof' command to find what processes have what files/directories open.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In addition, it was advised that, if I have additional Unix or Terminal related questions it would be best to post them in the Mac OS X Technologies > Unix Forum. So, one place where you can also redirect yourself for taking other unix Vodka Shots is Apple Unix Discussions

Thursday, February 17, 2011

Unix Commands related to Handling files

Without an introductory speech let me come directly to the point.
Listing files in a directory

ls
list the files in the current directory
ls -a
list ALL files, even ones which begin with a dot, which are normally omitted
ls -s
list files, with their sizes
ls -l
list files, giving full details about each file
ls -al mydir/
list all files in directory mydir (including those beginning with a dot), giving full details about each file
ls *.c
list the files which end ".c"
ls mydir/
list the files in directory mydir


Moving or renaming files (IMHO please consider both the same if you are on Unix flavored OS or on Mac)
Examples:
mv oldname newname
rename a file
mv myfile mydir
move a file into another directory
mv myfile1 myfile2 myfile3 mydir
move several files into another directory


To Copy files
Examples:
cp oldname newname
make a copy of a file
cp myfile mydir
make a copy of a file in another directory
cp myfile1 myfile2 myfile3 mydir
make a copy of several files in another directory


To Delete files
Examples:
rm file...
delete the specified files
rm -i file...
ask for confirmation before deletion
rm -f file...
don't ask for confirmation before deletion. BE CAREFUL!
rm -r directory
Delete directory and everything in it. BE CAREFUL! To remove empty directories, see rmdir
rm -rf directory
Delete directory and everything in it, without asking for confirmation. Hey man its not the magic. Actually –rf tells the OS to suppress asking for confirmation. Actually there is never a magic in Software Arena. It’s all how deeper you go, and how diversified the developers approached to a problem. But defects/bug usually come as a magic!! (Some say, if you understand a woman, it is a magic in itself. Have I understood my Girlfriend and would be wife yet!!!!)


You can write me at toughjamy@yahoo.com.
To Know me professionally visit ..Linked In..
You can befriend me at ..FaceBook..
Read jokes at ..Jokes Limitless..
You can also know more about me at ToughJamy : An Informal Me!!