Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Changing directories from BASH in Terminal

I am booting from a Yosemite USB stick to fix a problem. If interested/relevant, details of the problem may be found here:


https://discussions.apple.com/thread/7910180?start=15&tstart=0


In Yosemite booted from the USB stick, the command line reads: -bash-3.2#


Somehow I need to navigate from -bash-3.2# (in terminal) and change directories so that the command line looks like: [text1:~] text2% where text1 is my local host name and text2 is (I think) the short version of my user account name.


From there I know what terminal commands to run to solve the problem.


Can anyone help me figure how to navigate from -bash-3.2# to [text1:~] text2% while booted in Yosemite on the USB stick???


Also, one other issue I just thought of: FileVault is enabled. Will this impact the process in any way?


Thank you very much!!!

OS X El Capitan (10.11.6)

Posted on Apr 29, 2017 7:54 AM

Reply
5 replies

May 6, 2017 12:31 PM in response to rccharles

Very useful summary. Thank you!


But here's where we are at.


I boot from the Yosemite USB and see -bash-3.2#


I run /sbin/fsck -fy and it runs appropriately and says there are no errors.


/sbin/mount -uw / runs OK without errors, but when I run ls /Users it says there is no folder like Users or something like that.


I run cd .. several times to try and get to the top of the stack and see:


User uploaded file


I then run cd Volumes to look in there and see:


User uploaded file


So the question is, how does one navigate to your own user folder from "-bash-3.2#" ??? I'm totally befuddled.


If it helps, there are 3 startup disks listed: "Untitled Windows", "OS X Yosemite..." (the Yosemite USB stick purchased discussed above) and "MyComputer Encrypted Disk" (I am assuming it is saying Encrypted Disk since FileVault is enabled).


Much appreciated.

May 6, 2017 6:47 PM in response to CharPatton

If your /User is on the internal boot disk, and you are booted from an external USB drive, then you need to navigate through


cd '/Volumes/name of your boot volume/Users'


The single quotes '...' will protect the 'cd' command from spaces in the name of your internal boot disk.


The

/sbin/fsck -fy

/sbin/mount -uw /

cd /Users

commands are generally used when booting into Single User mode (boot holding Command-S), not for when booting from an external disk.


When booting from an external disk, your internal boot disk will look to the external USB device as an attached volume which gets mounted into /Volumes/name/Users/yourShortUsername

May 6, 2017 12:21 PM in response to CharPatton

[text1:~] text2%

What is displayed here are comments only.

so you want to go to here:

cd /Volumes/Macintosh\ HD/Users/yourshortname/.Trash


I think you are in single user mode via -bash-3.2#

# Type the follow two instructions to access the startup disk in read/write.

# check out the filesystem.
# ( in case of partial success repeat this command until errors go away. )
/sbin/fsck -fy

# Gain read / write access to your startup drive
/sbin/mount -uw /

->To find out the users on the system type, use the ls command. The l is a lower case L:
ls /Users



one of the folders listed will be your userid.


mac $ ls /Users
Deleted Users/        mac/                  penguin/
mac $ ls -ld /Users/mac
drwxr-xr-x+ 80 mac  staff  2.7K Apr 21 13:02 /Users/mac/
mac $ cd /Users/mac
mac $ pwd
/Users/mac
mac $ ls -la
total 12698808
drwxr-xr-x+  80 mac  staff  2.7K Apr 21 13:02 ./
drwxr-xr-x  11 root  admin  374B Apr 18 12:18 ../
-r--------    1 mac  staff    7B Jul 27  2015 .CFUserTextEncoding
-rw-r--r--@  1 mac  staff    46K Apr 28 16:59 .DS_Store
drwx------    5 mac  staff  170B Apr 28 14:24 .Trash/
drwxr-xr-x    7 mac  staff  238B Sep 25  2016 .android/
-rw-r--r--    1 mac  staff    0B Aug 20  2015 .applesetupdone.old
... clipped ...
-rw-r--r--    1 mac  staff  3.6G Mar 17 16:16 zero
mac $ cd .Trash
mac $ pwd
/Users/mac/.Trash
mac $ ls -l
total 2088
-rw-r--r--@ 1 mac  staff  760K Jan 20 18:34 Scan.pdf
-rw-r--r--@ 1 mac  staff  282K Apr 26 00:53 picture.jpg
mac $



------------------------------------------------------------



Here is an overview of the terminal commands. Lets assume that your account has a short user name of mac.

