0

I am having problem to find a file has basic commands like rm, ls, cd, etc. I need the file path in Ubuntu to edit them. I checked on web but just found UNIX file locations (/usr/bin).

So, here it is what I mean,

# cd /usr/bin
# ls -lh rm
-r-xr-xr-x   1 root   bin   14K May  1  2007 rm
# chmod 4555 rm
# ls -lh rm
-r-sr-xr-x   1 root   bin   14K May  1  2007 rm
# chmod 2555 rm
-r-xr-sr-x   1 root   bin   14K May  1  2007 rm

I want to change the privileges of rm. Inclusion of any suggestions or documentations are welcomed.

Kulfy
  • 17,696
Hexcake
  • 3
  • 2
  • Hi and welcome to the site! Could you please [edit] your question and explain what you mean a bit better. How can a file have commands? What exactly are you looking for? Are you trying to see where the executables (the programs) of these commands are? What have you found and how is it wrong (/usr/bin isn't only UNIX). – terdon Sep 18 '19 at 11:11
  • If I wanted to know where the command ls is, I'd use whereis ls and it tells be where the binary is located, plus manual (reference) page is too. – guiverc Sep 18 '19 at 11:14
  • whereis searches your $PATH for binaries (programs) that meet your request; if the "file path" you're asking about is the environment variable $PATH I missed it (I'm not sure what you really are after, as terdon already alluded to) – guiverc Sep 18 '19 at 11:21
  • I edited the comment with the screenshot. Hope it is clear now – Hexcake Sep 18 '19 at 11:22
  • Please don't post screenshots of text. You can copy text from a terminal and paste it here as text. – Pilot6 Sep 18 '19 at 11:25
  • Oh sorry about it. I cannot access that path on ubuntu that's why I shared this screenshot. – Hexcake Sep 18 '19 at 11:26
  • Thank you @guiverc for the answer. It worked :) – Hexcake Sep 18 '19 at 11:29
  • @Hexcake If one of the answers solved your issue, please take a moment to accept it by clicking on the checkmark on the left. That will mark the question as answered and is the way that thanks are conveyed on the Stack Exchange sites. – terdon Sep 18 '19 at 11:50
  • 2
    By the way, whatever you do *do not ever change the permissions of basic system utilities*! There is no good reason to do so and trying it could well break your system. Whatever it is you want to achieve by this, just ask a question about that instead. There will be a better way to do it. Changing the permissions of rm will not be the answer. – terdon Sep 18 '19 at 11:52
  • @terdon I accepted thank you for warning me. I am not going to change system utilities, just wanted to see where they are. Thank you for help everyone. – Hexcake Sep 18 '19 at 12:50

2 Answers2

2

whereis command tells you where the binary and all documentations are located of a command. But not all commands have some binary that is invoked whenever they are executed. Some commands are shell built-in. Since Ubuntu uses bash as its default shell, these Bash Builtins are present.

The easiest way to determine whether a command is an alias or invokes some binary or is a command provided by the shell, is using type (which itself is also a shell built-in command) with -a option.

For example, if you use

whereis cd

You'll observe that there is no output which may convince you that cd is some magical thing which isn't present in /usr/bin. But cd is a shell built-in command. And if you run

type -a cd

You'll get

cd is a shell builtin

If you try it yourself, you'll find that rm does have a binary in /bin.

But there are some exceptions. echo is the example.

If you run

type -a echo

You'll get

echo is a shell builtin
echo is /bin/echo

That means there is both an echo shell built-in command and an external command in /bin/echo. The reason is described in Eliah Kagan's answer and muru's answer.

ls is another exception. By default ls is an alias to ls --color=auto as well. The output of type -a ls will look like:

ls is aliased to `ls --color=auto'
ls is /bin/ls

This alias is defined in ~/.bashrc. If this alias is "unaliased", ls would invoke the binary located in /bin.

terdon
  • 100,812
Kulfy
  • 17,696
0

If I wanted to know where the command ls is, I'd ask the system using

whereis ls

guiverc@d960-ubu2:/de2900/buster$   whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz

and it tells be where the binary is located (/bin/ls), plus manual (reference) too (/usr/share/man/man1/ls.1.gz)

fyi: use man ls to view the manual page, the .1.gz at the end of the man (manual) page just tells you it's a page 1 type (ie. an executable program or shell command).

guiverc
  • 30,396
  • If you're wondering why I have the extra spaces before the whereis ls command, partially habit, but primarily because I don't want the command to show in my history (or command history). – guiverc Sep 18 '19 at 11:37