Is the cd cmd part of the kernel?


 
Thread Tools Search this Thread
Top Forums Programming Is the cd cmd part of the kernel?
# 1  
Old 05-05-2011
Is the cd cmd part of the kernel?

Hi All

I'm looking at writing something that handles changing directory in the calling shell and wanted to take a look at the cd command.
Code:
which cd

comes back with nothing and
Code:
man cd

does nothing either.

Where is the cd command?

I can see why it wouldn't be with the rest of the commands in /bin as it wouldn't change the directory in the calling shell if it was run in a sub-shell like the other commands are.

Is it part of the kernel?

If so would it be possible to write a kernel module to do what I want? I've been looking at tutorials on kernel programming but haven't found anything that tells me if I can extend the basic Unix command set this way. Most of the examples seem to be driver oriented or basic hello world examples writing to the logs.

Any help appreciated

Cheers
# 2  
Old 05-05-2011
It's neither a program, nor a part of the kernel, but a shell builtin. Same as echo (for most shells), eval, and sometimes even kill and printf.

If you want to enhance it, you can always write a shell function which supersedes the original command.
# 3  
Old 05-05-2011
The cd command is implemented by invoking the chdir() system call which is indeed part of the kernel.
# 4  
Old 05-05-2011
Hi Pludi

Thanks. I've already written this (PushPop) in Korn shell and it works very well but is of course now dependent on the user being a Korn shell user. I now want to implement the project independently of the user's login shell.

Hi Perderabo

Thanks that's really helpful.

Could you elaborate a little more? As a Korn shell user, when I type cd is the Korn shell using a built in to call chdir()? So every shell such as bash and C etc has its own wrapper called cd?
# 5  
Old 05-05-2011
Every shell has a cd command. They all invoke chdir() to accomplish it.
This User Gave Thanks to Perderabo For This Post:
# 6  
Old 05-05-2011
OK thanks Smilie
# 7  
Old 05-06-2011
Bug

Quote:
Originally Posted by steadyonabix
Hi All

I'm looking at writing something that handles changing directory in the calling shell and wanted to take a look at the cd command.
Code:
which cd

comes back with nothing and
Code:
man cd

does nothing either.

Where is the cd command?

I can see why it wouldn't be with the rest of the commands in /bin as it wouldn't change the directory in the calling shell if it was run in a sub-shell like the other commands are.

Is it part of the kernel?

If so would it be possible to write a kernel module to do what I want? I've been looking at tutorials on kernel programming but haven't found anything that tells me if I can extend the basic Unix command set this way. Most of the examples seem to be driver oriented or basic hello world examples writing to the logs.

Any help appreciated

Cheers
Hi,

'cd' command is not part of the kernel. though it is the part of the shell. Its a shell built-in. The other commands are external to the shell like 'file', 'find' . If a command is shell built-in the shell can invoke it directly . But if its outside the shell, the shell normally creates another process. As pointed above, almost all the commands (userspace) utilities like shell, daemon processes, commands (file, find, etc) uses system calls which in turn is in kernel space.

Thanks and Regards,
Gaurav.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Linux

Unload kernel module at boot time (Debian Wheezy 7.2, 3.2.0-4-686-pae kernel)

Hi everyone, I am trying to prevent the ehci_hcd kernel module to load at boot time. Here's what I've tried so far: 1) Add the following line to /etc/modprobe.d/blacklist.conf (as suggested here): 2) Blacklisted the module by adding the following string to 3) Tried to blacklist the module... (0 Replies)
Discussion started by: gacanepa
0 Replies

3. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

4. Shell Programming and Scripting

Perl open(CMD, "cmd |"); buffering problem..

Hello, There's a third-party application's command that shows the application's status like "tail -f verybusy.log". When use the command, the output comes every 1-sec. but when it goes in a script below the output comes every 8-sec...What is the problem and how can I fix it? open(CMD,... (2 Replies)
Discussion started by: Shawn, Lee
2 Replies

5. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 Replies

6. Solaris

Which file is read by kernel to set its default system kernel parameters values?

Hi gurus Could anybody tell me which file is read by kernel to set its default system kernal parameters values in solaris. Here I am not taking about /etc/system file which is used to load kernal modules or to change any default system kernal parameter value Is it /dev/kmem file or something... (1 Reply)
Discussion started by: girish.batra
1 Replies

7. Shell Programming and Scripting

comparing part of header with part of detailed records.

Hi there, I am lil confused with the following issue. I have a File, which has the following header: IMSHRATE_043008_101016 a sample detailed record is :9820101 A982005000CAVG030108000000000000010169000MAR 2008 9820102 MAR 2008 D030108 ... (1 Reply)
Discussion started by: cmaroju
1 Replies

8. SuSE

max number of slabs per kernel module (kernel 2.6.17, suse)

Hi All, Is there a max number of slabs that can be used per kernel module? I'm having a tough time finding out that kind of information, but the array 'node_zonelists' (mmzone.h) has a size of 5. I just want to avoid buffer overruns and other bad stuff. Cheers, Brendan (4 Replies)
Discussion started by: Brendan Kennedy
4 Replies

9. UNIX for Dummies Questions & Answers

man <cmd> >> cmd.txt

I've noticed most of my postings here are because of syntax errors. So I want to begin compiling a large txt file that contains all the "man <cmd>" of the commands I most have problems with. I ran a "man nawk >> nawk.txt" but it included a header/footer on each "page". Anyone know how I'd be... (6 Replies)
Discussion started by: yongho
6 Replies
Login or Register to Ask a Question