# Can we timeout cd command

**URL:** <https://community.unix.com/t/can-we-timeout-cd-command/219094>\
**Category:** Shell Programming and Scripting\
**Created:** [November 4, 2008, 5:20am UTC](https://community.unix.com/t/can-we-timeout-cd-command/219094 "2008-11-04T05:20:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dipashre](https://community.unix.com/letter_avatar/dipashre/32/5_5575768a8748004e209b776fc1b2916d.png) [@dipashre](https://community.unix.com/u/dipashre)\
**Post date:** [November 4, 2008, 5:20am UTC](https://community.unix.com/t/can-we-timeout-cd-command/219094/1 "2008-11-04T05:20:52Z")

</div>

Hi All,

I want to know whether we can timeout the cd command in unix.  
If we can how is it implemented?  
Suppose cd command hangs can we timeout the command.  
Please help

---

<div class="post-metadata">

**Author:** ![zaxxon](https://community.unix.com/user_avatar/community.unix.com/zaxxon/32/660_2.png) [@zaxxon](https://community.unix.com/u/zaxxon)\
**Post date:** [November 4, 2008, 5:24am UTC](https://community.unix.com/t/can-we-timeout-cd-command/219094/2 "2008-11-04T05:24:30Z")

</div>

Usually it doesn't hang ie. something else is the problem, filesystem, disk? Maybe try fix the causing problem first.

---

<div class="post-metadata">

**Author:** ![dipashre](https://community.unix.com/letter_avatar/dipashre/32/5_5575768a8748004e209b776fc1b2916d.png) [@dipashre](https://community.unix.com/u/dipashre)\
**Post date:** [November 4, 2008, 5:28am UTC](https://community.unix.com/t/can-we-timeout-cd-command/219094/3 "2008-11-04T05:28:06Z")

</div>

Well if there is some problem can we timeout the cd command?

---

<div class="post-metadata">

**Author:** ![dipashre](https://community.unix.com/letter_avatar/dipashre/32/5_5575768a8748004e209b776fc1b2916d.png) [@dipashre](https://community.unix.com/u/dipashre)\
**Post date:** [November 4, 2008, 6:07am UTC](https://community.unix.com/t/can-we-timeout-cd-command/219094/4 "2008-11-04T06:07:49Z")

</div>

Iam getting this error:-  
NFS getattr failed for server bsm1a: error 5 (RPC: Timed out)

Someone plese help

---

<div class="post-metadata">

**Author:** ![zaxxon](https://community.unix.com/user_avatar/community.unix.com/zaxxon/32/660_2.png) [@zaxxon](https://community.unix.com/u/zaxxon)\
**Post date:** [November 4, 2008, 6:38am UTC](https://community.unix.com/t/can-we-timeout-cd-command/219094/5 "2008-11-04T06:38:15Z")

</div>

Ah, NFS problems.. Does a ls hang too? If not, use that one mabye to check if the share is still available.

---

<div class="post-metadata">

**Author:** ![dipashre](https://community.unix.com/letter_avatar/dipashre/32/5_5575768a8748004e209b776fc1b2916d.png) [@dipashre](https://community.unix.com/u/dipashre)\
**Post date:** [November 4, 2008, 6:45am UTC](https://community.unix.com/t/can-we-timeout-cd-command/219094/6 "2008-11-04T06:45:33Z")

</div>

Hi,  
ls command is failing too.

We have a script which takes the backup of the database.  
Doing cd to a directory is one of the steps.  
The directories are not properlu mounted and hence cd command is failing.  
I want to know is there a way where i can timeout the cd command?

---

<div class="post-metadata">

**Author:** ![zaxxon](https://community.unix.com/user_avatar/community.unix.com/zaxxon/32/660_2.png) [@zaxxon](https://community.unix.com/u/zaxxon)\
**Post date:** [November 4, 2008, 6:55am UTC](https://community.unix.com/t/can-we-timeout-cd-command/219094/7 "2008-11-04T06:55:10Z")

</div>

Not by a parameter or something like that afaik. You could check with ps if there is a cd command for that user and script, get it's PID and kill it, after a timer of 10 seconds or whatever is ok for you. You could make that part of your script in the background.  
But even if I get on your nerves, you might want to fix that NFS problem.  
Isn't it a appropriate way in your using ssh/scp/rsync to get your backup?

We had similar problems which we could not solve even with support - that's one of the reasons I really don't like NFS, tbh.

---

<div class="post-metadata">

**Author:** ![dipashre](https://community.unix.com/letter_avatar/dipashre/32/5_5575768a8748004e209b776fc1b2916d.png) [@dipashre](https://community.unix.com/u/dipashre)\
**Post date:** [November 4, 2008, 7:19am UTC](https://community.unix.com/t/can-we-timeout-cd-command/219094/8 "2008-11-04T07:19:28Z")

</div>

Well I want to implement the check in the same script. Is there no way to time out the "cd" command?

---

<div class="post-metadata">

**Author:** ![fpmurphy](https://community.unix.com/user_avatar/community.unix.com/fpmurphy/32/110_2.png) [@fpmurphy](https://community.unix.com/u/fpmurphy)\
**Post date:** [November 4, 2008, 10:25am UTC](https://community.unix.com/t/can-we-timeout-cd-command/219094/9 "2008-11-04T10:25:28Z")

</div>

You can. In an earlier post Zaxxon described one way to do it.

---

<div class="post-metadata">

**Author:** ![Perderabo](https://community.unix.com/user_avatar/community.unix.com/perderabo/32/27_2.png) [@Perderabo](https://community.unix.com/u/Perderabo)\
**Post date:** [November 4, 2008, 11:41am UTC](https://community.unix.com/t/can-we-timeout-cd-command/219094/10 "2008-11-04T11:41:55Z")

</div>

A process performing disk i/o cannot be interrupted until the i/o completes. By default this also applies to NFS mounted filesystems. You can use a "intr" option to make NFS operation interruptable. You can also use a "soft" option to make them time out on their own. These are described on the mount\_nfs man page or whatever man page describes nfs mounts for your OS.
