Terminal (Shell) continues to show a folder even if it is deleted/ renamed

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.

All expected behavior.
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.
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.
In addition if you use 'pwd' command, it still shows that you are in directory "xyz"
'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 the future, if you have additional Unix or Terminal related questions it would be best to post them in the Mac OS X Technologies > Unix Forum
<http://discussions.apple.com/forum.jspa?forumID=735>

Similar Messages

  • ICloud continues to show open tabs even after Safari quit

    Since OS 10.10, when I close and quit Safari on my iMac or MBP iCloud occasionally continues to show an open tab on the other devices like the iPhone, even for several hours after Safari has been quit on the iMac. This is annoying in that one time I left it, and the iMac restarted because of a kernel panic.
    This appears to be an iCloud and Yosemite problem. Furthermore, I have called Apple care twice about this, and they have been unable to find any problem with my computers.
    Has anyone else had this problem, and what to do about it.

    Try clearing Safari's cache : Settings > Safari > Clear Cache (and Clear History)

  • I am using Yosemite.  I have spam e-mail showing up continuously in my junk folder.  (same ones I deleted)  What can I do to resolve this matter?

    I have an i-mac and using Yosemite.  (1) spam e-mails keep returning after being deleted.
                                                                (2) my canon P-208 document scanner will not perform.  Canon does not have a compatible driver on their site.
    How can I resolve these issues?

    The scanner works fine with mountain lion but when downloaded yosemite it opens but will not continue to perform -- cuts out. yosemite is  10.10.  believe the scanner is 10.7.

  • My iphone 6 keeps showing 0 bytes even though I keep deleting items. How do I fix this?

    I have done a restore. I delete items and for a short amount of time I will have a little space and then it eats it up. I had 2.3gigs last night before bed to awake to a full memory alert in the morning.
    I counted my used space and it's only about 20gigs on a 64gig iphone6.

    Have you tried doing the backup to itunes instead of icloud?

  • Chromium "show in folder" - how to use a terminal file manager?

    I am trying to get the Chromium download manager's "Show in folder" button to launch a terminal and run Ranger. I have created the file
    /usr/share/applications/ranger.desktop
    with the following contents:
    [Desktop Entry]
    Type=Application
    Name=Ranger
    Exec="xterm -e /usr/bin/ranger %f"
    Terminal=true
    and done the association with
    xdg-mime default ranger.desktop inode/directory
    This works, but only if I have launched Chromium from a terminal. If I launch it from dmenu, nothing happens when I click on "Show in folder".
    Is there any way to get it to work?
    Last edited by meanerelk (2012-05-18 20:49:07)

    Try removing the quotation marks in the desktop file.
    Exec=xterm -e /usr/bin/ranger %f
    Last edited by irishninja (2013-12-14 17:26:24)

  • My canon sx120IS continues to show low batter and shuts off even after changing the batteries.

    My canon sx120 is  continues to show low battery and shuts off even after changing the batteries.  Any suggestions? Do I need to send it for repair somewhere, and if so, where?

    Hi LB!
    Thank you for posting on our forum!
    Try cleaning the electrical contacts on the camera and the batteries using a soft microfiber cleaning cloth.  If the same warning still displays, then the camera will need to be serviced.  To start the repair process, you'll need to complete a Repair Request on our website.
    If the camera is more than a year old, you may participate in the Canon Loyalty Program instead.  The Canon Loyalty Program option allows you to replace your current camera for a discounted fee, plus shipping.  The original non-functioning camera would then be returned to Canon USA for recycling using a prepaid shipping label that would be provided.  
    If you would like to take part in this option, please call our Sales Department at (800) OK CANON (800-652-2666) seven days a week, 8am to Midnight.  Let them know you have been working with online support and the Canon Loyalty Program was offered.  Be sure to have your serial number for your camera at the time of your call.
    Did this answer your question? Please click the Accept as Solution button so that others may find the answer as well.

  • Continue to show headsets pluged in even when they...

    my nokia x202 continue to show headsets pluged in even when they are unpluged from the device.
    Moderator's notes: The post was edited. A more appropriate subject is provided.

    Hi musaka
    Thank you for posting and welcome to Nokia Support Discussions! 
    Here are simple things that you can try:
    Restart your phone
    1. Switch your phone off
    2. Remove the battery. 
    3. After a few seconds, put the battery in and switch your phone on.
    Reset the settings
    Restore the original factory settings of your phone. Go to Menu > Settings > Restore factory settings > Settings only. If prompted for a security/lock code enter 12345 unless changed. This will not delete any data on your phone but any personalization you've made will reset back to default.
    If my post helped you, please don't forget to click on the "White Star" and if it resolved your issue click on "Accept as Solution"

  • IPhone 4S..unable to turn cellular off in IOS6..continues to show verizon even though cellular turned off in settings

    iPhone 4S..unable to turn cellular off in IOS6..continues to show verizon even though cellular turned off in settings

    Thanks .. Your feedback helped:)

  • Trying to make double clickable Terminal Shell Script - total Novice here

    Short version: How do I make a text file of terminal commands executable?
    Backgound: I am running OS 10.4.11 and the shell that runs under terminal is Bash. I know almost nothing about Unix and scripts and such, so don't assume anything when giving instructions.
    Long Version: I have a terminal program I found called jhead where my only need for it is its ability to change the exif's "orientation" tag in photos. I already figured out how to get jhead into my /usr/bin directory so it is executable from any directory in Terminal.
    So here is the command I run in terminal simply to check the orientation tag of all the photos in my photo work directory:
    jhead -v ~/Desktop/temp\ Photos/*.jpg | grep -i orien
    All it does is reads the exif info for the photos but filtered to only show the orientation tag. These photos are in the folder "temp Photos" on my desktop. So it works fine.
    I read that to make a simple terminal shell script you can make a simple text document, add the extension .command and now you can double click it and it will run any commands in Terminal. I used text edit to create a plain text blank file in that folder. I then used pico in terminal to put the command into the file and saved it.
    The file has the right icon, but when I double click it I get this error:
    The .command file ‘/Users/Dad/Desktop/temp Photos/orientation_normal.command’ could not open. Most likely it is not executable.
    and then when I ok out of that error box, Terminal opens and that is about it.
    Assistance?
    Thanks,
    Patrick
    p.s. I want to add a couple more lines to the script so the script will first check the status of all files, change them all, then recheck them. I can then eye ball the terminal window and make sure everything looks correct. But for now I am starting with just the single command to first prove I can make a double-clickable script.

    D'oh. So easy. I had used that command on the program files itself, jhead, but it never even occurred to me to use it on the .command text file.
    I got the script working and fleshed it out with the other commands and now it does all the fixing of all the photos in the folder with one double-click. Super!
    Thanks!
    Patrick

  • When I open logic express 8 with eyetv open but not active and i close logic express 8 and make eyetv active it won't show closed captioning even though closed captioning is turned on

    when I open logic express 8 with eyetv open but not active and i close logic express 8 and make eyetv active eyetv won't show closed captioning even though closed captioning is turned on.  When I totally close eyetv and reopen eyetv and open a live tv window the closed captioning comes back.  I never noticed this with os leopard, Just after i installed os snow leopard.  All software is up to date only I think, thanks to apple they droped support for logic express.  Thanks for any suggestions.

    Does toggling CC off & back on bring it back?
    "Try Disk Utility
    1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
    *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
    3. Click the First Aid tab.
    4. Select your Mac OS X volume.
    5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214
    Then try a Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes.
    (Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.)
    If perchance you can't find your install Disc, at least try it from the Safe Boot part onward.

  • Printer properties continue to show HP photo paper, despite Preferences being set for Automatic.

    Yesterday, while attempting to print a Word Perfect 5 document (my word processing app), the printer( HP Office Jet 6500 E709) operated, passed the paper through and made the printing sounds, but no ink was applied to the paper.  I thought perhaps the cartridge had run dry, although I usually get a warning and then can visually see from the finished print job when the ink cartridge is empty.  My PC is running Win XP Professional, and the printer has never been a problem.  I installed a new Black cartridge and successfully printed off a test page.  Still could not print the WP document, or any other document from "my documents" file.  Tried the "copy" function and the printer worked fine.  Still no document printing.  Printed a Yahoo e-mail using the "print" option at the top of the message, and the printer worked fine.  When printing from that icon, I got a pop-up display with a menu option labeled "preferences."  This is the standard routine when printing an e-mail. I clicked on preferences saw that they were set at automatic, portrait, and color.  I changed color to Gray Scale, black ink only, and the page printed properly.  This has always been the routine, whether printing an e-mail of printing a document.  Then I went to my WP document and hit the printer icon on my task bar and got a different pop- up display.  In this display there was no "preferences" option, only a "properties" option.  When I pressed that button I saw a setting that said HP Photo paper, portrait, grayscale high quality.  I changed the paper type[ to "automatic" but cold not change the color option to black ink only.  I closed the menu and attempted to print.  No ink.  I repeated the steps and discovered that the properties had reverted back to HP Photo Paper.  I attempted to print from the File menu and by using Cntrl P.  Neither option worked and the "Pproperties" continued to show HP photo paper, even though I changed it after each failed attempt and the hopper was full of white ink jet paper.  I deinstalled the HP printer and reinstalled it using the original discs.  Since the reinstall, the preferences are set as desired, and remain that way every time I chack them.  I can print a test page, copy and print email.  However, when printing from the print option in File, the task bar printer icon or Cntrl P, the pages continue to be processed but no ink is applied.  The pop-up menu that appears when using any of these commands always contains the term "properties" and those properties always show HP photo paper as the stock being used.  Regaerdless of how many times I correct the paper type, the entry reverts to HP photo paper after each attempt at printing. 

    I have the B8550 too, and I just assumed that since it's a fairly high-end printer, it would support the highest-end HP photo paper (i.e., Premium Plus).  However, the manual states:
    HP Premium and HP Premium Plus photo papers are not supported with this product.
    Now, I don't know if that means you shouldn't use it, or that the advanced features won't work, or ??? Or if you should use it, what settings to use (since that type of paper is not listed in the options on the drop-down menu.)  I have used the Premium Plus Soft Gloss without any problems.  But HP seems to think that the highest quality paper you can use with this printer is "Advanced," which is their third-grade paper.  Not exactly what I'd expect from this type of printer. 

  • External Hard Drive doesn't show particular folder

    I have this weird issue with my hard disk.
    Have been using Seagate GoFlex 1 TB for quite some time, on Windows as well as on Mac.
    Recently I had copied a folder with lot of videos on Windows. But when I opened the Hard Disk on Mac, the folder was blank and in Info it showed Zero kb file size. Opened it again on the machine from where I had copied it from, showed the folder with it's contents as is it.
    I then opened the hard drive on another windows, it asks me to Format the Hard disk even before displaying the contents of the hard drive.
    I'm going bonkers, because I do not have the windows machine from which had originally copied the videos and these are my clients videos which I need to edit on FCP/Mac ASAP!!
    Anyone knows what might be the problem and how to sort it out?
    Thank You.

    What sort of disk format is this drive (NTFS, or ???) or is it two partitions (one for Windows like NTFS and one for Mac as HFS+)??

  • Show Library Folder on non-TM backup

    In Mac OS 10.9/10 you go to your home folder and select View > Show View Options (cmd-j) and there should be a check box marked "Show Library Folder" this is the easiest way to alow yourself access to your library folder.
    In the case of a non-TimeMachine backup of the (non-bootable) Home Folder, the Library Folder is not shown and the above technique is not applicable -- how can the Library Folder be revealed in this instance?

    Open the AppleScript Editor in the /Applications/Utilities/ folder, paste the text below exactly as it's written into it, and run the script:
    tell application "Finder" to quit
    do shell script "chflags nohidden " & quoted form of POSIX path of (choose folder with invisibles)
    delay 2
    tell application "Finder" to run
    (115904)

  • Why does the latest version continue to show CSS faults after they are corrected?

    After updating Firefox yesterday, I made an error with some css code and Firefox immediately picked it up (very helpful). After correcting the error, Firefox continues to show the error unless I validate the page and then re-open with Firefox. The same error is shown for every page in my local folder regardless of the fact that the error was never made on those pages. Is this new with the update, or am I unaware of a simple reset procedure? CSS Error: Unexpected end of file while searching for closing } of invalid rule set. My operating system is Windows 7. The problem not an issue for me unless I need to learn something about using Firefox.

    Reload web page(s) and bypass the cache.
    * Press and hold Shift and left-click the Reload button.
    * Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Linux)
    * Press "Cmd + Shift + R" (MAC)

  • On start up my mac is showing a folder and flashing question mark sign?

    On start up my mac shows a folder sign & flashing question mark?? Help and Why??

    Question (?) Mark, Blinking Folder, or Gray Screen at Startup
    These are related but not identical issues. Their causes are outlined in Intel-based Mac- Startup sequence and error codes, symbols. Solutions may be found in:
    A flashing question mark appears when you start your Mac
    Mac OS X- Gray screen appears during startup
    In most cases the problems may be caused by:
    Problem with the computer's PRAM - See Resetting your Mac's PRAM and NVRAM.
    Boot drive's directory has been corrupted - Repair with Disk Utility.
    Critical system files are damaged or deleted - Reinstall OS X.
    The disk drive is physically non-functional - Replace the hard drive.
    Repair the Hard Drive and Permissions
    Boot from your Snow Leopard Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Utilities menu. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer.
    If DU reports errors it cannot fix, then you will need Disk Warrior and/or Tech Tool Pro to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.
    The main difference if you are using Lion or Mountain Lion is that you must first boot from the Recovery HD:
    Boot From The Recovery HD:
    Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
    Reinstall Snow Leopard Without Erasing The drive
    1. Repair the Hard Drive and Permissions
    Boot from your Snow Leopard Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Utilities menu. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer.
    If DU reports errors it cannot fix, then you will need Disk Warrior and/or Tech Tool Pro to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.
    2. Reinstall Snow Leopard
    If the drive is OK then quit DU and return to the installer.  Proceed with reinstalling OS X.  Note that the Snow Leopard installer will not erase your drive or disturb your files.  After installing a fresh copy of OS X the installer will move your Home folder, third-party applications, support items, and network preferences into the newly installed system.
    Download and install Mac OS X 10.6.8 Update Combo v1.1.
    Reinstalling Lion/Mountain Lion Without Erasing The Drive
    Boot to the Recovery HD: Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
    Repair the Hard Drive and Permissions: Upon startup select Disk Utility from the main menu. Repair the Hard Drive and Permissions as follows.
    When the recovery menu appears select Disk Utility. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the main menu.
    Reinstall Lion/Mountain Lion: Select Reinstall Lion/Mountain Lion and click on the Continue button.
    Note: You will need an active Internet connection. I suggest using Ethernet if possible because it is three times faster than wireless.

Maybe you are looking for

  • REPORT- Unable to read data

    Hi all, I have a requirement that for a particular excise invoice no and date I should show the particular Material Company Code, Batch No, Gross Weight, Net Weight. There are two materials for that particular excise invoice no and for one material t

  • My macbook pro is not charging - any help please!?

    My macbook pro is not charging - any help please!? <Edited by Host>

  • Cisco CUE AA Editor

    Im new on this, I install the AA Editor 2.3, I hit new, but after that, I can't drag and drop anything. What is the problem? thanks.

  • How do I get Mac OS X 10.5 or later ?

    Im currently using Yosemite OS X 10.10...

  • Split a collection object

    Hi I have a collection object which is contains strings like (Name Address City State Country). The collection object is created from a result set. I am not sure how to parse into respective variable for the UI to display. As of now, I am just dumpin