Sponsored Content
Top Forums Shell Programming and Scripting bash: cd command to access "strange" directories Post 302125728 by robotronic on Friday 6th of July 2007 04:12:28 PM
Old 07-06-2007
Question bash: cd command to access "strange" directories

I have a problem using bash. Simply, I cannot find the right command (if there's one!) to enter in the "- Arch_02 -" directory. As you can see, the name begins with a hyphen and this is causing some trouble:

Code:
localhost arch2 # pwd
/mnt/arch2
localhost arch2 # ls -l
total 4
dr-x------ 1 root root 4096 2007-04-29 20:09 - Arch_02 -
dr-x------ 1 root root    0 2006-12-10 18:14 RECYCLER
dr-x------ 1 root root    0 2006-12-02 22:24 System Volume Information

localhost arch2 # cd -\ Arch_02\ -
bash: cd: - : invalid option
cd: usage: cd [-L|-P] [dir]

localhost arch2 # cd "- Arch_02 -"
bash: cd: - : invalid option
cd: usage: cd [-L|-P] [dir]

localhost arch2 # cd '- Arch_02 -'
bash: cd: - : invalid option
cd: usage: cd [-L|-P] [dir]

localhost arch2 # cd - -\ Arch_02\ -
/root

localhost ~ # cd /mnt/arch2

localhost arch2 # cd - "- Arch_02 -"
/root


If I use csh instead, I can regularly access the directory by issuing the command:
Code:
(localhost:/mnt/arch2) # cd "- Arch_02 -"
(localhost:/mnt/arch2/- Arch_02 -) # pwd
/mnt/arch2/- Arch_02 -

With bash completion, if I press tab while typing directory's name, I can also see the subdirectories under "- Arch_02 -", but cannot access them with cd!

Does anyone have the answer?

Thanks a lot!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

chmod 777 on all directories below...how do I do that using the "find" command?

I've got 100 directories that each have 2 directories with in them. Structered like this: /home/domains/domain1/ through to /home/domains/domain100/ and those 2 directories mentioned above are here: /home/domains/domain1/directory1/ /home/domains/domain1/directory2/ through to... (7 Replies)
Discussion started by: Neko
7 Replies

2. UNIX for Dummies Questions & Answers

Listing only directories in the current working directory using the "ls" command

Hello All, I am trying to list only directories in my current directory using the command "ls -d". But the output only contains the default directory "." and doesn't list the rest of the directories in the working directory. Can anyone explain why this is happening (2 Replies)
Discussion started by: igandu
2 Replies

3. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies

4. AIX

Typing "bash" at the command line spawns two bash processes

Server: IBM p770 OS: AIX 6.1 TL5 SP1 When one of our develoeprs types "bash" on the command line to switch shells, it hangs. For some reason, two bash processes are created....the first bash process spawns a second bash process in the same console, causing a hang. Anyone have any idea what... (2 Replies)
Discussion started by: wjssj
2 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Strange "cut" command's behaviour

Hi, Suppose if I have a file having data like this: $ cat file.txt A B C D And, if I do a cut operation like this: $ cut -d" " -f2 file.txt The output is A C D This is the same for even if we try to get the field 3 with -f3 (assume line 2 has 3 fields : C E F). The above... (1 Reply)
Discussion started by: royalibrahim
1 Replies

7. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

8. UNIX and Linux Applications

Problem on SQLplus command ""bash: sqlplus: command not found""

Hi all, i face an error related to my server ""it's running server"" when i use sqlplus command $ sqlplus bash: sqlplus: command not found the data base is up and running i just need to access the sqlplus to import the dump file as a daily backup. i already check the directory... (4 Replies)
Discussion started by: clerck
4 Replies

9. Shell Programming and Scripting

Why awk print is strange when I set FS = " " instead of FS = "\t"?

Look at the following data file(cou.data) which has four fields separated by tab. Four fields are country name, land area, population, continent where it belongs. As for country name or continent name which has two words, two words are separated by space. (Data are not accurately... (1 Reply)
Discussion started by: chihuyu
1 Replies

10. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
chroot(8)						      System Manager's Manual							 chroot(8)

NAME
chroot - Changes the root directory of a command SYNOPSIS
/usr/sbin/chroot directory command DESCRIPTION
Only root can use the chroot command. The chroot command changes the root directory from / to the specified directory when the command executes. (The command specified includes both the command name as well as any arguments.) Consequently, the root of any path (as indicated by the first / (slash) in the pathname) changes to directory and is always relative to the current root. Even if the chroot command is in effect, directory is relative to the current root of the running process. Several programs may not operate properly after chroot executes. You must ensure that all vital files are present in the new root file system and the relevant pathnames for the files map correctly in the new root file system. For example, the ls -l command fails to give user and group names if the new root file system does not have a copy of the /etc/passwd and /etc/group files. If the /etc/passwd and /etc/group files in the new root file system represent different user and group names, then the output from the ls -l command will be based on those names, not the ones for the system's own name database. Utilities that depend on description files produced by the ctab command may also fail if the required description files are not present in the new root file system. The chroot program uses the execv() function to invoke the specified command. As a consequence, the command specified must be an exe- cutable binary, not a shell script. Further, if the program requires indirect loading (for example, due to unresolved symbols requiring use of a shared library), then /sbin/loader as well as any files it requires (for example, shared libraries) must be present in the new root file system in the appropriate locations. EXAMPLES
To run a subshell with another file system as the root, enter a command similar to the following. Note in this example, the file system is on the /dev/disk/dsk13a device and is mounted to /mnt/dsk13a: chroot /mnt/dsk13a /sbin/sh The command shown in the previous example spec- ifies a change from the current root file system to the one mounted on /mnt/dsk13a while /sbin/sh (which itself is relative to the new root file system) executes. When /bin/sh executes, the original root file system is inaccessible. The file system mounted on /mnt/dsk13a must contain the standard directories of a root file system. In particular, the shell looks for commands in /sbin, /bin, and /usr/bin (among others) on the new root file system. Running the /sbin/sh command creates a subshell that runs as a separate process from the original shell. Press to exit the subshell and return to the original shell. This restores the environment of the original shell, including the meanings of the current directory (.) and the root directory (/). To run a command in another root file system and save the output on the initial root file system, enter a command similar to the following. Note in this example, the file system is on the /dev/disk/dsk13a device and is mounted to /mnt/dsk13a: chroot /mnt/dsk13a /bin/cc -E /u/bob/prog.c > prep.out The previous command runs the /bin/cc command with /mnt/dsk13a as the specified root file system. It compiles the /mnt/dsk13a/u/bob/prog.c file, reads the #include files from the /mnt/dsk13a/usr/include directory, and puts the compiled text in the prep.out file on the initial root file system. To create a file relative to the original root rather than the new one, use this syntax and enter: chroot directory command > file CAUTIONS
If special files in the new root have different major and minor device numbers than the initial root directory, it is possible to overwrite the file system. FILES
Specifies the command path. RELATED INFORMATION
Commands: cc(1), cpp(1), ls(1), sh(1) Functions: chdir(2), chroot(2) exec(2) delim off chroot(8)
All times are GMT -4. The time now is 05:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy