top | item 32886315

Linux command line for you and me

218 points| rex_lupi | 3 years ago |lym.readthedocs.io | reply

35 comments

order
[+] davidpfarrell|3 years ago|reply
TIL that mac has an executable `cd` command:

   $ cat /usr/bin/cd
   
   #!/bin/sh
   # $FreeBSD: src/usr.bin/alias/generic.sh,v 1.2 2005/10/24 22:32:19 cperciva 
   Exp $
   # This file is in the public domain.
   builtin `echo ${0##*/} | tr \[:upper:] \[:lower:]` ${1+"$@"}
Although it didn't behave as expected when invoked ...
[+] cperciva|3 years ago|reply
Required by POSIX, and it does exactly what it's supposed to do: Changes directory in the process (not the parent shell). This isn't completely useless -- you get an exit status and potentially error messages out.

(And yes, I'm the cperciva in that version tag.)

[+] StuckDuck|3 years ago|reply
Something to note which wasn't mentioned here is that `cd` is not a binary executable, but instead a shell command. You won't find it anywhere in /bin, /sbin and so on. That's also why `sudo cd ` doesn't work, `sudo` will try to execute `cd` as root but it's not an executable so it won't find it. (tip: do `sudo -i` instead)
[+] remram|3 years ago|reply
cd is a good example of something that has to be a built-in command, because it makes the shell itself do something (change its current working directory). Other commands in that category are umask, the job control ones (fg, bg, wait, ...), the ones setting variables (read, printf), and the control flow ones (if, while, break, return, exit, ...).

A lot of commands are also built-in for convenience but don't strictly need to be.

[+] rjsw|3 years ago|reply
An executable of 'cd' wouldn't do anything useful, it could only change its own idea of working directory then exit, the shell or other executable that invoked it would be unchanged.
[+] saagarjha|3 years ago|reply
Many platforms will ship a (mostly) useless cd binary.
[+] codegeek|3 years ago|reply
These are always fun and informative. One of the cool options that a lot of people don't know about the "cd" command is the :

    cd -
This takes you to the last directory you were in (not the same as cd .. which takes you one level up)
[+] 5e92cb50239222b|3 years ago|reply
pushd / popd are also useful in scripts. For some reason they don't seem to be very well known and I rarely see them in practice.

  $ pwd
  /foo
 
 $ pushd /bar && pwd
  /bar

  $ pushd /quux && pwd
  /quux

  $ popd && pwd
  /bar

  $ popd && pwd
  /foo
So it's basically a stack.
[+] photochemsyn|3 years ago|reply
Nice basic introduction. For anyone wanting a comprehensive overview of each command, with examples (and generally more readable than man pages), the computerhope site is good. For example here's wc:

https://www.computerhope.com/unix/uwc.htm

[+] unixbane|3 years ago|reply
It's UN*X. The one thing it actually does good is having documentation on the system, instead of some weirdo's web page covered in ads. Type man <cmd> or info <cmd> in the shell. Also, for most of the world population, this will be a few seconds faster since it avoids loading a web page.
[+] orsenthil|3 years ago|reply
Very nicely written and comprehensive website. It is handy as we often work with docker and linux command line these days.
[+] chiefalchemist|3 years ago|reply
Probably not popular to say here, but it's ironic that the key benefit of computers is the ability to distance the user from complexity and mind-defeating details, yet computers themselves don't - yet? - offer said type of benefits.
[+] 74ls00|3 years ago|reply
What are you talking about? Of course they do! Try performing any of the operations listed in this article, or making a reply to this comment, by only twiddling the state of the transistors in your CPU.
[+] firstSpeaker|3 years ago|reply
Anyone knows of something similar for MacOs?