Change directory mac os terminal

Question: Q: 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:

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

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.

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

Posted on May 6, 2017 6:47 PM

Helpful answers

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#

one of the folders listed will be your userid.

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.

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?

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

/»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.

Источник

«Change Directory» Command doesn’t work in Mac terminal

I’m learning python by myself on my Mac. I downloaded a folder to my desktop called ExercisesFiles and it has a subfolder called Chap01. And Chap01 has a python file called 01_03.py. Now I open a Mac terminal and tried to write some commands to open the 01_03.py file. I wrote down:

Then the terminal tells me:

-bash: cd: Desktop/ExerciseFiles/Chap01: No such file or directory

I can’t figure out why the terminal doesn’t allow me to change directory? I look up the Mac terminal commands and I believe my commands are right. Thank you.

/Desktop/ExerciseFiles/Chap01 will work no matter where you’re starting from, because it ignores your current directory and starts from your home directory.

1 Answer 1

Perform pwd for checking current working directory. Maybe you’re not in user’s home dir. If you want to go to Desktop from any place, you can exec cd

/Desktop/ . In this case,

makes sure that you’re in logged-in-user’s home dir. Adjust this command accordingly for your needs.

Desktop/ExerciseFiles/Chap01 , it returns zsh: no such user or named directory: Desktop . Then I entered pwd , it returns /Users/vivhuang . Then I entered cd

Desktop/ExerciseFiles/Chap01 , it returns zsh: no such user or named directory: Desktop . Then I entered cd

/Desktop/ExerciseFiles/Chap01 , it returns nothing. So I entered ls and the python file come out! Can you please explain a little bit what happens? I’m still not 100% clear about how it works. Thx.

Источник

How to change the default directory in Terminal on Mac?

this is my very first question in here since I just started coding, and I hope it’s an easy one. Have found likewise questions on here, but none of their solutions seemed to work for me, or I just didn’t know how to pull them off. So here goes: How do I change the default directory, when I open up Terminal on my Mac version 10.12.4? Whenever I open, it says this of course: Last login: Thu May 17 09:02:07 on ttys004 Mikkels-MacBook-Air:

MikkelMalmros$ Then I have to use the «cd desktop/coding» to move to the folder I created for programming. I would like to skip that step, so it automatically opens up in there. I’ve tried going to preferences and changing «Shell opens with command» thing and put in «cd desktop/coding». Whenever I open up Terminal then, it just says «process done» and I can’t write anything at all.

So what am I doing wrong, and is there a way to fix this small problem for me?

1 Answer 1

Add ‘cd path/to/directory’ to .bash_profile

Not the answer you’re looking for? Browse other questions tagged macos terminal or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.10.8.40416

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Set the default directory in mac terminal

I only use terminal (mac) for git, and I only use git for one directory. Is it possible to set the default directory (the directory when terminal is opened) to the directory where I use git, and if so how?

6 Answers 6

As of Mac OS X Lion 10.7, Terminal supports Resume and by default will automatically restore terminals you had open when you quit, restoring their working directories. So, you can just open a new terminal and cd to your git directory, then leave the window open when you Quit. Each time you reopen Terminal, the terminal will be there, in the same directory. (This works for bash by default. If you’re using some other shell, you’ll need to adapt the code in /etc/bashrc to your shell. I’ve posted code for zsh in my answer to Resume Zsh-Terminal (OS X Lion) on SuperUser.)

You can also arrange for Terminal to start a shell in a particular directory. You can customize or create a «Settings Profile» to issue a «cd» command when it starts:

Terminal > Preferences > Settings > [profile] > Shell > Startup > Run command

Enable «Run command» and «Run inside shell», then set the command to cd your_git_directory . When you open a new terminal with that profile, it will go to your git directory.

I recommend you Duplicate the current default profile (if you’ve never changed it, the default is «Basic») using the Action («gear») menu at the bottom of the profiles list, then customize that profile.

Finally, to have it automatically open a terminal with this profile when you open Terminal, set

Terminal > Preferences > Startup > On Startup, open

to your custom profile. (On Lion, Resume will restore windows that were open when you quit, rather than perform the startup action. As I mentioned, you can just leave this terminal open when you Quit and it will be restored when you open Terminal again. Or, you can press the Option modifier key when quitting; the Quit menu item will change to «Quit and Discard Windows» and the next time you open Terminal it will perform the startup action.)

Источник

Move and copy files in Terminal on Mac

In Terminal, you can move and copy files locally or remotely using the mv , cp and scp command-line tools.

Tip: It’s easier to move and copy files using the Finder. See Organise files in folders.

Move a file or folder locally

In the Terminal app on your Mac, use the mv command to move files or folders from one location to another on the same computer. The mv command moves the file or folder from its old location and puts it in the new location.

For example, to move a file from your Downloads folder to a Work folder in your Documents folder:

You can also change the name of the file as it’s moved:

Copy a file or folder locally

In the Terminal app on your Mac, use the cp command to make a copy of a file.

For example, to copy a folder named Expenses in your Documents folder to another volume named Data:

The -R flag causes cp to copy the folder and its contents. Note that the folder name does not end with a slash, which would change how cp copies the folder.

Copy a file or folder remotely

In the Terminal app on your Mac, use the scp command to copy a file or folder to or from a remote computer.

scp uses the same underlying protocols as ssh .

For example, to copy a compressed file from your home folder to another user’s home folder on a remote server:

You’re prompted for the user’s password.

The -E flag preserves extended attributes, resource forks and ACL information.

The -r flag, which isn’t used in this example, causes scp to copy a folder and its contents.

Источник

Читайте также:  Neighbors windows and doors
Оцените статью