Alias command in mac os x

Make an Alias in Bash or Zsh Shell in macOS with Terminal

To make aliases of macOS Unix commands in your bash or zsh shell on macOS and earlier versions, it is done via your .bash_profile or .zshrc file which lives in your home account directory, if the file does not already exist, just create one.

Launch Terminal from the /Application/Utilities folder

Go to your home directory by just entering ‘cd’ followed by the ‘return’ key to enter the command:

List your home directory contents including invisible files to see if the file already exists, use:

Create the .bash_profile or .zshrc file using the command line program called ‘nano’ if it doesn’t exist, if it does exist you add your aliases to the end of the file. The commands below assume you are in your home directory:

If you are not in your home directory you would use a prefix of the tilde ‘

’ and forward slash, which is the home directory path:

When the .bash_profile or .zshrc file is created you are ready to enter your alias commands.
So here I am using the alias ‘l’ to alias the command ‘ls -lah’

In nano ‘control+o’ to write the file out and ‘control+x’ to exit the file.

Refresh the shell environment by entering the command below:

That’s it, now the alias will take effect.

To add other aliases just start a new line, and apply the same formatting.

Источник

Create and remove aliases on Mac

To make it easier to find a file, folder, app or disk, you can create an alias for it and put the alias in an easy-to-find location. When you open an alias, the original item opens.

Create an alias

On your Mac, do one of the following:

Select the item, then choose File > Make Alias.

You can create as many aliases for an item as you want, then drag them to other folders or to the desktop.

Press Option-Command while you drag the original item to another folder or to the desktop to create an alias and move it in one step.

Add items to the Finder sidebar or Dock

The items you see in the Finder sidebar and the Dock are aliases that point to the original app, file, disk or folder. For example, in the sidebar, Documents opens the Documents folder located inside your home folder. You can add your own items to the sidebar or the Dock.

On your Mac, do one of the following:

Add a folder, app or disk to the Finder sidebar: Drag the original item to the Favourites section.

Add a file, folder or app to the Dock: Drag the original item to the Dock.

Drag apps to the left side of the line that separates the recently used apps. Drag files and folders to the right side of the other line that separates recently used apps. If you moved the Dock to the side of your desktop, drag files and folders below the separator and apps above.

Читайте также:  Space windows live spaces

Remove an item from the Finder sidebar or Dock

On your Mac, do one of the following:

Remove an item from the Finder sidebar: Drag the item out of the Finder sidebar until you see the remove sign .

Remove an alias from the Dock: Drag the item out of the Dock until you see Remove.

If you remove an item from the sidebar or Dock, only the alias is removed. The original item isn’t removed from your Mac.

Find the original item for an item in the Finder sidebar or Dock

On your Mac, do any of the following:

In the sidebar: Control-click the item in the sidebar, then choose Show in Enclosing Folder.

In the Dock: Control-click the item in the Dock, then choose Options > Show in Finder.

Источник

Question: Q: Using aliases in Terminal

I’m trying to add new alias to my terminal so I used the below commands

First I went to my bash_profile by using the commands

nano .bash_profile

Then I added the below line at the end of the file and saved it & exit the file

alias htdocs= «cd /Applications/mamp/htdocs»

After that I closed the terminal and opened it again to restart it, then I typed «htdocs» then pressed enter but still found the terminal informing me «-sh: htdocs: command not found «

Now I’m asking why the alias not working with me . , what I miss .

MacBook Pro (Retina, 13-inch, Mid 2014), OS X Mavericks (10.9.5)

Posted on Feb 28, 2018 5:46 AM

All replies

Loading page content

Page content loaded

It has been years since I used MAMP, so I don’t know if your path to htdocs is correct. Isn’t MAMP capitalized?

When you update the

/.bashrc file, you either update your Bash session by quitting the Terminal and restarting it, or with the following command which updates your alias without quitting Terminal:

Also, I use single, straight quotes on my alias target.

Feb 28, 2018 6:13 AM

After I used the command source

/.bash_profile , I found it working well now

Feb 28, 2018 6:23 AM

That would imply that you did not quit Terminal and re-launch it after modifying the .bash_profile

Of that you have some funky Terminal preferences set that is preventing .bash_profile from being read by the shell when you start.

I’m assuming you are running the default shell ‘bash’

If you are running a different shell, that also might explain it.

Feb 28, 2018 6:32 AM

I found that usually after closing the terminal or restarting my mac I found the alias undefined and the terminal informing me » -sh: htdocs: command not found «
what I should do to keeping it for every .

Mar 3, 2018 11:50 PM

1 — I put this line in the being of my .profile_bash

/».bash_profile but claims to be $0 running under $«

I put similar lines in all my profiles.

here is what I see when I start a terminal session.

Читайте также:  Aimp нет звука windows 10

Yes, my .bash_profile calls config/profile.bash. The /etc/profile and /etc/bashrc are system stuff.

2 — run the alias command to see what was aliased.

3 — put an echo before and after your alias command.

4— put the alias command alone «alias» after your aliasing to see if your command worked.

Doing this will help debug your system.

Mar 4, 2018 11:18 AM

You are NOT running ‘bash’, so .bash_profile is not being invoked

the -sh says you are running sh. If you were running bash it would say -bash : but it does not.

What does the following command say:

If the output is

then you need to use .profile