Macintosh-HD -> Applications -> Utilities -> Terminal

What is my short user name? Type the whoami command.

mac $ whoami
mac
mac $

How to list all of your disks.
The ls command is for list

mac $ ls /Volumes/
Audio CD Macintosh-HD Spotless Tiger-ext
mac $

Let's say your flash drive is named Spotless


# cd is change directory

mac $ cd /Volumes/Spotless
# pwd is Print Working Directory. A directory is the Unix name for a folder. You are always in a directory.
mac $ pwd
/Volumes/Spotless
mac $

# The ls command is for list
# l is long
# F is type of file where / is directory. For directories, the slash is pasted to the end of the name.

mac $ ls -lF
total 134704
-rw-r--r-- 1 mac staff 64560 Mar 3 2009 A-picture-of-Youpi-key.png
drwxr-xr-x 83 mac staff 2822 Nov 7 14:52 Applescript files/
drwxrwxrwx 12 mac staff 408 Dec 13 2008 Christmas Cards/
drwxr-xr-x 9 mac staff 306 Dec 21 17:39 Christmas Cards 2009/
... trimmed ...

What does all this mean?

drwxrwxrwx

d = directory
r = read
w = write
x = executeable program

drwxrwxrwx
||||
|||all other users not in first two types
|||
||group
||
|owner
|
What type of entry is this? d = directory, - = file, etc.


Every Unix resource: files, folders, etc has an owner, group, other
A Unix resource has one owner.
A Unix resource has one group. A group contains a list of users.


To gain access to a file, you can be the owner, in the group, or not the owner and not in the group hence you end up as other. The owner, group, or other has read, write, or execute permissions.


# l is long
# a is all to show hidden files & folders

mac $ ls -lFa
total 134736
drwxr-xr-x 41 mac staff 1496 Dec 22 17:11 .
drwxrwxrwt 8 root admin 272 Dec 24 13:55 ..
-rwxrwxrwx 1 mac staff 15364 Dec 23 12:52 .DS_Store*
drwx------ 4 mac staff 136 Jan 22 2009 .Spotlight-V100
drwxrwxrwt 5 mac staff 170 Sep 14 16:36 .TemporaryItems
d-wx-wx-wx 4 mac staff 136 Dec 31 1969 .Trashes
-rw-r--r-- 1 mac staff 64560 Mar 3 2009 A-picture-of-Youpi-key.png
drwxr-xr-x 83 mac staff 2822 Nov 7 14:52 Applescript files
drwxrwxrwx 12 mac staff 408 Dec 13 2008 Christmas Cards
drwxr-xr-x 9 mac staff 306 Dec 21 17:39 Christmas Cards 2009
... trimmed ...

# mv is move or rename
mv -i the-name the-new-name




# You can just rename the file back to what it was with mv command.
mv -i old-name new-name


Here is what these commands mean:
cd is change directory
pwd is a print working directory
ls is list
sudo is Super user do
mv is move or rename


For cryptic comments, you can always uses the manual command which is man. For example:
man mv


Type the letter q to quit the man command.


In case you have spaces in your filenames or directories, you need to escape them. See examples:

Use quotes around the name

mac $ ls -l ~/"see it"
-rw-r--r-- 1 mac staff 3171 Oct 26 23:38 /Users/mac/see it
mac $

Use the backslash character to escape the next character
mac $ cd /Users/mac/Desktop/ttt\ html\ copy/


Do you know about tabbing? Type in a few letters of a name then press the tab key. The computer will type out the rest of the name if it is unique.


Press the up arrow key to see the previous command(s).


To edit a command, use the left arrow key to more left and the right arrow key to move right. Use the delete key to delete the key to the left. Type a letter to insert.


history to see many previous commands.


mac $ history

1 pwd

2 man ls

3 history

You may copy then paste from this list.


----------------------


http://discussions.apple.com/thread.jspa?threadID=2692161&tstart=0


Robert

May 6, 2017 8:53 PM in response to BobHarris

Woo hoo/ Solved! Thanks for all your help.


The final trick necessary was to decrypt the disk (i.e., turn off FileVault). Once that was done you could boot from the Yosemite USB stick, then use "cd .." and "ls" repeatedly to rise to the top level, then navigate back down to the now available (unencrypted) drive using cd "directory name" and finally get to .Trash. Once there the remove command worked like a charm.


This was a lot of work but fun learning stuff. Again, appreciate all who chimed in with hints!

Changing directories from BASH in Terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.