Or you need to change your shell to the default bash.

It is possible that the dscl command will say /bin/bash. If that is the case, then it is possible you have your Terminal -> Preferences -> General -> Shells to open with: (X) Command (complete path): /bin/sh

Mar 4, 2018 1:20 PM

Dears Guys,
First I would like every one for helping me, It’s working well now after I changed the alias to .profile as BobHarris saidto me

Thanks for every one

Mar 5, 2018 12:09 AM

First I would like every one for helping me, It’s working well now after I changed the alias to .profile as BobHarris saidto me

Some information to keep in the back of your mind.

By default macOS sets the default shell to bash. The fact that you are using sh means there has been some change made to your macOS setup. Whether you did this intentionally, or by accident, you should keep this in mind.

And the reason you should keep this in mind is that if you create a new account, or switch to a different Mac, you may find that in the new environment bash is now your shell, and assumptions you were making in your current environment are not working the same in the new environment.

And now that you have BOTH a .bash_profile _AND_ a .profile, you should know that if you magically switch back to bash, that when bash starts up it looks for one of the following 3 initialization files in the following order, and will use the first it finds, then ignore all the others

I mention this, because if you end up back with bash in your current account, it will start using the .bash_profile you currently have, and ignore the .profile you may have built up. This will be confusing, so keep this bit of information in the back of your mind. Unless of course you delete the .bash_profile, then bash will also find your .profile.

Источник

Создание файловых псевдонимов (алиасов) в Mac OS

Автор: Александр Конищев | Категория: Mac OS

Большая часть файлов, создаваемых вами на Mac, будут наилучшим образом располагаться в родных для них папках, и у вас никогда не возникнет ни малейшей необходимости держать их копии в других папках. Тем не менее вдруг вам потребуется предоставить другим людям доступ к копии какого-нибудь файла в вашей открытой папке? Или вы размещаете фотографию у себя на сайте и хотите, чтобы она была одновременно видна в папке «Изображения» (Pictures) и в той папке, где вы храните фото для веб? Самый простой способ сделать это — скопировать исходный файл (выбрать его и нажать Command + С) и вставить его в другую папку (нажать Command + V).

Читайте также:  Windows 10 yf heccrjv

Но в этом случае возникают две проблемы:

  • если вы изменяете исходный файл, придется снова копировать и вставлять его (без вариантов);
  • копии занимают дисковое пространство. Для большей части файлов в этом нет ничего страшного, однако размеры некоторых изображений, музыкальных или видеофайлов могут достигать десятков и сотен мегабайт или даже нескольких гигабайт, поэтому хранить россыпь подобных копий по всему компьютеру нерационально.

Для решения этих проблем Mac предлагает использовать «псевдонимы» файлов (файловые алиасы), которые являются особым видом файлов и просто предоставляют точку доступа к своим оригиналам. То есть если вы два раза кликнете на алиас, то Mac перейдет к оригиналу и откроет его. В этом смысле алиасы в среде Mac очень похожи на ярлыки в Windows.
Иными словами, вместо копирования самого файла в другое место вы создаете там его алиас.

Файловые псевдонимы решают обе упомянутые проблемы:

  • так как вы все время работаете с оригиналом, алиас и исходный файл никогда не будут отличаться друг от друга;
  • неважно, какой размер имеет исходный файл: его алиас занимает всего 100- 150 Кбайт. Это такой мизер, что вы можете свободно наполнить Mac таким количеством алиасов, какое вам нужно.

Существует два способа создать алиас:

1) Выберите исходный файл, а затем нажмите «Файл» (File) «Создать псевдоним» (Make Alias) или сочетание Command + L. Mac OS X создаст новый значок с тем же именем, что и оригинальный файл, но с пометкой «псевдоним».

2) Удерживая клавиши Option и Command, нажмите на файл и перетащите его мышью в нужную папку. OS X создаст новый значок с именем исходного файла.

Заметьте, что во втором случае значок создается без пометки «псевдоним». Однако если вы создаете алиас в той же папке, что и оригинал, то пометка «псевдоним» появится обязательно, чтобы в одной папке не было двух файлов с одним и тем же названием. С этим немного разобрались.

Но как отличить алиас от оригинала? Посмотрите на значок. Система Mac OS X прикрепляет к нижнему левому углу значка небольшую стрелку, что является обозначением файлового псевдонима.

Источник

Alias (Mac OS)

From Wikipedia, the free encyclopedia

Mac OS Alias
Type code alis
Uniform Type Identifier (UTI) com.apple.alias-file
Magic number ‘book\0\0\0\0mark\0\0\0\0’
Developed by Apple, Inc.
Type of format shortcut

In classic Mac OS System 7 and later, and in macOS, an alias is a small file that represents another object in a local, remote, or removable [1] file system and provides a dynamic link to it; the target object may be moved or renamed, and the alias will still link to it (unless the original file is recreated; such an alias is ambiguous and how it is resolved depends on the version of macOS). In Windows, a «shortcut», a file with a .lnk extension, performs a similar function.

It is similar to the Unix symbolic link, but with the distinction of working even if the target file moves to another location on the same disk (in this case it acts like a hard link, but the source and target of the link may be on different filesystems, and the target of the link may be a directory). As a descendant of BSD, macOS supports Unix symbolic (and hard) links as well.

Источник

Оцените статью